Skip to content

Commit d76e2e2

Browse files
committed
text view only show new_path for iterable item moved OR if
verbose_level=2 and the new_path is different than path
1 parent 3d3bfd8 commit d76e2e2

File tree

5 files changed

+37
-23
lines changed

5 files changed

+37
-23
lines changed

deepdiff/diff.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,9 @@ def _diff_dict(
587587
notpresent,
588588
t2[key],
589589
child_relationship_class=rel_class,
590-
child_relationship_param=key)
590+
child_relationship_param=key,
591+
child_relationship_param2=key,
592+
)
591593
self._report_result(item_added_key, change_level, local_tree=local_tree)
592594

593595
for key in t_keys_removed:
@@ -599,7 +601,9 @@ def _diff_dict(
599601
t1[key],
600602
notpresent,
601603
child_relationship_class=rel_class,
602-
child_relationship_param=key)
604+
child_relationship_param=key,
605+
child_relationship_param2=key,
606+
)
603607
self._report_result(item_removed_key, change_level, local_tree=local_tree)
604608

605609
for key in t_keys_intersect: # key present in both dicts - need to compare values
@@ -618,7 +622,9 @@ def _diff_dict(
618622
t1[key1],
619623
t2[key2],
620624
child_relationship_class=rel_class,
621-
child_relationship_param=key)
625+
child_relationship_param=key,
626+
child_relationship_param2=key,
627+
)
622628
self._diff(next_level, parents_ids_added, local_tree=local_tree)
623629

624630
def _diff_set(self, level, local_tree=None):
@@ -943,15 +949,19 @@ def _diff_ordered_iterable_by_difflib(
943949
x,
944950
notpresent,
945951
child_relationship_class=child_relationship_class,
946-
child_relationship_param=index + t1_from_index)
952+
child_relationship_param=index + t1_from_index,
953+
child_relationship_param2=index + t1_from_index,
954+
)
947955
self._report_result('iterable_item_removed', change_level, local_tree=local_tree)
948956
elif tag == 'insert':
949957
for index, y in enumerate(level.t2[t2_from_index:t2_to_index]):
950958
change_level = level.branch_deeper(
951959
notpresent,
952960
y,
953961
child_relationship_class=child_relationship_class,
954-
child_relationship_param=index + t2_from_index)
962+
child_relationship_param=index + t2_from_index,
963+
child_relationship_param2=index + t2_from_index,
964+
)
955965
self._report_result('iterable_item_added', change_level, local_tree=local_tree)
956966
return opcodes_with_values
957967

@@ -1501,7 +1511,9 @@ def _diff_numpy_array(self, level, parents_ids=frozenset(), local_tree=None):
15011511
t1_row,
15021512
t2_row,
15031513
child_relationship_class=NumpyArrayRelationship,
1504-
child_relationship_param=t1_path)
1514+
child_relationship_param=t1_path,
1515+
child_relationship_param2=t2_path,
1516+
)
15051517

15061518
self._diff_iterable_in_order(new_level, parents_ids, _original_type=_original_type, local_tree=local_tree)
15071519

