diff --git a/deepdiff/diff.py b/deepdiff/diff.py index 3b5d2c6..9b05e00 100755 --- a/deepdiff/diff.py +++ b/deepdiff/diff.py @@ -587,7 +587,9 @@ def _diff_dict( notpresent, t2[key], child_relationship_class=rel_class, - child_relationship_param=key) + child_relationship_param=key, + child_relationship_param2=key, + ) self._report_result(item_added_key, change_level, local_tree=local_tree) for key in t_keys_removed: @@ -599,7 +601,9 @@ def _diff_dict( t1[key], notpresent, child_relationship_class=rel_class, - child_relationship_param=key) + child_relationship_param=key, + child_relationship_param2=key, + ) self._report_result(item_removed_key, change_level, local_tree=local_tree) for key in t_keys_intersect: # key present in both dicts - need to compare values @@ -618,7 +622,9 @@ def _diff_dict( t1[key1], t2[key2], child_relationship_class=rel_class, - child_relationship_param=key) + child_relationship_param=key, + child_relationship_param2=key, + ) self._diff(next_level, parents_ids_added, local_tree=local_tree) def _diff_set(self, level, local_tree=None): @@ -943,7 +949,9 @@ def _diff_ordered_iterable_by_difflib( x, notpresent, child_relationship_class=child_relationship_class, - child_relationship_param=index + t1_from_index) + child_relationship_param=index + t1_from_index, + child_relationship_param2=index + t1_from_index, + ) self._report_result('iterable_item_removed', change_level, local_tree=local_tree) elif tag == 'insert': for index, y in enumerate(level.t2[t2_from_index:t2_to_index]): @@ -951,7 +959,9 @@ def _diff_ordered_iterable_by_difflib( notpresent, y, child_relationship_class=child_relationship_class, - child_relationship_param=index + t2_from_index) + child_relationship_param=index + t2_from_index, + child_relationship_param2=index + t2_from_index, + ) self._report_result('iterable_item_added', change_level, local_tree=local_tree) return opcodes_with_values @@ -1501,7 +1511,9 @@ def _diff_numpy_array(self, level, parents_ids=frozenset(), local_tree=None): t1_row, t2_row, child_relationship_class=NumpyArrayRelationship, - child_relationship_param=t1_path) + child_relationship_param=t1_path, + child_relationship_param2=t2_path, + ) self._diff_iterable_in_order(new_level, parents_ids, _original_type=_original_type, local_tree=local_tree) diff --git a/deepdiff/model.py b/deepdiff/model.py index f07d499..f375fcd 100644 --- a/deepdiff/model.py +++ b/deepdiff/model.py @@ -189,7 +189,6 @@ def _from_tree_type_changes(self, tree): if 'type_changes' in tree: for change in tree['type_changes']: path = change.path(force=FORCE_DEFAULT) - new_path = change.path(use_t2=True, force=FORCE_DEFAULT) if type(change.t1) is type: include_values = False old_type = change.t1 @@ -202,8 +201,10 @@ def _from_tree_type_changes(self, tree): 'old_type': old_type, 'new_type': new_type, }) - if path != new_path: - remap_dict['new_path'] = new_path + if self.verbose_level > 1: + new_path = change.path(use_t2=True, force=FORCE_DEFAULT) + if path != new_path: + remap_dict['new_path'] = new_path self['type_changes'][path] = remap_dict if self.verbose_level and include_values: remap_dict.update(old_value=change.t1, new_value=change.t2) @@ -212,10 +213,11 @@ def _from_tree_value_changed(self, tree): if 'values_changed' in tree and self.verbose_level > 0: for change in tree['values_changed']: path = change.path(force=FORCE_DEFAULT) - new_path = change.path(use_t2=True, force=FORCE_DEFAULT) the_changed = {'new_value': change.t2, 'old_value': change.t1} - if path != new_path: - the_changed['new_path'] = new_path + if self.verbose_level > 1: + new_path = change.path(use_t2=True, force=FORCE_DEFAULT) + if path != new_path: + the_changed['new_path'] = new_path self['values_changed'][path] = the_changed if 'diff' in change.additional: 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 # traverse all levels of this relationship while level and level is not self: # get this level's relationship object - if(use_t2): - next_rel = level.t2_child_rel + if use_t2: + next_rel = level.t2_child_rel or level.t1_child_rel else: next_rel = level.t1_child_rel or level.t2_child_rel # next relationship object to get a formatted param from diff --git a/tests/test_cache.py b/tests/test_cache.py index e9779b4..ec1ff08 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -66,8 +66,8 @@ def test_cache_deeply_nested_b(self, nested_b_t1, nested_b_t2, nested_b_result): stats = diff.get_stats() expected_stats = { - 'PASSES COUNT': 110, - 'DIFF COUNT': 306, + 'PASSES COUNT': 104, + 'DIFF COUNT': 288, 'DISTANCE CACHE HIT COUNT': 0, 'MAX PASS LIMIT REACHED': False, 'MAX DIFF LIMIT REACHED': False diff --git a/tests/test_distance.py b/tests/test_distance.py index 3aed3a7..64f5d94 100644 --- a/tests/test_distance.py +++ b/tests/test_distance.py @@ -165,7 +165,7 @@ def test_get_distance_works_event_when_ignore_order_and_different_hasher(self): diff = DeepDiff(t1, t2, ignore_order=True, get_deep_distance=True, cache_size=100, hasher=sha256hex) dist = diff['deep_distance'] - assert str(dist)[:4] == '0.44' + assert str(dist)[:4] == '0.55' def test_get_distance_does_not_care_about_the_size_of_string(self): t1 = ["a", "b"] diff --git a/tests/test_ignore_order.py b/tests/test_ignore_order.py index ddcc006..d162db7 100644 --- a/tests/test_ignore_order.py +++ b/tests/test_ignore_order.py @@ -648,8 +648,8 @@ def test_bool_vs_number(self): @pytest.mark.parametrize('max_passes, expected', [ (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'}}}}), - (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]]]]}}}), - (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}}}) + (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]"}}}), + (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]"}}}) ]) def test_ignore_order_max_passes(self, max_passes, expected): t1 = [ @@ -679,8 +679,8 @@ def test_ignore_order_max_passes(self, max_passes, expected): @pytest.mark.parametrize('max_diffs, expected', [ (1, {}), - (65, {'values_changed': {"root[1]['key5']": {'new_value': 'CHANGE', 'old_value': 'val5'}}}), - (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}}}), + (65, {'values_changed': {"root[1]['key5']": {'new_value': 'CHANGE', 'old_value': 'val5', 'new_path': "root[0]['key5']"}}}), + (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]"}}}), ]) def test_ignore_order_max_diffs(self, max_diffs, expected): t1 = [ @@ -720,8 +720,8 @@ def test_stats_that_include_distance_cache_hits(self): diff = DeepDiff(t1, t2, ignore_order=True, cache_size=5000, cutoff_intersection_for_pairs=1) expected = { - 'PASSES COUNT': 7, - 'DIFF COUNT': 37, + 'PASSES COUNT': 6, + 'DIFF COUNT': 33, 'DISTANCE CACHE HIT COUNT': 0, 'MAX PASS LIMIT REACHED': False, 'MAX DIFF LIMIT REACHED': False,