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)
def test_distance_of_the_same_objects(self): t1 = [{1, 2, 3}, {4, 5, 6}] t2 = [{4, 5, 6}, {1, 2, 3}] ddiff = DeepDiff(t1, t2, ignore_order=True, cache_purge_level=0) assert {} == ddiff assert 0 == _get_item_length(ddiff) assert '0' == str(ddiff._get_rough_distance())[:10] assert 9 == ddiff._DistanceMixin__get_item_rough_length(ddiff.t1) assert 9 == ddiff._DistanceMixin__get_item_rough_length(ddiff.t2)
def test_distance_of_list_sets(self): t1 = [{1, 2, 3}, {4, 5}] t2 = [{4, 5, 6}, {1, 2, 3}] ddiff = DeepDiff(t1, t2, ignore_order=True, cache_purge_level=0) delta = ddiff._to_delta_dict(report_repetition_required=False) assert {'set_item_added': {'root[1]': {6}}} == delta assert 1 == _get_item_length(ddiff) assert '0.05882352' == str(ddiff._get_rough_distance())[:10] assert 8 == ddiff._DistanceMixin__get_item_rough_length(ddiff.t1) assert 9 == ddiff._DistanceMixin__get_item_rough_length(ddiff.t2)
def test_distance_of_list_sets2(self, verbose_level): t1 = [{1, 2, 3}, {4, 5}, {1}] t2 = [{4, 5, 6}, {1, 2, 3}, {1, 4}] ddiff = DeepDiff(t1, t2, ignore_order=True, verbose_level=verbose_level, get_deep_distance=True, cache_purge_level=0) delta = ddiff._to_delta_dict(report_repetition_required=False) assert {'set_item_added': {'root[2]': {4}, 'root[1]': {6}}} == delta assert 2 == _get_item_length(ddiff) assert '0.09090909' == str(ddiff['deep_distance'])[:10] assert 10 == ddiff._DistanceMixin__get_item_rough_length(ddiff.t1) assert 12 == ddiff._DistanceMixin__get_item_rough_length(ddiff.t2)
def test_item_length(self, diff, expected_length): length = _get_item_length(diff) assert expected_length == length
def test_get_item_length_custom_class2_loop(self): item = CustomClass(a=10) item.b = item item_length = _get_item_length(item) assert 2 == item_length
def test_get_item_length_when_loops2(self): t1 = {1: 1} t1[2] = t1 item_length = _get_item_length(t1) assert 2 == item_length
def test_get_item_length_when_loops1(self): t1 = [[1, 2, 1, 3]] t1.append(t1) item_length = _get_item_length(t1) assert 8 == item_length