Changeset View
Changeset View
Standalone View
Standalone View
swh/model/tests/test_merkle.py
Show First 20 Lines • Show All 166 Lines • ▼ Show 20 Lines | class TestMerkleNode(unittest.TestCase): | ||||
def test_collect(self): | def test_collect(self): | ||||
collected = self.root.collect() | collected = self.root.collect() | ||||
self.assertEqual(len(collected[self.root.object_type]), len(self.nodes)) | self.assertEqual(len(collected[self.root.object_type]), len(self.nodes)) | ||||
for node in self.nodes.values(): | for node in self.nodes.values(): | ||||
self.assertTrue(node.collected) | self.assertTrue(node.collected) | ||||
collected2 = self.root.collect() | collected2 = self.root.collect() | ||||
self.assertEqual(collected2, {}) | self.assertEqual(collected2, {}) | ||||
def test_iter_tree(self): | def test_iter_tree_with_deduplication(self): | ||||
zack: maybe you can rename this test case to `test_iter_tree_with_deduplication`, for clearer output… | |||||
nodes = list(self.root.iter_tree()) | nodes = list(self.root.iter_tree()) | ||||
self.assertCountEqual(nodes, self.nodes.values()) | self.assertCountEqual(nodes, self.nodes.values()) | ||||
def test_iter_tree_without_deduplication(self): | |||||
# duplicate existing hash in merkle tree | |||||
self.root[b"d"] = MerkleTestNode({"value": b"root/c/c/c"}) | |||||
nodes_dedup = list(self.root.iter_tree()) | |||||
nodes = list(self.root.iter_tree(dedup=False)) | |||||
assert nodes != nodes_dedup | |||||
assert len(nodes) == len(nodes_dedup) + 1 | |||||
def test_get(self): | def test_get(self): | ||||
for key in (b"a", b"b", b"c"): | for key in (b"a", b"b", b"c"): | ||||
self.assertEqual(self.root[key], self.nodes[b"root/" + key]) | self.assertEqual(self.root[key], self.nodes[b"root/" + key]) | ||||
with self.assertRaisesRegex(KeyError, "b'nonexistent'"): | with self.assertRaisesRegex(KeyError, "b'nonexistent'"): | ||||
self.root[b"nonexistent"] | self.root[b"nonexistent"] | ||||
def test_del(self): | def test_del(self): | ||||
▲ Show 20 Lines • Show All 61 Lines • Show Last 20 Lines |
maybe you can rename this test case to test_iter_tree_with_deduplication, for clearer output wrt the newly added one