コード例 #1
0
ファイル: test_model.py プロジェクト: seperman/deepdiff
 def test_repetition_attribute_and_repr(self):
     t1 = [1, 1]
     t2 = [1]
     some_repetition = 'some repetition'
     node = DiffLevel(t1, t2)
     node.additional['repetition'] = some_repetition
     assert node.repetition == some_repetition
     assert repr(node) == "<root {'repetition': 'some repetition'}>"
コード例 #2
0
 def test_repetition_attribute_and_repr(self):
     t1 = [1, 1]
     t2 = [1]
     some_repetition = 'some repetition'
     node = DiffLevel(t1, t2)
     node.additional['repetition'] = some_repetition
     self.assertEqual(node.repetition, some_repetition)
     self.assertEqual(repr(node), "<root {'repetition': 'some repetition'}>")
コード例 #3
0
ファイル: test_model.py プロジェクト: tfroehlich82/deepdiff
 def test_repetition_attribute_and_repr(self):
     t1 = [1, 1]
     t2 = [1]
     some_repetition = 'some repetition'
     node = DiffLevel(t1, t2)
     node.additional['repetition'] = some_repetition
     assert node.repetition == some_repetition
     assert repr(node) == "<root {'repetition': 'some repetition'}>"
コード例 #4
0
 def test_repetition_attribute_and_repr(self):
     t1 = [1, 1]
     t2 = [1]
     some_repetition = 'some repetition'
     node = DiffLevel(t1, t2)
     node.additional['repetition'] = some_repetition
     self.assertEqual(node.repetition, some_repetition)
     self.assertEqual(repr(node),
                      "<root {'repetition': 'some repetition'}>")
コード例 #5
0
 def test_path_when_both_children_empty(self):
     """
     This is a situation that should never happen.
     But we are creating it artificially.
     """
     t1 = {1: 1}
     t2 = {1: 2}
     child_t1 = {}
     child_t2 = {}
     up = DiffLevel(t1, t2)
     down = up.down = DiffLevel(child_t1, child_t2)
     path = down.path()
     self.assertEqual(path, 'root')
コード例 #6
0
ファイル: test_model.py プロジェクト: tfroehlich82/deepdiff
 def test_path_when_both_children_empty(self):
     """
     This is a situation that should never happen.
     But we are creating it artificially.
     """
     t1 = {1: 1}
     t2 = {1: 2}
     child_t1 = {}
     child_t2 = {}
     up = DiffLevel(t1, t2)
     down = up.down = DiffLevel(child_t1, child_t2)
     path = down.path()
     assert path == 'root'
     assert down.path(output_format='list') == []
コード例 #7
0
    def setUp(self):
        # Test data
        self.custom1 = CustomClass(a='very long text here', b=37)
        self.custom2 = CustomClass(a=313, b=37)
        self.t1 = {42: 'answer', 'vegan': 'for life', 1337: self.custom1}
        self.t2 = {
            42: 'answer',
            'vegan': 'for the animals',
            1337: self.custom2
        }

        # Manually build diff, bottom up
        self.lowest = DiffLevel(self.custom1.a,
                                self.custom2.a,
                                report_type='values_changed')

        # Test manual child relationship
        rel_int_low_t1 = AttributeRelationship(parent=self.custom1,
                                               child=self.custom1.a,
                                               param="a")
        rel_int_low_t2 = AttributeRelationship(parent=self.custom2,
                                               child=self.custom2.a,
                                               param="a")
        self.intermediate = DiffLevel(self.custom1,
                                      self.custom2,
                                      down=self.lowest,
                                      child_rel1=rel_int_low_t1,
                                      child_rel2=rel_int_low_t2)
        self.lowest.up = self.intermediate

        # Test automatic child relationship
        t1_child_rel = ChildRelationship.create(klass=DictRelationship,
                                                parent=self.t1,
                                                child=self.intermediate.t1,
                                                param=1337)
        t2_child_rel = ChildRelationship.create(klass=DictRelationship,
                                                parent=self.t2,
                                                child=self.intermediate.t2,
                                                param=1337)
        self.highest = DiffLevel(self.t1,
                                 self.t2,
                                 down=self.intermediate,
                                 child_rel1=t1_child_rel,
                                 child_rel2=t2_child_rel)
        self.intermediate.up = self.highest
