Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions deepdiff/colored_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,13 @@ def _colorize_json(self, obj: Any, path: str = 'root', indent: int = 0) -> str:
return '{\n' + ',\n'.join(items) + f'\n{current_indent}' + '}'

elif isinstance(obj, (list, tuple)):
if not obj:
return '[]'
removed_map = self._get_path_removed(path)
for index in removed_map:
self._colorize_skip_paths.add(f"{path}[{index}]")

if not obj and not removed_map:
return '[]'

items = []
remove_index = 0
for index, value in enumerate(obj):
Expand Down
16 changes: 16 additions & 0 deletions tests/test_colored_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,22 @@ def test_colored_view_list_deletions():
assert result == expected


def test_colored_view_list_all_removed():
"""Test that removing all items from a list shows them in colored view."""
t1 = [1, 2, 3]
t2 = []

diff = DeepDiff(t1, t2, view=COLORED_VIEW)
result = str(diff)

expected = f'''[
{RED}1{RESET},
{RED}2{RESET},
{RED}3{RESET}
]'''
assert result == expected


def test_colored_view_list_additions():
t1 = [2, 4]
t2 = [1, 2, 3, 4, 5]
Expand Down