Commit 851fadda by willmcgugan

Tests now pass on Windows

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