How to use the deepdiff.model.ChildRelationship.create 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
def test_create_invalid_klass(self):
        with pytest.raises(TypeError):
            ChildRelationship.create(DiffLevel, "hello", 42)
github seperman / deepdiff / tests / test_model.py View on Github external
# 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,
            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_max(self):
        rel = ChildRelationship.create(SubscriptableIterableRelationship,
                                       self.l, self.custom, 2)
        assert rel.get_param_repr() == "[2]"
github seperman / deepdiff / tests / test_model.py View on Github external
def test_strkey(self):
        rel = ChildRelationship.create(
            klass=DictRelationship,
            parent=self.d,
            child=self.d['vegan'],
            param='vegan')
        result = rel.get_param_repr()
        assert result == "['vegan']"
github seperman / deepdiff / tests / test_model.py View on Github external
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,
            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 / deepdiff / model.py View on Github external
def auto_generate_child_rel(self, klass, param):
        """
        Auto-populates the child_rel attribute of all my LevelContent attributes.
        If I'm a DiffLevel, this populates the self.child_rel1 and self.child_rel2 aliases.
        This requires self.down to be another valid BaseLevel object of the same kind.
        :param klass: A ChildRelationship subclass describing the kind of parent-child relationship,
                      e.g. DictRelationship.
        :param param: A ChildRelationship subclass-dependent parameter describing how to get from parent to child,
                      e.g. the key in a dict
        """
        sides = zip_longest(self.level_contents(), self.down.level_contents())
        for (self_level_content, down_level_content) in sides:
            if down_level_content.obj is not NotPresentHere:
                self_level_content.child_rel = ChildRelationship.create(
                    klass=klass,
                    parent=self_level_content.obj,
                    child=down_level_content.obj,
                    param=param)