Commit 851fadda by willmcgugan

Tests now pass on Windows

parent d6848353
...@@ -604,8 +604,12 @@ class FS(object): ...@@ -604,8 +604,12 @@ class FS(object):
dst_syspath = self.getsyspath(dst, allow_none=True) dst_syspath = self.getsyspath(dst, allow_none=True)
if src_syspath is not None and dst_syspath is not None: if src_syspath is not None and dst_syspath is not None:
try:
shutil.move(src_syspath, dst_syspath) shutil.move(src_syspath, dst_syspath)
else: return
except WindowsError:
pass
def movefile_noerrors(src, dst): def movefile_noerrors(src, dst):
try: try:
......
...@@ -28,7 +28,7 @@ class OSFS(FS): ...@@ -28,7 +28,7 @@ class OSFS(FS):
__repr__ = __str__ __repr__ = __str__
def getsyspath(self, path, allow_none=False): def getsyspath(self, path, allow_none=False):
sys_path = os.path.join(self.root_path, makerelative(self._resolve(path))) sys_path = os.path.join(self.root_path, makerelative(self._resolve(path))).replace('/', os.sep)
return sys_path return sys_path
def open(self, path, mode="r", **kwargs): def open(self, path, mode="r", **kwargs):
...@@ -77,10 +77,17 @@ class OSFS(FS): ...@@ -77,10 +77,17 @@ class OSFS(FS):
os.mkdir(sys_path, mode) os.mkdir(sys_path, mode)
except OSError, e: except OSError, e:
if allow_recreate: if allow_recreate:
if e.errno !=17: if e.errno != 17:
raise OperationFailedError("MAKEDIR_FAILED", path) raise OperationFailedError("MAKEDIR_FAILED", path)
else: else:
raise OperationFailedError("MAKEDIR_FAILED", path) raise OperationFailedError("MAKEDIR_FAILED", path)
except WindowsError, e:
if allow_recreate:
if e.errno != 183:
raise OperationFailedError("MAKEDIR_FAILED", path)
else:
raise OperationFailedError("MAKEDIR_FAILED", path)
except OSError, e: except OSError, e:
if e.errno == 17: if e.errno == 17:
return return
......
...@@ -28,9 +28,10 @@ class TempFS(OSFS): ...@@ -28,9 +28,10 @@ class TempFS(OSFS):
def __unicode__(self): def __unicode__(self):
return unicode(self.__str__()) return unicode(self.__str__())
def _cleanup(self): def close(self):
"""Called by __del__ to remove the temporary directory. Can be called directly, """Removes the temporary directory.
but it is probably not neccesary.""" This will be called automatically when the object is cleaned up by Python.
Note that once this method has been called, the FS object may no longer be used."""
if not self._cleaned: if not self._cleaned:
self._lock.acquire() self._lock.acquire()
...@@ -41,7 +42,7 @@ class TempFS(OSFS): ...@@ -41,7 +42,7 @@ class TempFS(OSFS):
self._lock.release() self._lock.release()
def __del__(self): def __del__(self):
self._cleanup() self.close()
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -357,8 +357,12 @@ class TestOSFS(unittest.TestCase): ...@@ -357,8 +357,12 @@ class TestOSFS(unittest.TestCase):
def test_readwriteappendseek(self): def test_readwriteappendseek(self):
def checkcontents(path, check_contents): def checkcontents(path, check_contents):
f = None
try:
f = self.fs.open(path, "rb") f = self.fs.open(path, "rb")
read_contents = f.read() read_contents = f.read()
finally:
if f is not None:
f.close() f.close()
return read_contents == check_contents return read_contents == check_contents
test_strings = ["Beautiful is better than ugly.", test_strings = ["Beautiful is better than ugly.",
...@@ -390,15 +394,15 @@ class TestOSFS(unittest.TestCase): ...@@ -390,15 +394,15 @@ class TestOSFS(unittest.TestCase):
f4.write(test_strings[2]) f4.write(test_strings[2])
f4.close() f4.close()
self.assert_(checkcontents("b.txt", test_strings[2])) self.assert_(checkcontents("b.txt", test_strings[2]))
f5 = self.fs.open("c.txt", "wt") f5 = self.fs.open("c.txt", "wb")
for s in test_strings: for s in test_strings:
f5.write(s+"\n") f5.write(s+"\n")
f5.close() f5.close()
f6 = self.fs.open("c.txt", "rt") f6 = self.fs.open("c.txt", "rb")
for s, t in zip(f6, test_strings): for s, t in zip(f6, test_strings):
self.assertEqual(s, t+"\n") self.assertEqual(s, t+"\n")
f6.close() f6.close()
f7 = self.fs.open("c.txt", "rt") f7 = self.fs.open("c.txt", "rb")
f7.seek(13) f7.seek(13)
word = f7.read(6) word = f7.read(6)
self.assertEqual(word, "better") self.assertEqual(word, "better")
...@@ -412,6 +416,7 @@ class TestOSFS(unittest.TestCase): ...@@ -412,6 +416,7 @@ class TestOSFS(unittest.TestCase):
self.assertEqual(self.fs.getcontents("a.txt"), all_strings) self.assertEqual(self.fs.getcontents("a.txt"), all_strings)
class TestSubFS(TestOSFS): class TestSubFS(TestOSFS):
def setUp(self): def setUp(self):
...@@ -466,7 +471,7 @@ class TestTempFS(TestOSFS): ...@@ -466,7 +471,7 @@ class TestTempFS(TestOSFS):
def tearDown(self): def tearDown(self):
td = self.fs._temp_dir td = self.fs._temp_dir
del self.fs self.fs.close()
self.assert_(not os.path.exists(td)) self.assert_(not os.path.exists(td))
def check(self, p): def check(self, p):
......
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