コード例 #8
0
ファイル: diff.py プロジェクト: xuweibj/deepdiff
    def __init__(self,
                 t1,
                 t2,
                 ignore_order=False,
                 report_repetition=False,
                 significant_digits=None,
                 exclude_paths=None,
                 exclude_regex_paths=None,
                 exclude_types=None,
                 ignore_type_in_groups=None,
                 ignore_string_type_changes=False,
                 ignore_numeric_type_changes=False,
                 verbose_level=1,
                 view=TEXT_VIEW,
                 hasher=DeepHash.murmur3_128bit,
                 **kwargs):
        if kwargs:
            raise ValueError((
                "The following parameter(s) are not valid: %s\n"
                "The valid parameters are ignore_order, report_repetition, significant_digits, "
                "exclude_paths, exclude_types, exclude_regex_paths, ignore_type_in_groups, "
                "ignore_string_type_changes, ignore_numeric_type_changes, verbose_level, view, "
                "and hasher.") % ', '.join(kwargs.keys()))

        self.ignore_order = ignore_order
        self.ignore_type_in_groups = self.get_ignore_types_in_groups(
            ignore_type_in_groups, ignore_string_type_changes,
            ignore_numeric_type_changes)
        self.report_repetition = report_repetition
        self.exclude_paths = convert_item_or_items_into_set_else_none(
            exclude_paths)
        self.exclude_regex_paths = convert_item_or_items_into_compiled_regexes_else_none(
            exclude_regex_paths)
        self.exclude_types = set(exclude_types) if exclude_types else None
        self.exclude_types_tuple = tuple(
            exclude_types
        ) if exclude_types else None  # we need tuple for checking isinstance
        self.ignore_string_type_changes = ignore_string_type_changes
        self.ignore_numeric_type_changes = ignore_numeric_type_changes
        self.hashes = {}
        self.hasher = hasher

        self.significant_digits = self.get_significant_digits(
            significant_digits, ignore_numeric_type_changes)

        self.tree = TreeResult()

        Verbose.level = verbose_level

        root = DiffLevel(t1, t2)
        self.__diff(root, parents_ids=frozenset({id(t1)}))

        self.tree.cleanup()

        self.view = view
        view_results = self._get_view_results(view)
        self.update(view_results)
コード例 #9
0
    def __init__(self,
                 t1,
                 t2,
                 ignore_order=False,
                 report_repetition=False,
                 significant_digits=None,
                 exclude_paths=set(),
                 exclude_types=set(),
                 verbose_level=1,
                 view='text',
                 **kwargs):
        # if kwargs:
        #     raise ValueError((
        #         "The following parameter(s) are not valid: %s\n"
        #         "The valid parameters are ignore_order, report_repetition, significant_digits,"
        #         "exclude_paths, exclude_types, verbose_level and view.") % ', '.join(kwargs.keys()))

        self.ignore_order = ignore_order
        self.report_repetition = report_repetition
        self.exclude_paths = set(exclude_paths)
        self.exclude_types = set(exclude_types)
        self.exclude_types_tuple = tuple(
            exclude_types)  # we need tuple for checking isinstance
        self.hashes = {}
        self.accept_later = kwargs.get('accept_later')
        self.accept_earlier = kwargs.get('accept_earlier')
        self.accept_new = kwargs.get('accept_new')
        self.result_dict = dict()

        if significant_digits is not None and significant_digits < 0:
            raise ValueError(
                "significant_digits must be None or a non-negative integer")
        self.significant_digits = significant_digits

        self.tree = TreeResult()

        Verbose.level = verbose_level

        root = DiffLevel(t1, t2)
        self.__diff(root, parents_ids=frozenset({id(t1)}))

        self.tree.cleanup()

        if view == 'tree':
            self.update(self.tree)
            del self.tree
        else:
            result_text = TextResult(tree_results=self.tree)
            result_text.cleanup()  # clean up text-style result dictionary
            self.update(
                result_text
            )  # be compatible to DeepDiff 2.x if user didn't specify otherwise

        self.result_text = result_text
        self.result_dict = self.dict_result()
