Commit b6db31f6 by willmcgugan

Work in progress

parent d6ec7a9d
......@@ -51,6 +51,9 @@ class MemoryFile(object):
assert self.mem_file is not None, "self.mem_file should have a value"
self.closed = False
def __str__(self):
return "<MemoryFile in %s %s>" % (self.memory_fs, self.path)
def __del__(self):
if not self.closed:
self.close()
......
......@@ -9,14 +9,32 @@ class TempFS(OSFS):
"""Create a Filesystem in a tempory directory (with tempfile.mkdtemp),
and removes it when the TempFS object is cleaned up."""
def __init__(self):
self._temp_dir = tempfile.mkdtemp("fstest")
def __init__(self, identifier=None):
"""Creates a temporary Filesystem
identifier -- A string that is included in the name of the temporary directory,
default uses "TempFS"
"""
self._temp_dir = tempfile.mkdtemp(identifier or "TempFS")
self._cleaned = False
OSFS.__init__(self, self._temp_dir)
def __str__(self):
return '<TempFS in "%s">' % self._temp_dir
def _cleanup(self):
if self._temp_dir:
"""Called by __del__ to remove the temporary directory. Can be called directly,
but it is probably not advisable."""
if not self._cleaned:
rmtree(self._temp_dir)
self._temp_dir = ""
self._cleaned = True
def __del__(self):
self._cleanup()
if __name__ == "__main__":
tfs = TempFS()
print tfs
\ No newline at end of file
......@@ -150,6 +150,11 @@ class TestOSFS(unittest.TestCase):
def check(self, p):
return os.path.exists(os.path.join(self.temp_dir, makerelative(p)))
def test_debug(self):
str(self.fs)
repr(self.fs)
self.assert_(hasattr(self.fs, 'desc'))
def test_makedir(self):
check = self.check
......@@ -166,6 +171,8 @@ class TestOSFS(unittest.TestCase):
self.fs.makedir("a/b/child")
self.assert_(check("a/b/child"))
self.fs.desc("a")
self.fs.desc("a/b/child")
def test_removedir(self):
check = self.check
......@@ -247,6 +254,7 @@ class TestOSFS(unittest.TestCase):
f.close()
info = self.fs.getinfo("info.txt")
self.assertEqual(info['size'], len(test_str))
self.fs.desc("info.txt")
def test_getsize(self):
test_str = "*"*23
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment