22from deepdiff .helper import COLORED_VIEW , COLORED_COMPACT_VIEW
33from deepdiff .colored_view import RED , GREEN , RESET
44
5+
56def test_colored_view_basic ():
67 t1 = {
78 "name" : "John" ,
@@ -45,6 +46,7 @@ def test_colored_view_basic():
4546}}'''
4647 assert result == expected
4748
49+
4850def test_colored_view_nested_changes ():
4951 t1 = {
5052 "level1" : {
@@ -80,6 +82,7 @@ def test_colored_view_nested_changes():
8082}}'''
8183 assert result == expected
8284
85+
8386def test_colored_view_list_changes ():
8487 t1 = [1 , 2 , 3 , 4 ]
8588 t2 = [1 , 5 , 3 , 6 ]
@@ -95,6 +98,7 @@ def test_colored_view_list_changes():
9598]'''
9699 assert result == expected
97100
101+
98102def test_colored_view_list_deletions ():
99103 t1 = [1 , 2 , 3 , 4 , 5 , 6 ]
100104 t2 = [2 , 4 ]
@@ -112,7 +116,59 @@ def test_colored_view_list_deletions():
112116]'''
113117 assert result == expected
114118
115- def test_colored_view_with_ignore_order ():
119+
120+ def test_colored_view_list_additions ():
121+ t1 = [2 , 4 ]
122+ t2 = [1 , 2 , 3 , 4 , 5 ]
123+
124+ diff = DeepDiff (t1 , t2 , view = COLORED_VIEW )
125+ result = str (diff )
126+
127+ expected = f'''[
128+ { GREEN } 1{ RESET } ,
129+ 2,
130+ { GREEN } 3{ RESET } ,
131+ 4,
132+ { GREEN } 5{ RESET }
133+ ]'''
134+ assert result == expected
135+
136+
137+ def test_colored_view_list_changes_deletions ():
138+ t1 = [1 , 5 , 7 , 3 , 6 ]
139+ t2 = [1 , 2 , 3 , 4 ]
140+
141+ diff = DeepDiff (t1 , t2 , view = COLORED_VIEW )
142+ result = str (diff )
143+
144+ expected = f'''[
145+ 1,
146+ { RED } 5{ RESET } -> { GREEN } 2{ RESET } ,
147+ { RED } 7{ RESET } ,
148+ 3,
149+ { RED } 6{ RESET } -> { GREEN } 4{ RESET }
150+ ]'''
151+ assert result == expected
152+
153+
154+ def test_colored_view_list_changes_additions ():
155+ t1 = [1 , 2 , 3 , 4 ]
156+ t2 = [1 , 5 , 7 , 3 , 6 ]
157+
158+ diff = DeepDiff (t1 , t2 , view = COLORED_VIEW )
159+ result = str (diff )
160+
161+ expected = f'''[
162+ 1,
163+ { RED } 2{ RESET } -> { GREEN } 5{ RESET } ,
164+ { GREEN } 7{ RESET } ,
165+ 3,
166+ { RED } 4{ RESET } -> { GREEN } 6{ RESET }
167+ ]'''
168+ assert result == expected
169+
170+
171+ def test_colored_view_list_no_changes_with_ignore_order ():
116172 t1 = [1 , 2 , 3 ]
117173 t2 = [3 , 2 , 1 ]
118174
@@ -126,7 +182,8 @@ def test_colored_view_with_ignore_order():
126182]'''
127183 assert result == expected
128184
129- def test_colored_view_with_empty_diff ():
185+
186+ def test_colored_view_no_changes ():
130187 t1 = {"a" : 1 , "b" : 2 }
131188 t2 = {"a" : 1 , "b" : 2 }
132189
@@ -139,6 +196,7 @@ def test_colored_view_with_empty_diff():
139196}'''
140197 assert result == expected
141198
199+
142200def test_compact_view_basic ():
143201 t1 = {
144202 "name" : "John" ,
@@ -194,6 +252,7 @@ def test_compact_view_basic():
194252}}'''
195253 assert result == expected
196254
255+
197256def test_compact_view_nested_changes ():
198257 t1 = {
199258 "level1" : {
@@ -251,6 +310,7 @@ def test_compact_view_nested_changes():
251310}}'''
252311 assert result == expected
253312
313+
254314def test_compact_view_no_changes ():
255315 # Test with dict
256316 t1 = {"a" : 1 , "b" : [1 , 2 ], "c" : {"x" : True }}
@@ -264,6 +324,7 @@ def test_compact_view_no_changes():
264324 diff = DeepDiff (t1 , t2 , view = COLORED_COMPACT_VIEW )
265325 assert str (diff ) == "[...]"
266326
327+
267328def test_compact_view_list_changes ():
268329 t1 = [1 , {"a" : 1 , "b" : {"x" : 1 , "y" : 2 }}, [1 , 2 , {"z" : 3 }]]
269330 t2 = [1 , {"a" : 2 , "b" : {"x" : 1 , "y" : 2 }}, [1 , 2 , {"z" : 3 }]]
@@ -281,6 +342,7 @@ def test_compact_view_list_changes():
281342]'''
282343 assert result == expected
283344
345+
284346def test_compact_view_primitive_siblings ():
285347 t1 = {
286348 "changed" : 1 ,
@@ -333,4 +395,3 @@ def test_colored_view_bool_evaluation():
333395 # Scenario 2: With differences
334396 diff_with_diff_compact = DeepDiff (t1_with_diff , t2_with_diff , view = COLORED_COMPACT_VIEW )
335397 assert bool (diff_with_diff_compact ), "bool(diff) should be True when diffs exist (compact view)"
336-
0 commit comments