How to use the deepdiff.model.DiffLevel function in deepdiff

To help you get started, we’ve selected a few deepdiff examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github seperman / deepdiff / tests / test_model.py View on Github external
child_rel1=rel_int_low_t1,
            child_rel2=rel_int_low_t2)
        cls.lowest.up = cls.intermediate

        # Test automatic child relationship
        t1_child_rel = ChildRelationship.create(
            klass=DictRelationship,
            parent=cls.t1,
            child=cls.intermediate.t1,
            param=1337)
        t2_child_rel = ChildRelationship.create(
            klass=DictRelationship,
            parent=cls.t2,
            child=cls.intermediate.t2,
            param=1337)
        cls.highest = DiffLevel(
            cls.t1,
            cls.t2,
            down=cls.intermediate,
            child_rel1=t1_child_rel,
            child_rel2=t2_child_rel)
        cls.intermediate.up = cls.highest
github seperman / deepdiff / tests / test_model.py View on Github external
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'
github seperman / deepdiff / tests / test_model.py View on Github external
def setup_class(cls):
        # Test data
        cls.custom1 = CustomClass(a='very long text here', b=37)
        cls.custom2 = CustomClass(a=313, b=37)
        cls.t1 = {42: 'answer', 'vegan': 'for life', 1337: cls.custom1}
        cls.t2 = {
            42: 'answer',
            'vegan': 'for the animals',
            1337: cls.custom2
        }

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

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

        # Test automatic child relationship
github seperman / deepdiff / tests / test_model.py View on Github external
cls.t2 = {
            42: 'answer',
            'vegan': 'for the animals',
            1337: cls.custom2
        }

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

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

        # Test automatic child relationship
        t1_child_rel = ChildRelationship.create(
            klass=DictRelationship,
            parent=cls.t1,
            child=cls.intermediate.t1,
            param=1337)
        t2_child_rel = ChildRelationship.create(
            klass=DictRelationship,
            parent=cls.t2,
github seperman / deepdiff / tests / test_model.py View on Github external
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'
github seperman / deepdiff / tests / test_model.py View on Github external
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) == ""
github seperman / deepdiff / deepdiff / model.py View on Github external
def __init__(self,
                 objs = [],
                 down=None,
                 up=None,
                 report_type=None,
                 child_rels=[],
                 additional=None,
                 verbose_level=1):
        """
        See BaseLevel.__init__ for common params.
        """
        super(DiffLevel, self).__init__(objs, down, up, child_rels, additional)

        # self.left   # this gets set by the base class constructor
        """
        This level's content in the left hand tree.
        self.left.obj will be the payload object; self.t1 is available as an alias
        """

        # self.right  # this gets set by the base class constructor
        """
        This level's content in the right hand tree.
        self.right.obj will be the payload object; self.t2 is available as an alias
        """

        self.report_type = report_type
        """
        If this object is this change's deepest level, this contains a string describing the type of change.
github seperman / deepdiff / deepdiff / diff.py View on Github external
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)