コード例 #10
0
    def setUp(self):
        # Test data
        self.custom1 = CustomClass(a='very long text here', b=37)
        self.custom2 = CustomClass(a=313, b=37)
        self.t1 = {42: 'answer', 'vegan': 'for life', 1337: self.custom1}
        self.t2 = {
            42: 'answer',
            'vegan': 'for the animals',
            1337: self.custom2
        }

        # Manually build diff, bottom up
        self.lowest = DiffLevel(
            self.custom1.a, self.custom2.a, report_type='values_changed')

        # Test manual child relationship
        rel_int_low_t1 = AttributeRelationship(
            parent=self.custom1, child=self.custom1.a, param="a")
        rel_int_low_t2 = AttributeRelationship(
            parent=self.custom2, child=self.custom2.a, param="a")
        self.intermediate = DiffLevel(
            self.custom1,
            self.custom2,
            down=self.lowest,
            child_rel1=rel_int_low_t1,
            child_rel2=rel_int_low_t2)
        self.lowest.up = self.intermediate

        # Test automatic child relationship
        t1_child_rel = ChildRelationship.create(
            klass=DictRelationship,
            parent=self.t1,
            child=self.intermediate.t1,
            param=1337)
        t2_child_rel = ChildRelationship.create(
            klass=DictRelationship,
            parent=self.t2,
            child=self.intermediate.t2,
            param=1337)
        self.highest = DiffLevel(
            self.t1,
            self.t2,
            down=self.intermediate,
            child_rel1=t1_child_rel,
            child_rel2=t2_child_rel)
        self.intermediate.up = self.highest
コード例 #11
0
ファイル: diff.py プロジェクト: Moult/deepdiff
    def __init__(self,
                 t1,
                 t2,
                 terminate_on_first=False,
                 skip_after_n=False,
                 ignore_order=False,
                 report_repetition=False,
                 significant_digits=None,
                 number_format_notation="f",
                 exclude_paths=None,
                 exclude_regex_paths=None,
                 exclude_types=None,
                 ignore_type_in_groups=None,
                 ignore_string_type_changes=False,
                 ignore_numeric_type_changes=False,
                 ignore_type_subclasses=False,
                 ignore_string_case=False,
                 number_to_string_func=None,
                 ignore_nan_inequality=False,
                 verbose_level=1,
                 view=TEXT_VIEW,
                 hasher=None,
                 **kwargs):
        if kwargs:
            raise ValueError((
                "The following parameter(s) are not valid: %s\n"
                "The valid parameters are ignore_order, report_repetition, significant_digits, "
                "number_format_notation, exclude_paths, exclude_types, exclude_regex_paths, ignore_type_in_groups, "
                "ignore_string_type_changes, ignore_numeric_type_changes, ignore_type_subclasses, "
                "ignore_nan_inequality, number_to_string_func, verbose_level, view, and hasher."
            ) % ', '.join(kwargs.keys()))

        self.terminate_on_first = terminate_on_first
        self.skip_after_n = skip_after_n
        self.total_diffed = 0
        self.ignore_order = ignore_order
        self.ignore_type_in_groups = self.get_ignore_types_in_groups(
            ignore_type_in_groups=ignore_type_in_groups,
            ignore_string_type_changes=ignore_string_type_changes,
            ignore_numeric_type_changes=ignore_numeric_type_changes,
            ignore_type_subclasses=ignore_type_subclasses)
        self.report_repetition = report_repetition
        self.exclude_paths = convert_item_or_items_into_set_else_none(
            exclude_paths)
        self.exclude_regex_paths = convert_item_or_items_into_compiled_regexes_else_none(
            exclude_regex_paths)
        self.exclude_types = set(exclude_types) if exclude_types else None
        self.exclude_types_tuple = tuple(
            exclude_types
        ) if exclude_types else None  # we need tuple for checking isinstance
        self.ignore_string_type_changes = ignore_string_type_changes
        self.ignore_numeric_type_changes = ignore_numeric_type_changes
        self.ignore_type_subclasses = ignore_type_subclasses
        self.type_check_func = type_is_subclass_of_type_group if ignore_type_subclasses else type_in_type_group
        self.ignore_string_case = ignore_string_case
        self.number_to_string = number_to_string_func or number_to_string
        self.ignore_nan_inequality = ignore_nan_inequality
        self.hashes = {}
        self.hasher = hasher

        self.significant_digits = self.get_significant_digits(
            significant_digits, ignore_numeric_type_changes)
        self.number_format_notation = number_format_notation

        self.tree = TreeResult()

        Verbose.level = verbose_level

        root = DiffLevel(t1, t2)
        self.__diff(root, parents_ids=frozenset({id(t1)}))

        self.tree.cleanup()

        self.view = view
        view_results = self._get_view_results(view)
        self.update(view_results)
