本文整理汇总了Python中deepdiff.DeepDiff方法的典型用法代码示例。如果您正苦于以下问题:Python deepdiff.DeepDiff方法的具体用法?Python deepdiff.DeepDiff怎么用?Python deepdiff.DeepDiff使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类deepdiff
的用法示例。
在下文中一共展示了deepdiff.DeepDiff方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: compare_objects
# 需要导入模块: import deepdiff [as 别名]
# 或者: from deepdiff import DeepDiff [as 别名]
def compare_objects(first_object, second_object, ignore_order=False, report_repetition=False, significant_digits=None,
exclude_paths=None, exclude_types=None, verbose_level=2):
"""
Return difference between two objects.
:param first_object: first object to compare
:param second_object: second object to compare
:param ignore_order: ignore difference in order
:param report_repetition: report when is repetition
:param significant_digits: use to properly compare numbers(float arithmetic error)
:param exclude_paths: path which be excluded from comparison
:param exclude_types: types which be excluded from comparison
:param verbose_level: higher verbose level shows you more details - default 0.
:return: difference between two objects
"""
if exclude_paths is None:
exclude_paths = set()
if exclude_types is None:
exclude_types = set()
diff = deepdiff.DeepDiff(first_object, second_object, ignore_order=ignore_order,
report_repetition=report_repetition, significant_digits=significant_digits,
exclude_paths=exclude_paths, exclude_types=exclude_types, verbose_level=verbose_level)
return diff
示例2: is_state_definition_equivalent
# 需要导入模块: import deepdiff [as 别名]
# 或者: from deepdiff import DeepDiff [as 别名]
def is_state_definition_equivalent(self):
"""
Compares the desired state and current state definition and returns whether they are equivalent
Only considers fields defined in the desired definition
All fields not specified are left alone in the current state (excluding rules)
Both rules lists must be defined even when empty
Returns:
bool
"""
self.sync_state()
# use filters to remove any extra information
desired_config = pcf_util.param_filter(self.desired_state_definition.get("custom_config", {}),
SecurityGroup.DEFINITION_FILTER)
current_config = pcf_util.param_filter(self.get_current_state_definition(), desired_config.keys())
diff = DeepDiff(current_config, desired_config, ignore_order=True)
return diff == {}
示例3: test_cache_deeply_nested_a1
# 需要导入模块: import deepdiff [as 别名]
# 或者: from deepdiff import DeepDiff [as 别名]
def test_cache_deeply_nested_a1(self, nested_a_t1, nested_a_t2, nested_a_result):
diff = DeepDiff(nested_a_t1, nested_a_t2, ignore_order=True,
cache_size=5000, cache_tuning_sample_size=280,
cutoff_intersection_for_pairs=1)
stats = diff.get_stats()
expected_stats = {
'PASSES COUNT': 1772,
'DIFF COUNT': 9206,
'DISTANCE CACHE HIT COUNT': 3442,
'MAX PASS LIMIT REACHED': False,
'MAX DIFF LIMIT REACHED': False
}
assert expected_stats == stats
assert nested_a_result == diff
diff_of_diff = DeepDiff(nested_a_result, diff.to_dict(), ignore_order=False, ignore_type_in_groups=[(dict, OrderedDictPlus)])
assert not diff_of_diff
示例4: test_delta_dump_and_read3
# 需要导入模块: import deepdiff [as 别名]
# 或者: from deepdiff import DeepDiff [as 别名]
def test_delta_dump_and_read3(self):
t1 = [1, 2]
t2 = [1, 2, 3, 5]
diff = DeepDiff(t1, t2)
delta_content = Delta(diff).dumps()
path = '/tmp/delta_test2.delta'
with open(path, 'wb') as the_file:
the_file.write(delta_content)
with pytest.raises(ValueError) as excinfo:
with open(path, 'r') as the_file:
delta = Delta(delta_file=the_file)
assert BINIARY_MODE_NEEDED_MSG[:20] == str(excinfo.value)[:20]
with open(path, 'rb') as the_file:
delta = Delta(delta_file=the_file)
os.remove(path)
assert delta + t1 == t2
示例5: test_numpy_delta_cases
# 需要导入模块: import deepdiff [as 别名]
# 或者: from deepdiff import DeepDiff [as 别名]
def test_numpy_delta_cases(self, t1, t2, deepdiff_kwargs, to_delta_kwargs, expected_delta_dict, expected_result):
diff = DeepDiff(t1, t2, **deepdiff_kwargs)
delta_dict = diff._to_delta_dict(**to_delta_kwargs)
if expected_delta_dict:
assert expected_delta_dict == delta_dict
delta = Delta(diff, verify_symmetry=False, raise_errors=True)
if expected_result == 't2':
result = delta + t1
assert np.array_equal(result, t2)
elif expected_result == 't2_via_deepdiff':
result = delta + t1
diff = DeepDiff(result, t2, ignore_order=True, report_repetition=True)
assert not diff
elif expected_result is DeltaNumpyOperatorOverrideError:
with pytest.raises(DeltaNumpyOperatorOverrideError):
assert t1 + delta
else:
result = delta + t1
assert np.array_equal(result, expected_result)
示例6: test_apply_delta_to_incompatible_object10_ignore_order
# 需要导入模块: import deepdiff [as 别名]
# 或者: from deepdiff import DeepDiff [as 别名]
def test_apply_delta_to_incompatible_object10_ignore_order(self, mock_logger):
t1 = [1, 2, 'B']
t2 = [1, 2]
t3 = [1, 2, 'C']
diff = DeepDiff(t1, t2, ignore_order=True, report_repetition=True)
# when verify_symmetry=False, we still won't remove the item that is different
# than what we expect specifically when ignore_order=True when generating the diff.
# The reason is that when ignore_order=True, we can' rely too much on the index
# of the item alone to delete it. We need to make sure we are deleting the correct value.
# The expected behavior is exactly the same as when verify_symmetry=True
# specifically for when ignore_order=True AND an item is removed.
delta = Delta(diff, raise_errors=False, verify_symmetry=False)
t4 = delta + t3
assert [1, 2, 'C'] == t4
expected_msg = FAIL_TO_REMOVE_ITEM_IGNORE_ORDER_MSG.format(2, 'root', 'B', 'C')
mock_logger.assert_called_once_with(expected_msg)
示例7: test_distance_of_list_sets_and_strings
# 需要导入模块: import deepdiff [as 别名]
# 或者: from deepdiff import DeepDiff [as 别名]
def test_distance_of_list_sets_and_strings(self, verbose_level):
t1 = [{1, 2, 3}, {4, 5, 'hello', 'right!'}, {4, 5, (2, 4, 7)}]
t2 = [{4, 5, 6, (2, )}, {1, 2, 3}, {5, 'hello', 'right!'}]
ddiff = DeepDiff(t1, t2, ignore_order=True, view=DELTA_VIEW, verbose_level=verbose_level)
delta = ddiff._to_delta_dict(report_repetition_required=False)
expected = {
'set_item_removed': {
'root[1]': {4}
},
'iterable_items_added_at_indexes': {
'root': {
0: {(2, ), 4, 5, 6}
}
},
'iterable_items_removed_at_indexes': {
'root': {
2: {4, 5, (2, 4, 7)}
}
}
}
assert expected == ddiff
# If the diff was in delta view, spitting out another delta dict should produce identical results.
assert delta == ddiff
assert 10 == _get_item_length(ddiff)
示例8: test_non_subscriptable_iterable
# 需要导入模块: import deepdiff [as 别名]
# 或者: from deepdiff import DeepDiff [as 别名]
def test_non_subscriptable_iterable(self):
t1 = (i for i in [42, 1337, 31337])
t2 = (i for i in [
42,
1337,
])
ddiff = DeepDiff(t1, t2, view='tree')
(change, ) = ddiff['iterable_item_removed']
assert set(ddiff.keys()) == {'iterable_item_removed'}
assert len(ddiff['iterable_item_removed']) == 1
assert change.up.t1 == t1
assert change.up.t2 == t2
assert change.report_type == 'iterable_item_removed'
assert change.t1 == 31337
assert change.t2 is notpresent
assert isinstance(change.up.t1_child_rel,
NonSubscriptableIterableRelationship)
assert change.up.t2_child_rel is None
示例9: test_ignore_order_depth5
# 需要导入模块: import deepdiff [as 别名]
# 或者: from deepdiff import DeepDiff [as 别名]
def test_ignore_order_depth5(self):
t1 = [4, 2, 2, 1]
t2 = [4, 1, 1, 1]
ddiff = DeepDiff(t1, t2, ignore_order=True, report_repetition=True, cache_purge_level=0)
expected = {
'iterable_item_removed': {
'root[1]': 2,
'root[2]': 2
},
'repetition_change': {
'root[3]': {
'old_repeat': 1,
'new_repeat': 3,
'old_indexes': [3],
'new_indexes': [1, 2, 3],
'value': 1
}
}
}
assert expected == ddiff
ddiff = DeepDiff(t1, t2, ignore_order=True, report_repetition=False, cache_purge_level=0)
dist = ddiff._get_rough_distance()
assert 0.1 == dist
示例10: test_ignore_order_depth6
# 需要导入模块: import deepdiff [as 别名]
# 或者: from deepdiff import DeepDiff [as 别名]
def test_ignore_order_depth6(self):
t1 = [[1, 2, 3, 4], [4, 2, 2, 1]]
t2 = [[4, 1, 1, 1], [1, 3, 2, 4]]
ddiff = DeepDiff(t1, t2, ignore_order=True, report_repetition=True)
expected = {
'iterable_item_removed': {
'root[1][1]': 2,
'root[1][2]': 2
},
'repetition_change': {
'root[1][3]': {
'old_repeat': 1,
'new_repeat': 3,
'old_indexes': [3],
'new_indexes': [1, 2, 3],
'value': 1
}
}
}
assert expected == ddiff
示例11: test_nested_list_ignore_order_report_repetition_wrong_currently
# 需要导入模块: import deepdiff [as 别名]
# 或者: from deepdiff import DeepDiff [as 别名]
def test_nested_list_ignore_order_report_repetition_wrong_currently(self):
t1 = [1, 2, [3, 4]]
t2 = [[4, 3, 3], 2, 1]
ddiff = DeepDiff(t1, t2, ignore_order=True, report_repetition=True)
result = {
'repetition_change': {
'root[2][0]': {
'old_repeat': 1,
'new_indexes': [1, 2],
'old_indexes': [1],
'value': 3,
'new_repeat': 2
}
}
}
assert result != ddiff
示例12: test_list_of_unhashable_difference_ignore_order2
# 需要导入模块: import deepdiff [as 别名]
# 或者: from deepdiff import DeepDiff [as 别名]
def test_list_of_unhashable_difference_ignore_order2(self):
t1 = [1, {"a": 2}, {"b": [3, 4, {1: 1}]}, "B"]
t2 = [{"b": [3, 4, {1: 1}]}, {"a": 2}, {1: 1}]
ddiff = DeepDiff(t1, t2, ignore_order=True)
result = {
'iterable_item_added': {
'root[2]': {
1: 1
}
},
'iterable_item_removed': {
'root[3]': 'B',
'root[0]': 1
}
}
assert result == ddiff
示例13: test_list_of_unhashable_difference_ignore_order3
# 需要导入模块: import deepdiff [as 别名]
# 或者: from deepdiff import DeepDiff [as 别名]
def test_list_of_unhashable_difference_ignore_order3(self):
t1 = [1, {"a": 2}, {"a": 2}, {"b": [3, 4, {1: 1}]}, "B"]
t2 = [{"b": [3, 4, {1: 1}]}, {1: 1}]
ddiff = DeepDiff(t1, t2, ignore_order=True)
result = {
'values_changed': {
'root[1]': {
'new_value': {
1: 1
},
'old_value': {
'a': 2
}
}
},
'iterable_item_removed': {
'root[0]': 1,
'root[4]': 'B'
}
}
assert result == ddiff
示例14: test_list_of_unhashable_difference_ignore_order_report_repetition
# 需要导入模块: import deepdiff [as 别名]
# 或者: from deepdiff import DeepDiff [as 别名]
def test_list_of_unhashable_difference_ignore_order_report_repetition(
self):
t1 = [1, {"a": 2}, {"a": 2}, {"b": [3, 4, {1: 1}]}, "B"]
t2 = [{"b": [3, 4, {1: 1}]}, {1: 1}]
ddiff = DeepDiff(t1, t2, ignore_order=True, report_repetition=True)
result = {
'iterable_item_added': {
'root[1]': {
1: 1
}
},
'iterable_item_removed': {
'root[4]': 'B',
'root[0]': 1,
'root[1]': {
'a': 2
},
'root[2]': {
'a': 2
}
}
}
assert result == ddiff
示例15: test_list_of_unhashable_difference_ignore_order_report_repetition2
# 需要导入模块: import deepdiff [as 别名]
# 或者: from deepdiff import DeepDiff [as 别名]
def test_list_of_unhashable_difference_ignore_order_report_repetition2(
self):
t1 = [{"a": 2}, {"a": 2}]
t2 = [{"a": 2}]
ddiff = DeepDiff(t1, t2, ignore_order=True, report_repetition=True)
result = {
'repetition_change': {
'root[0]': {
'old_repeat': 2,
'new_indexes': [0],
'old_indexes': [0, 1],
'value': {
'a': 2
},
'new_repeat': 1
}
}
}
assert result == ddiff