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,9 +109,10 @@ 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)
if not obj and not removed_map:
return '[]'

for index in removed_map:
self._colorize_skip_paths.add(f"{path}[{index}]")

Expand Down
30 changes: 30 additions & 0 deletions tests/test_colored_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,36 @@ def test_colored_view_list_additions():
assert result == expected


def test_colored_view_list_all_items_removed():
"""Test that all removed items are displayed when list becomes empty."""
t1 = [2, 4]
t2 = []

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

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


def test_colored_compact_view_list_all_items_removed():
"""Test that all removed items are displayed when list becomes empty with compact view."""
t1 = [2, 4]
t2 = []

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

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


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