Skip to content

Commit 9f0a56c

Browse files
committed
adding colored view tests from commit by https://github.com/Nagato-Yuzuru
1 parent ebc6171 commit 9f0a56c

1 file changed

Lines changed: 39 additions & 1 deletion

File tree

tests/test_colored_view.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from deepdiff import DeepDiff
22
from deepdiff.helper import COLORED_VIEW, COLORED_COMPACT_VIEW
3-
from deepdiff.colored_view import RED, GREEN, RESET
3+
from deepdiff.colored_view import RED, GREEN, RESET, ColoredView
44

55

66
def test_colored_view_basic():
@@ -455,3 +455,41 @@ def test_colored_view_bool_evaluation():
455455
# Scenario 2: With differences
456456
diff_with_diff_compact = DeepDiff(t1_with_diff, t2_with_diff, view=COLORED_COMPACT_VIEW)
457457
assert bool(diff_with_diff_compact), "bool(diff) should be True when diffs exist (compact view)"
458+
459+
460+
def test_colored_view_with_empty_list_shows_removals():
461+
"""
462+
Tests ColoredView correctly shows about an empty list.
463+
This covers the bug where it would just show '[]'.
464+
"""
465+
t1 = [1, 2, 3]
466+
t2 = []
467+
ddiff = DeepDiff(t1, t2)
468+
view = ColoredView(t2, ddiff.tree)
469+
result = str(view)
470+
471+
# The output should contain the removed items, colored in red.
472+
assert f"{RED}1{RESET}" in result
473+
assert f"{RED}2{RESET}" in result
474+
assert f"{RED}3{RESET}" in result
475+
assert result.strip().startswith('[')
476+
assert result.strip().endswith(']')
477+
assert result != '[]'
478+
479+
480+
def test_colored_view_with_empty_dict_shows_removals():
481+
"""
482+
Tests ColoredView correctly shows about an empty dict.
483+
This covers the bug where it would just show '{}'.
484+
"""
485+
t1 = {'a': 1, 'b': 2}
486+
t2 = {}
487+
ddiff = DeepDiff(t1, t2)
488+
view = ColoredView(t2, ddiff.tree)
489+
result = str(view)
490+
491+
assert f'{RED}{{"a": 1' in result
492+
assert f'"b": 2}}{RESET}' in result
493+
assert result.strip().startswith(RED)
494+
assert result.strip().endswith(RESET)
495+
assert result != '{}'

0 commit comments

Comments
 (0)