Commit 29cab8cf by rfkelly0

FTPFS: raise ResourceInvalidError when open() is called on a directory

parent 081ea835
...@@ -956,6 +956,8 @@ class FTPFS(FS): ...@@ -956,6 +956,8 @@ class FTPFS(FS):
@ftperrors @ftperrors
def open(self, path, mode='r'): def open(self, path, mode='r'):
mode = mode.lower() mode = mode.lower()
if self.isdir(path):
raise ResourceInvalidError(path)
if 'r' in mode: if 'r' in mode:
if not self.isfile(path): if not self.isfile(path):
raise ResourceNotFoundError(path) raise ResourceNotFoundError(path)
......
...@@ -21,6 +21,7 @@ import os, os.path ...@@ -21,6 +21,7 @@ import os, os.path
import pickle import pickle
import random import random
import copy import copy
from StringIO import StringIO
import time import time
try: try:
...@@ -75,7 +76,7 @@ class FSTestCases(object): ...@@ -75,7 +76,7 @@ class FSTestCases(object):
except ResourceInvalidError: except ResourceInvalidError:
pass pass
except Exception: except Exception:
ecls = sys.exc_info[0] ecls = sys.exc_info()[0]
assert False, "%s raised instead of ResourceInvalidError" % (ecls,) assert False, "%s raised instead of ResourceInvalidError" % (ecls,)
else: else:
f.close() f.close()
...@@ -98,6 +99,14 @@ class FSTestCases(object): ...@@ -98,6 +99,14 @@ class FSTestCases(object):
self.assertEquals(f.read(),"test file overwrite") self.assertEquals(f.read(),"test file overwrite")
f.close() f.close()
def test_setcontents(self):
# setcontents() should accept both a string...
self.fs.setcontents("hello","world")
self.assertEquals(self.fs.getcontents("hello"),"world")
# ...and a file-like object
self.fs.setcontents("hello",StringIO("to you, good sir!"))
self.assertEquals(self.fs.getcontents("hello"),"to you, good sir!")
def test_isdir_isfile(self): def test_isdir_isfile(self):
self.assertFalse(self.fs.exists("dir1")) self.assertFalse(self.fs.exists("dir1"))
self.assertFalse(self.fs.isdir("dir1")) self.assertFalse(self.fs.isdir("dir1"))
...@@ -703,7 +712,7 @@ class ThreadingTestCases: ...@@ -703,7 +712,7 @@ class ThreadingTestCases:
finally: finally:
sys.setcheckinterval(check_interval) sys.setcheckinterval(check_interval)
def test_setcontents(self): def test_setcontents_threaded(self):
def setcontents(name,contents): def setcontents(name,contents):
f = self.fs.open(name,"w") f = self.fs.open(name,"w")
self._yield() self._yield()
...@@ -722,7 +731,7 @@ class ThreadingTestCases: ...@@ -722,7 +731,7 @@ class ThreadingTestCases:
self.assertEquals(self.fs.getcontents("thread2.txt"),c) self.assertEquals(self.fs.getcontents("thread2.txt"),c)
self._runThreads(thread1,thread2) self._runThreads(thread1,thread2)
def test_setcontents_samefile(self): def test_setcontents_threaded_samefile(self):
def setcontents(name,contents): def setcontents(name,contents):
f = self.fs.open(name,"w") f = self.fs.open(name,"w")
self._yield() self._yield()
......
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