From: Brian Warner Date: Sun, 21 Jan 2007 04:14:41 +0000 (-0700) Subject: filetree: start testing IVirtualDrive, beginning with list() X-Git-Tag: tahoe_v0.1.0-0-UNSTABLE~341 X-Git-Url: https://git.rkrishnan.org/components/com_hotproperty/css/%3C?a=commitdiff_plain;h=324033c9e2e9b03dca82dc32ababfbaa5e1a2420;p=tahoe-lafs%2Ftahoe-lafs.git filetree: start testing IVirtualDrive, beginning with list() --- diff --git a/src/allmydata/filetree/directory.py b/src/allmydata/filetree/directory.py index 859e36f7..91613e6e 100644 --- a/src/allmydata/filetree/directory.py +++ b/src/allmydata/filetree/directory.py @@ -44,7 +44,7 @@ class SubTreeNode: # self.child_specifications = {} def list(self): - return sorted(self.children.keys()) + return self.children def get(self, childname): if childname in self.children: diff --git a/src/allmydata/filetree/redirect.py b/src/allmydata/filetree/redirect.py index b7fa12a9..bfd54016 100644 --- a/src/allmydata/filetree/redirect.py +++ b/src/allmydata/filetree/redirect.py @@ -30,7 +30,7 @@ class _BaseRedirection(object): return ([], self.child_node, path) def serialize_subtree_to_file(self, f): - return self.child_node.serialize_node() + f.write(self.child_node.serialize_node()) def _populate_from_data(self, data, node_maker): assert INodeMaker(node_maker) diff --git a/src/allmydata/filetree/vdrive.py b/src/allmydata/filetree/vdrive.py index 64e78b69..63e7271f 100644 --- a/src/allmydata/filetree/vdrive.py +++ b/src/allmydata/filetree/vdrive.py @@ -46,6 +46,8 @@ class NodeMaker(object): return node raise RuntimeError("unable to handle node type '%s'" % prefix) + + all_openable_subtree_types = [ directory.LocalFileSubTree, directory.CHKDirectorySubTree, @@ -102,6 +104,7 @@ class SubTreeMaker(object): return subtree + class VirtualDrive(object): implements(IVirtualDrive) @@ -137,12 +140,8 @@ class VirtualDrive(object): return d def _get_closest_node_1(self, subtree, path): - d = subtree.get_node_for_path(path) - d.addCallback(self._get_closest_node_2, subtree.is_mutable()) - return d - - def _get_closest_node_2(self, res, parent_is_mutable): - (found_path, node, remaining_path) = res + (found_path, node, remaining_path) = subtree.get_node_for_path(path) + parent_is_mutable = subtree.is_mutable() if IDirectoryNode.providedBy(node): # traversal done return (node, remaining_path) diff --git a/src/allmydata/test/test_filetree_new.py b/src/allmydata/test/test_filetree_new.py index cb592837..6a94e1b5 100644 --- a/src/allmydata/test/test_filetree_new.py +++ b/src/allmydata/test/test_filetree_new.py @@ -335,10 +335,10 @@ class Stuff(unittest.TestCase): v = vdrive.VirtualDrive(wq, dl, root_node) return v + def failUnlessListsAreEqual(self, list1, list2): + self.failUnlessEqual(sorted(list1), sorted(list2)) + def testDirectory(self): - # TODO: we only need this VirtualDrive for the opener. Perhaps - # make_subtree_from_node should move out of that class and into a - # module-level function. stm = vdrive.SubTreeMaker(None, None) # create an empty directory (stored locally) @@ -352,7 +352,7 @@ class Stuff(unittest.TestCase): self.failUnlessEqual(remaining_path, []) self.failUnless(INode.providedBy(root)) self.failUnless(IDirectoryNode.providedBy(root)) - self.failUnlessEqual(root.list(), []) + self.failUnlessListsAreEqual(root.list().keys(), []) self.failUnlessIdentical(root.get_subtree(), subtree) # now add some children to it @@ -360,13 +360,14 @@ class Stuff(unittest.TestCase): file1 = CHKFileNode() file1.new("uri1") root.add("foo.txt", file1) - self.failUnlessEqual(root.list(), ["foo.txt", "subdir1"]) + self.failUnlessListsAreEqual(root.list().keys(), + ["foo.txt", "subdir1"]) self.failUnlessIdentical(root.get("foo.txt"), file1) subdir1a = root.get("subdir1") self.failUnlessIdentical(subdir1, subdir1a) del subdir1a self.failUnless(IDirectoryNode.providedBy(subdir1)) - self.failUnlessEqual(subdir1.list(), []) + self.failUnlessListsAreEqual(subdir1.list().keys(), []) self.failUnlessIdentical(subdir1.get_subtree(), subtree) subdir2 = subdir1.add_subdir("subdir2") @@ -374,7 +375,7 @@ class Stuff(unittest.TestCase): subdir4 = subdir2.add_subdir("subdir4") subdir2.delete("subdir4") - self.failUnlessEqual(subdir2.list(), ["subdir3"]) + self.failUnlessListsAreEqual(subdir2.list().keys(), ["subdir3"]) del root, subdir1, subdir2, subdir3, subdir4 # leaving file1 for later use @@ -409,7 +410,8 @@ class Stuff(unittest.TestCase): self.failUnlessEqual(remaining_path, []) self.failUnless(INode.providedBy(root)) self.failUnless(IDirectoryNode.providedBy(root)) - self.failUnlessEqual(root.list(), ["foo.txt", "subdir1"]) + self.failUnlessListsAreEqual(root.list().keys(), + ["foo.txt", "subdir1"]) file1a = root.get("foo.txt") self.failUnless(INode(file1a)) self.failUnless(isinstance(file1a, CHKFileNode)) @@ -417,27 +419,23 @@ class Stuff(unittest.TestCase): self.failUnlessEqual(file1a.get_uri(), "uri1") subdir1 = root.get("subdir1") subdir2 = subdir1.get("subdir2") - self.failUnlessEqual(subdir2.list(), ["subdir3"]) + self.failUnlessListsAreEqual(subdir2.list().keys(), ["subdir3"]) subdir2.delete("subdir3") - self.failUnlessEqual(subdir2.list(), []) + self.failUnlessListsAreEqual(subdir2.list().keys(), []) d.addCallback(_opened) return d def testVdrive(self): - # create some stuff, see if we can import everything - - # create an empty directory (stored locally) as our root - root = directory.LocalFileSubTree() - root.new("dirtree.save") - - # and a node to point to it - root_node = directory.LocalFileSubTreeNode() - root_node.new("dirtree.save") - - v = self.makeVirtualDrive("test_filetree_new/testVdrive", root_node) + topdir = directory.LocalFileSubTree().new("vdrive-dirtree.save") + topdir.update_now(None) + root = redirect.LocalFileRedirection().new("vdrive-root", + topdir.create_node_now()) + root.update_now(None) + wq = self.makeVirtualDrive("vdrive", root.create_node_now()) + + d = wq.list([]) + def _listed(contents): + self.failUnlessEqual(contents, {}) + d.addCallback(_listed) + return d - def start(): - root_node = redirect.LocalFileRedirectionNode() -# root_node.new("handle", dirtree) - root = redirect.LocalFileRedirection() - # wow, bootstrapping is hard