コード例 #12
0
class DiffLevelTestCase(TestCase):
    def setUp(self):
        # Test data
        self.custom1 = CustomClass(a='very long text here', b=37)
        self.custom2 = CustomClass(a=313, b=37)
        self.t1 = {42: 'answer', 'vegan': 'for life', 1337: self.custom1}
        self.t2 = {
            42: 'answer',
            'vegan': 'for the animals',
            1337: self.custom2
        }

        # Manually build diff, bottom up
        self.lowest = DiffLevel(self.custom1.a,
                                self.custom2.a,
                                report_type='values_changed')

        # Test manual child relationship
        rel_int_low_t1 = AttributeRelationship(parent=self.custom1,
                                               child=self.custom1.a,
                                               param="a")
        rel_int_low_t2 = AttributeRelationship(parent=self.custom2,
                                               child=self.custom2.a,
                                               param="a")
        self.intermediate = DiffLevel(self.custom1,
                                      self.custom2,
                                      down=self.lowest,
                                      child_rel1=rel_int_low_t1,
                                      child_rel2=rel_int_low_t2)
        self.lowest.up = self.intermediate

        # Test automatic child relationship
        t1_child_rel = ChildRelationship.create(klass=DictRelationship,
                                                parent=self.t1,
                                                child=self.intermediate.t1,
                                                param=1337)
        t2_child_rel = ChildRelationship.create(klass=DictRelationship,
                                                parent=self.t2,
                                                child=self.intermediate.t2,
                                                param=1337)
        self.highest = DiffLevel(self.t1,
                                 self.t2,
                                 down=self.intermediate,
                                 child_rel1=t1_child_rel,
                                 child_rel2=t2_child_rel)
        self.intermediate.up = self.highest

    def test_all_up(self):
        self.assertEqual(self.lowest.all_up, self.highest)

    def test_all_down(self):
        self.assertEqual(self.highest.all_down, self.lowest)

    def test_automatic_child_rel(self):
        self.assertIsInstance(self.highest.t1_child_rel, DictRelationship)
        self.assertIsInstance(self.highest.t2_child_rel, DictRelationship)

        self.assertEqual(self.highest.t1_child_rel.parent, self.highest.t1)
        self.assertEqual(self.highest.t2_child_rel.parent, self.highest.t2)
        self.assertEqual(self.highest.t1_child_rel.parent, self.highest.t1)
        self.assertEqual(self.highest.t2_child_rel.parent, self.highest.t2)

        # Provides textual relationship from t1 to t1[1337]
        self.assertEqual('[1337]', self.highest.t2_child_rel.get_param_repr())

    def test_path(self):
        # Provides textual path all the way through
        self.assertEqual(self.lowest.path("self.t1"), "self.t1[1337].a")

    def test_change_of_path_root(self):
        self.assertEqual(self.lowest.path("root"), "root[1337].a")
        self.assertEqual(self.lowest.path(""), "[1337].a")

    def test_path_when_both_children_empty(self):
        """
        This is a situation that should never happen.
        But we are creating it artificially.
        """
        t1 = {1: 1}
        t2 = {1: 2}
        child_t1 = {}
        child_t2 = {}
        up = DiffLevel(t1, t2)
        down = up.down = DiffLevel(child_t1, child_t2)
        path = down.path()
        self.assertEqual(path, 'root')

    def test_repr_short(self):
        level = Verbose.level
        Verbose.level = 0
        item_repr = repr(self.lowest)
        Verbose.level = level
        self.assertEqual(item_repr, '<root[1337].a>')

    def test_repr_long(self):
        level = Verbose.level
        Verbose.level = 1
        item_repr = repr(self.lowest)
        Verbose.level = level
        self.assertEqual(item_repr,
                         "<root[1337].a t1:'very long t...', t2:313>")

    def test_repetition_attribute_and_repr(self):
        t1 = [1, 1]
        t2 = [1]
        some_repetition = 'some repetition'
        node = DiffLevel(t1, t2)
        node.additional['repetition'] = some_repetition
        self.assertEqual(node.repetition, some_repetition)
        self.assertEqual(repr(node),
                         "<root {'repetition': 'some repetition'}>")
