Commit d4e33c63 by rfkelly0

Fix test_open_on_directory for SFTPFS

parent 6f3827d0
...@@ -49,8 +49,6 @@ systems with Dokan installed. ...@@ -49,8 +49,6 @@ systems with Dokan installed.
# All rights reserved; available under the terms of the MIT License. # All rights reserved; available under the terms of the MIT License.
import sys import sys
if sys.platform != "win32":
raise ImportError("Dokan is only available on win32")
import os import os
import signal import signal
...@@ -61,9 +59,6 @@ import subprocess ...@@ -61,9 +59,6 @@ import subprocess
import pickle import pickle
import datetime import datetime
import ctypes import ctypes
from ctypes.wintypes import LPCWSTR, WCHAR
kernel32 = ctypes.windll.kernel32
from fs.base import threading from fs.base import threading
from fs.errors import * from fs.errors import *
...@@ -72,13 +67,14 @@ from fs.local_functools import wraps ...@@ -72,13 +67,14 @@ from fs.local_functools import wraps
try: try:
import libdokan import libdokan
except (NotImplementedError,EnvironmentError,ImportError): except (NotImplementedError,EnvironmentError,ImportError,NameError,):
is_available = False is_available = False
sys.modules.pop("fs.expose.dokan.libdokan",None) sys.modules.pop("fs.expose.dokan.libdokan",None)
libdokan = None libdokan = None
else: else:
is_available = True is_available = True
from ctypes.wintypes import LPCWSTR, WCHAR
kernel32 = ctypes.windll.kernel32
# Options controlling the behaiour of the Dokan filesystem # Options controlling the behaiour of the Dokan filesystem
DOKAN_OPTION_DEBUG = 1 DOKAN_OPTION_DEBUG = 1
......
...@@ -136,12 +136,12 @@ class SFTPFS(FS): ...@@ -136,12 +136,12 @@ class SFTPFS(FS):
@convert_os_errors @convert_os_errors
def open(self,path,mode="r",bufsize=-1): def open(self,path,mode="r",bufsize=-1):
npath = self._normpath(path) npath = self._normpath(path)
# paramiko implements its own buffering and write-back logic,
# so we don't need to use a RemoteFileBuffer here.
f = self.client.open(npath,mode,bufsize)
if self.isdir(path): if self.isdir(path):
msg = "that's a directory: %(path)s" msg = "that's a directory: %(path)s"
raise ResourceInvalidError(path,msg=msg) raise ResourceInvalidError(path,msg=msg)
# paramiko implements its own buffering and write-back logic,
# so we don't need to use a RemoteFileBuffer here.
f = self.client.open(npath,mode,bufsize)
return f return f
@convert_os_errors @convert_os_errors
......
...@@ -70,7 +70,15 @@ class FSTestCases(object): ...@@ -70,7 +70,15 @@ class FSTestCases(object):
def test_open_on_directory(self): def test_open_on_directory(self):
self.fs.makedir("testdir") self.fs.makedir("testdir")
self.assertRaises(ResourceInvalidError,self.fs.open,"testdir") try:
self.fs.open("testdir")
except ResourceInvalidError:
pass
except Exception:
ecls = sys.exc_info[0]
assert False, "%s raised instead of ResourceInvalidError" % (ecls,)
else:
assert False, "ResourceInvalidError was not raised"
def test_writefile(self): def test_writefile(self):
self.assertRaises(ResourceNotFoundError,self.fs.open,"test1.txt") self.assertRaises(ResourceNotFoundError,self.fs.open,"test1.txt")
......
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