|
1 | 1 | from deepdiff import DeepDiff |
2 | 2 | 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 |
4 | 4 |
|
5 | 5 |
|
6 | 6 | def test_colored_view_basic(): |
@@ -455,3 +455,41 @@ def test_colored_view_bool_evaluation(): |
455 | 455 | # Scenario 2: With differences |
456 | 456 | diff_with_diff_compact = DeepDiff(t1_with_diff, t2_with_diff, view=COLORED_COMPACT_VIEW) |
457 | 457 | 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