Add in memory filesystem clearing

Change-Id: Ibd22eddeec87f660e729099f702f52cdd6b828ea
This commit is contained in:
Joshua Harlow
2015-03-24 15:43:23 -07:00
committed by Joshua Harlow
parent 179854e3ee
commit f11579bba4
2 changed files with 15 additions and 0 deletions

View File

@@ -114,6 +114,10 @@ class FakeFilesystem(object):
"""Return list of all children of the given path."""
return [node.item for node in self._fetch_node(path)]
def clear(self):
for node in list(self._root.reverse_iter()):
node.disassociate()
def _iter_pieces(self, path, include_root=False):
if path == self._root.item:
# Check for this directly as the following doesn't work with

View File

@@ -84,6 +84,17 @@ class MemoryFilesystemTest(test.TestCase):
path += "/" + p
self.assertIsNone(fs[path])
def test_clear(self):
fs = impl_memory.FakeFilesystem()
paths = ['/b', '/c', '/a/b/c']
for p in paths:
fs.ensure_path(p)
for p in paths:
self.assertIsNone(self._get_item_path(fs, p))
fs.clear()
for p in paths:
self.assertRaises(exc.NotFound, self._get_item_path, fs, p)
def test_not_found(self):
fs = impl_memory.FakeFilesystem()
self.assertRaises(exc.NotFound, self._get_item_path, fs, '/c')