dulwich-users team mailing list archive
-
dulwich-users team
-
Mailing list archive
-
Message #00227
[PATCH] Added unit tests for dulwich.object_store.tree_lookup_path.
* dulwich/tests/test_object_store.py
(TreeLookupPathTests): This test case contains a few tests that ensure the
tree_lookup_path function works as expected.
---
dulwich/tests/test_object_store.py | 47 ++++++++++++++++++++++++++++++++++++
1 files changed, 47 insertions(+), 0 deletions(-)
diff --git a/dulwich/tests/test_object_store.py b/dulwich/tests/test_object_store.py
index 646b3a5..8cc59ff 100644
--- a/dulwich/tests/test_object_store.py
+++ b/dulwich/tests/test_object_store.py
@@ -26,14 +26,20 @@ import tempfile
from dulwich.index import (
commit_tree,
)
+from dulwich.errors import (
+ NotTreeError,
+ )
from dulwich.objects import (
object_class,
Blob,
+ ShaFile,
Tag,
+ Tree,
)
from dulwich.object_store import (
DiskObjectStore,
MemoryObjectStore,
+ tree_lookup_path,
)
from dulwich.pack import (
write_pack_data,
@@ -199,4 +205,45 @@ class DiskObjectStoreTests(PackBasedObjectStoreTests, TestCase):
commit()
+class TreeLookupPathTests(TestCase):
+
+ def setUp(self):
+ TestCase.setUp(self)
+ self.store = MemoryObjectStore()
+ blob_a = make_object(Blob, data='a')
+ blob_b = make_object(Blob, data='b')
+ blob_c = make_object(Blob, data='c')
+ for blob in [blob_a, blob_b, blob_c]:
+ self.store.add_object(blob)
+
+ blobs = [
+ ('a', blob_a.id, 0100644),
+ ('ad/b', blob_b.id, 0100644),
+ ('ad/bd/c', blob_c.id, 0100755),
+ ('ad/c', blob_c.id, 0100644),
+ ('c', blob_c.id, 0100644),
+ ]
+ self.tree_id = commit_tree(self.store, blobs)
+
+ def get_object(self, sha):
+ return self.store[sha]
+
+ def test_lookup_blob(self):
+ o_id = tree_lookup_path(self.get_object, self.tree_id, 'a')[1]
+ self.assertTrue(isinstance(self.store[o_id], Blob))
+
+ def test_lookup_tree(self):
+ o_id = tree_lookup_path(self.get_object, self.tree_id, 'ad')[1]
+ self.assertTrue(isinstance(self.store[o_id], Tree))
+ o_id = tree_lookup_path(self.get_object, self.tree_id, 'ad/bd')[1]
+ self.assertTrue(isinstance(self.store[o_id], Tree))
+ o_id = tree_lookup_path(self.get_object, self.tree_id, 'ad/bd/')[1]
+ self.assertTrue(isinstance(self.store[o_id], Tree))
+
+ def test_lookup_nonexistent(self):
+ self.assertRaises(KeyError, tree_lookup_path, self.get_object, self.tree_id, 'j')
+
+ def test_lookup_not_tree(self):
+ self.assertRaises(NotTreeError, tree_lookup_path, self.get_object, self.tree_id, 'ad/b/j')
+
# TODO: MissingObjectFinderTests
--
1.6.5.3
Follow ups