Merge "Add in memory filesystem clearing"

This commit is contained in:
Jenkins
2015-04-08 18:01:48 +00:00
committed by Gerrit Code Review
2 changed files with 15 additions and 0 deletions

View File

@@ -141,6 +141,10 @@ class FakeFilesystem(object):
paths.append(child_path)
return paths
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

@@ -113,6 +113,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')