Commit e0dd1077 by willmcgugan

some enhancements

parent 42961816
...@@ -335,7 +335,22 @@ class FS(object): ...@@ -335,7 +335,22 @@ class FS(object):
return "OS file, maps to %s" % sys_path return "OS file, maps to %s" % sys_path
def open(self, path, mode="r", **kwargs): def open(self, path, mode="r", **kwargs):
raise UNSUPPORTED_ERROR("UNSUPPORTED") raise UnsupportedError("UNSUPPORTED")
def getcontents(self, path):
"""Returns the contents of a file as a string.
path -- path of file to read.
"""
f = None
try:
f = self.open(path, "rb")
contents = f.read()
return contents
finally:
if f is not None:
f.close()
def opendir(self, path): def opendir(self, path):
if not self.exists(path): if not self.exists(path):
......
...@@ -405,6 +405,7 @@ class TestOSFS(unittest.TestCase): ...@@ -405,6 +405,7 @@ class TestOSFS(unittest.TestCase):
word = f7.read(7) word = f7.read(7)
self.assertEqual(word, "complex") self.assertEqual(word, "complex")
f7.close() f7.close()
self.assertEqual(self.fs.getcontents("a.txt"), all_strings)
class TestSubFS(TestOSFS): class TestSubFS(TestOSFS):
......
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