How to use the deepdiff.contenthash.DeepHash 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_hash_tree.py View on Github external
def test_same_dict_in_list_same_hash(self):
        t1 = [{'b': 5, 'c': 4}]
        t2 = [{'b': 5, 'c': 4}]
        hash1 = DeepHash(t1, view='tree')
        hash2 = DeepHash(t2, view='tree')
        self.assertEqual(hash1["hash"].hash(), hash2["hash"].hash())
github seperman / deepdiff / tests / test_hash_tree.py View on Github external
def test_same_dict_same_hash(self):
        t1 = {'b': 5, 'c': 4}
        t2 = {'b': 5, 'c': 4}
        hash1 = DeepHash(t1, view='tree', hasher=sha1)
        hash2 = DeepHash(t2, view='tree', hasher=sha1)
        self.assertEqual(hash1["hash"].hash(), hash2["hash"].hash())
github seperman / deepdiff / tests / test_hash_tree.py View on Github external
def test_float(self):
        t1 = 3.1415927
        t2 = 3.143

        hash1 = DeepHash(t1, view='tree')
        hash2 = DeepHash(t2, view='tree')

        self.assertNotEqual(hash1["hash"].leaf_hash, hash2["hash"].leaf_hash)
        # Note: ^ different values v
        self.assertNotEqual(hash1["hash"].hash(), hash2["hash"].hash())
        # Note: ^ compares same values v
        self.assertNotEqual(hash1, hash2)
github seperman / deepdiff / tests / test_hash_tree.py View on Github external
def test_set_of_none(self):
        t1 = set()
        t2 = set([None])
        hash1 = DeepHash(t1, view='tree')
        hash2 = DeepHash(t2, view='tree')
        self.assertNotEqual(hash1["hash"].hash(), hash2["hash"].hash())
github seperman / deepdiff / tests / test_hash_tree.py View on Github external
def test_different_dict_in_list_different_hash(self):
        t1 = [{'a': 1, 'b': 2}]
        t2 = [{'a': 1, 'b': 3}]
        hash1 = DeepHash(t1, view='tree', hasher=sha1)
        hash2 = DeepHash(t2, view='tree', hasher=sha1)
        self.assertNotEqual(hash1["hash"].hash(), hash2["hash"].hash())
github seperman / deepdiff / tests / test_hash_tree.py View on Github external
def test_set_of_none(self):
        t1 = set()
        t2 = set([None])
        hash1 = DeepHash(t1, view='tree')
        hash2 = DeepHash(t2, view='tree')
        self.assertNotEqual(hash1["hash"].hash(), hash2["hash"].hash())
github seperman / deepdiff / tests / test_hash_tree.py View on Github external
def test_significant_digits(self):
        t1 = 3.1415927
        t2 = 3.142

        hash1 = DeepHash(t1, view='tree', significant_digits=2)
        hash2 = DeepHash(t2, view='tree', significant_digits=2)

        self.assertEqual(hash1["hash"].leaf_hash, hash2["hash"].leaf_hash)
        self.assertEqual(hash1["hash"].hash(), hash2["hash"].hash())
        self.assertEqual(hash1, hash2)
github seperman / deepdiff / tests / test_hash_tree.py View on Github external
def test_bad_in_list(self):
        bad = Bad()
        obj = [42, 1337, 31337, bad]

        result = DeepHash(obj, view='tree', ignore_repetition=False)
        top = result["hash"]

        # check object structure:
        # get all levels, verify objects in place
        self.assertEqual(top.obj, obj)

        fourtytwo = top.down
        self.assertEqual(fourtytwo.obj, 42)

        leet = top.right.down
        self.assertEqual(leet.obj, 1337)

        elite = top.right.right.down
        self.assertEqual(elite.obj, 31337)

        badobject = top.right.right.right.down
github seperman / deepdiff / tests / test_hash_tree.py View on Github external
def test_significant_false2(self):
        t1 = 3.1415927
        t2 = 3.143

        hash1 = DeepHash(t1, view='tree', significant_digits=256)
        hash2 = DeepHash(t2, view='tree', significant_digits=256)

        self.assertNotEqual(hash1["hash"].leaf_hash, hash2["hash"].leaf_hash)
        self.assertNotEqual(hash1["hash"].hash(), hash2["hash"].hash())
        self.assertNotEqual(hash1, hash2)
github seperman / deepdiff / tests / test_hash_tree.py View on Github external
def test_float(self):
        t1 = 3.1415927
        t2 = 3.143

        hash1 = DeepHash(t1, view='tree')
        hash2 = DeepHash(t2, view='tree')

        self.assertNotEqual(hash1["hash"].leaf_hash, hash2["hash"].leaf_hash)
        # Note: ^ different values v
        self.assertNotEqual(hash1["hash"].hash(), hash2["hash"].hash())
        # Note: ^ compares same values v
        self.assertNotEqual(hash1, hash2)