deepdiff/model.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ def _from_tree_type_changes(self, tree):
189189
if 'type_changes' in tree:
190190
for change in tree['type_changes']:
191191
path = change.path(force=FORCE_DEFAULT)
192-
new_path = change.path(use_t2=True, force=FORCE_DEFAULT)
193192
if type(change.t1) is type:
194193
include_values = False
195194
old_type = change.t1
@@ -202,8 +201,10 @@ def _from_tree_type_changes(self, tree):
202201
'old_type': old_type,
203202
'new_type': new_type,
204203
})
205-
if path != new_path:
206-
remap_dict['new_path'] = new_path
204+
if self.verbose_level > 1:
205+
new_path = change.path(use_t2=True, force=FORCE_DEFAULT)
206+
if path != new_path:
207+
remap_dict['new_path'] = new_path
207208
self['type_changes'][path] = remap_dict
208209
if self.verbose_level and include_values:
209210
remap_dict.update(old_value=change.t1, new_value=change.t2)
@@ -212,10 +213,11 @@ def _from_tree_value_changed(self, tree):
212213
if 'values_changed' in tree and self.verbose_level > 0:
213214
for change in tree['values_changed']:
214215
path = change.path(force=FORCE_DEFAULT)
215-
new_path = change.path(use_t2=True, force=FORCE_DEFAULT)
216216
the_changed = {'new_value': change.t2, 'old_value': change.t1}
217-
if path != new_path:
218-
the_changed['new_path'] = new_path
217+
if self.verbose_level > 1:
218+
new_path = change.path(use_t2=True, force=FORCE_DEFAULT)
219+
if path != new_path:
220+
the_changed['new_path'] = new_path
219221
self['values_changed'][path] = the_changed
220222
if 'diff' in change.additional:
221223
the_changed.update({'diff': change.additional['diff']})
@@ -717,8 +719,8 @@ def path(self, root="root", force=None, get_parent_too=False, use_t2=False, outp
717719
# traverse all levels of this relationship
718720
while level and level is not self:
719721
# get this level's relationship object
720-
if(use_t2):
721-
next_rel = level.t2_child_rel
722+
if use_t2:
723+
next_rel = level.t2_child_rel or level.t1_child_rel
722724
else:
723725
next_rel = level.t1_child_rel or level.t2_child_rel # next relationship object to get a formatted param from
724726

tests/test_cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ def test_cache_deeply_nested_b(self, nested_b_t1, nested_b_t2, nested_b_result):
6666

6767
stats = diff.get_stats()
6868
expected_stats = {
69-
'PASSES COUNT': 110,
70-
'DIFF COUNT': 306,
69+
'PASSES COUNT': 104,
70+
'DIFF COUNT': 288,
7171
'DISTANCE CACHE HIT COUNT': 0,
7272
'MAX PASS LIMIT REACHED': False,
7373
'MAX DIFF LIMIT REACHED': False

tests/test_distance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def test_get_distance_works_event_when_ignore_order_and_different_hasher(self):
165165
diff = DeepDiff(t1, t2, ignore_order=True, get_deep_distance=True,
166166
cache_size=100, hasher=sha256hex)
167167
dist = diff['deep_distance']
168-
assert str(dist)[:4] == '0.44'
168+
assert str(dist)[:4] == '0.55'
169169

170170
def test_get_distance_does_not_care_about_the_size_of_string(self):
171171
t1 = ["a", "b"]

tests/test_ignore_order.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,8 @@ def test_bool_vs_number(self):
648648

649649
@pytest.mark.parametrize('max_passes, expected', [
650650
(0, {'values_changed': {'root[0]': {'new_value': {'key5': 'CHANGE', 'key6': 'val6'}, 'old_value': {'key3': [[[[[1, 2, 4, 5]]]]], 'key4': [7, 8]}}, 'root[1]': {'new_value': {'key3': [[[[[1, 3, 5, 4]]]]], 'key4': [7, 8]}, 'old_value': {'key5': 'val5', 'key6': 'val6'}}}}),
651-
(1, {'values_changed': {"root[1]['key5']": {'new_value': 'CHANGE', 'old_value': 'val5'}, "root[0]['key3'][0]": {'new_value': [[[[1, 3, 5, 4]]]], 'old_value': [[[[1, 2, 4, 5]]]]}}}),
652-
(22, {'values_changed': {"root[1]['key5']": {'new_value': 'CHANGE', 'old_value': 'val5'}, "root[0]['key3'][0][0][0][0][1]": {'new_value': 3, 'old_value': 2}}})
651+
(1, {'values_changed': {"root[1]['key5']": {'new_value': 'CHANGE', 'old_value': 'val5', 'new_path': "root[0]['key5']"}, "root[0]['key3'][0]": {'new_value': [[[[1, 3, 5, 4]]]], 'old_value': [[[[1, 2, 4, 5]]]], 'new_path': "root[1]['key3'][0]"}}}),
652+
(22, {'values_changed': {"root[1]['key5']": {'new_value': 'CHANGE', 'old_value': 'val5', 'new_path': "root[0]['key5']"}, "root[0]['key3'][0][0][0][0][1]": {'new_value': 3, 'old_value': 2, 'new_path': "root[1]['key3'][0][0][0][0][1]"}}})
653653
])
654654
def test_ignore_order_max_passes(self, max_passes, expected):
655655
t1 = [
@@ -679,8 +679,8 @@ def test_ignore_order_max_passes(self, max_passes, expected):
679679

680680
@pytest.mark.parametrize('max_diffs, expected', [
681681
(1, {}),
682-
(65, {'values_changed': {"root[1]['key5']": {'new_value': 'CHANGE', 'old_value': 'val5'}}}),
683-
(80, {'values_changed': {"root[1]['key5']": {'new_value': 'CHANGE', 'old_value': 'val5'}, "root[0]['key3'][0][0][0][0][1]": {'new_value': 3, 'old_value': 2}}}),
682+
(65, {'values_changed': {"root[1]['key5']": {'new_value': 'CHANGE', 'old_value': 'val5', 'new_path': "root[0]['key5']"}}}),
683+
(80, {'values_changed': {"root[1]['key5']": {'new_value': 'CHANGE', 'old_value': 'val5', 'new_path': "root[0]['key5']"}, "root[0]['key3'][0][0][0][0][1]": {'new_value': 3, 'old_value': 2, 'new_path': "root[1]['key3'][0][0][0][0][1]"}}}),
684684
])
685685
def test_ignore_order_max_diffs(self, max_diffs, expected):
686686
t1 = [
@@ -720,8 +720,8 @@ def test_stats_that_include_distance_cache_hits(self):
720720

721721
diff = DeepDiff(t1, t2, ignore_order=True, cache_size=5000, cutoff_intersection_for_pairs=1)
722722
expected = {
723-
'PASSES COUNT': 7,
724-
'DIFF COUNT': 37,
723+
'PASSES COUNT': 6,
724+
'DIFF COUNT': 33,
725725
'DISTANCE CACHE HIT COUNT': 0,
726726
'MAX PASS LIMIT REACHED': False,
727727
'MAX DIFF LIMIT REACHED': False,

0 commit comments

Comments
 (0)