Merge "Ensure empty paths raise a value error"

This commit is contained in:
Jenkins
2015-05-30 03:08:42 +00:00
committed by Gerrit Code Review
2 changed files with 9 additions and 0 deletions

View File

@@ -75,6 +75,9 @@ class FakeFilesystem(object):
@classmethod
def normpath(cls, path):
"""Return a normalized absolutized version of the pathname path."""
if not path:
raise ValueError("This filesystem can only normalize paths"
" that are not empty")
if not path.startswith(cls.root_path):
raise ValueError("This filesystem can only normalize"
" paths that start with %s: '%s' is not"

View File

@@ -128,6 +128,12 @@ class MemoryFilesystemTest(test.TestCase):
fs = impl_memory.FakeFilesystem()
self.assertRaises(exc.NotFound, self._get_item_path, fs, '/c')
def test_bad_norms(self):
fs = impl_memory.FakeFilesystem()
self.assertRaises(ValueError, fs.normpath, '')
self.assertRaises(ValueError, fs.normpath, 'abc/c')
self.assertRaises(ValueError, fs.normpath, '../c')
def test_del_root_not_allowed(self):
fs = impl_memory.FakeFilesystem()
self.assertRaises(ValueError, self._del_item_path, fs, '/')