コード例 #13
0
class DiffLevelTestCase(TestCase):
    def setUp(self):
        # Test data
        self.custom1 = CustomClass(a='very long text here', b=37)
        self.custom2 = CustomClass(a=313, b=37)
        self.t1 = {42: 'answer', 'vegan': 'for life', 1337: self.custom1}
        self.t2 = {
            42: 'answer',
            'vegan': 'for the animals',
            1337: self.custom2
        }

        # Manually build diff, bottom up
        self.lowest = DiffLevel(
            self.custom1.a, self.custom2.a, report_type='values_changed')

        # Test manual child relationship
        rel_int_low_t1 = AttributeRelationship(
            parent=self.custom1, child=self.custom1.a, param="a")
        rel_int_low_t2 = AttributeRelationship(
            parent=self.custom2, child=self.custom2.a, param="a")
        self.intermediate = DiffLevel(
            self.custom1,
            self.custom2,
            down=self.lowest,
            child_rel1=rel_int_low_t1,
            child_rel2=rel_int_low_t2)
        self.lowest.up = self.intermediate

        # Test automatic child relationship
        t1_child_rel = ChildRelationship.create(
            klass=DictRelationship,
            parent=self.t1,
            child=self.intermediate.t1,
            param=1337)
        t2_child_rel = ChildRelationship.create(
            klass=DictRelationship,
            parent=self.t2,
            child=self.intermediate.t2,
            param=1337)
        self.highest = DiffLevel(
            self.t1,
            self.t2,
            down=self.intermediate,
            child_rel1=t1_child_rel,
            child_rel2=t2_child_rel)
        self.intermediate.up = self.highest

    def test_all_up(self):
        self.assertEqual(self.lowest.all_up, self.highest)

    def test_all_down(self):
        self.assertEqual(self.highest.all_down, self.lowest)

    def test_automatic_child_rel(self):
        self.assertIsInstance(self.highest.t1_child_rel, DictRelationship)
        self.assertIsInstance(self.highest.t2_child_rel, DictRelationship)

        self.assertEqual(self.highest.t1_child_rel.parent, self.highest.t1)
        self.assertEqual(self.highest.t2_child_rel.parent, self.highest.t2)
        self.assertEqual(self.highest.t1_child_rel.parent, self.highest.t1)
        self.assertEqual(self.highest.t2_child_rel.parent, self.highest.t2)

        # Provides textual relationship from t1 to t1[1337]
        self.assertEqual('[1337]', self.highest.t2_child_rel.get_param_repr())

    def test_path(self):
        # Provides textual path all the way through
        self.assertEqual(self.lowest.path("self.t1"), "self.t1[1337].a")

    def test_change_of_path_root(self):
        self.assertEqual(self.lowest.path("root"), "root[1337].a")
        self.assertEqual(self.lowest.path(""), "[1337].a")

    def test_path_when_both_children_empty(self):
        """
        This is a situation that should never happen.
        But we are creating it artificially.
        """
        t1 = {1: 1}
        t2 = {1: 2}
        child_t1 = {}
        child_t2 = {}
        up = DiffLevel(t1, t2)
        down = up.down = DiffLevel(child_t1, child_t2)
        path = down.path()
        self.assertEqual(path, 'root')

    def test_repr_short(self):
        level = Verbose.level
        Verbose.level = 0
        item_repr = repr(self.lowest)
        Verbose.level = level
        self.assertEqual(item_repr, '<root[1337].a>')

    def test_repr_long(self):
        level = Verbose.level
        Verbose.level = 1
        item_repr = repr(self.lowest)
        Verbose.level = level
        self.assertEqual(item_repr,
                         "<root[1337].a t1:'very long t...', t2:313>")

    def test_repetition_attribute_and_repr(self):
        t1 = [1, 1]
        t2 = [1]
        some_repetition = 'some repetition'
        node = DiffLevel(t1, t2)
        node.additional['repetition'] = some_repetition
        self.assertEqual(node.repetition, some_repetition)
        self.assertEqual(repr(node), "<root {'repetition': 'some repetition'}>")