Commit a5ffbc28 by willmcgugan

Got tests working again

parent 4dff3320
......@@ -45,7 +45,7 @@ List contents of [PATH]"""
if iswildcard(path):
path, wildcard = pathsplit(path)
if path != '.' and fs.isfile(path):
if not options.dirsonly:
file_paths.append(path)
......
......@@ -208,7 +208,7 @@ class Command(object):
help="make output verbose", metavar="VERBOSE")
return optparse
def run(self):
def run(self):
parser = self.get_optparse()
options, args = parser.parse_args()
args = [unicode(arg, sys.getfilesystemencoding()) for arg in args]
......
......@@ -253,30 +253,16 @@ class RemoteFileBuffer(FileWrapper):
if "w" in self.mode or "a" in self.mode or "+" in self.mode:
pos = self.wrapped_file.tell()
self.wrapped_file.seek(0)
# chunk_size = 64*1024
# f = None
# try:
# f = self.fs.wrapped_fs.open(self.path, 'wb')
# chunk = self.wrapped_file.read(chunk_size)
# while chunk:
# f.write(chunk)
# chunk = self.wrapped_file.read(chunk_size)
# finally:
# if f is not None:
# f.close()
self.fs.setcontents(self.path, self.wrapped_file)
self.fs.setcontents(self.path, self.wrapped_file)
self.wrapped_file.seek(pos)
def close(self):
def close(self):
with self._lock:
if not self.closed:
if not self.closed:
self._setcontents()
if self._rfile is not None:
self._rfile.close()
super(RemoteFileBuffer,self).close()
super(RemoteFileBuffer,self).close()
class ConnectionManagerFS(LazyFS):
......@@ -345,6 +331,7 @@ class ConnectionManagerFS(LazyFS):
if not self._poll_thread:
target = self._poll_connection
self._poll_thread = threading.Thread(target=target)
self._poll_thread.daemon = True
self._poll_thread.start()
self._connection_cond.wait(timeout)
finally:
......
......@@ -24,8 +24,8 @@ def re_raise_faults(func):
try:
return func(*args,**kwds)
except xmlrpclib.Fault, f:
import traceback
traceback.print_exc()
#import traceback
#traceback.print_exc()
# Make sure it's in a form we can handle
bits = f.faultString.split(" ")
if bits[0] not in ["<type","<class"]:
......
......@@ -102,51 +102,21 @@ class SFTPFS(FS):
hostname, port = connection
except ValueError:
pass
hostkeytype = None
hostkey = None
if hostname is not None:
try:
host_keys = paramiko.util.load_host_keys(os.path.expanduser('~/.ssh/known_hosts'))
except IOError:
try:
# try ~/ssh/ too, because windows can't have a folder named ~/.ssh/
host_keys = paramiko.util.load_host_keys(os.path.expanduser('~/ssh/known_hosts'))
except IOError:
host_keys = {}
if host_keys.has_key(hostname):
hostkeytype = host_keys[hostname].keys()[0]
hostkey = host_keys[hostname][hostkeytype]
credentials['hostkey'] = hostkey
if not credentials.get('username'):
credentials['username'] = getuser()
super(SFTPFS, self).__init__()
super(SFTPFS, self).__init__()
self.root_path = abspath(normpath(root_path))
if isinstance(connection,paramiko.Channel):
self._transport = None
self._client = paramiko.SFTPClient(connection)
else:
if not isinstance(connection, paramiko.Transport):
else:
if not isinstance(connection,paramiko.Transport):
connection = paramiko.Transport(connection)
self._owns_transport = True
try:
if not connection.is_authenticated():
connection.connect(**credentials)
if not connection.is_authenticated():
self._agent_auth(connection, credentials.get('username'))
if not connection.is_authenticated():
connection.close()
raise RemoteConnectionError('No auth')
except paramiko.AuthenticationException:
raise RemoteConnectionError('Auth rejected')
if not connection.is_authenticated():
connection.connect(**credentials)
self._transport = connection
self.root_path = abspath(normpath(root_path))
@classmethod
def _agent_auth(cls, transport, username):
......
......@@ -761,7 +761,9 @@ class ThreadingTestCases:
func()
except Exception:
errors.append(sys.exc_info())
return threading.Thread(target=runThread)
thread = threading.Thread(target=runThread)
thread.daemon = True
return thread
def _runThreads(self,*funcs):
check_interval = sys.getcheckinterval()
......
......@@ -38,7 +38,7 @@ class TestRPCFS(unittest.TestCase,FSTestCases,ThreadingTestCases):
raise
self.server_addr = ("localhost",port)
self.serve_more_requests = True
self.server_thread = threading.Thread(target=self.runServer)
self.server_thread = threading.Thread(target=self.runServer)
self.server_thread.start()
def runServer(self):
......@@ -197,3 +197,5 @@ if dokan.is_available:
self.mount_proc.terminate()
self.temp_fs.close()
if __name__ == '__main__':
unittest.main()
\ No newline at end of file
......@@ -229,7 +229,7 @@ class TestCacheFS(unittest.TestCase,FSTestCases,ThreadingTestCases):
sys.setcheckinterval(self._check_interval)
class TestConnectionManagerFS(unittest.TestCase,FSTestCases,ThreadingTestCases):
class TestConnectionManagerFS(unittest.TestCase,FSTestCases):#,ThreadingTestCases):
"""Test simple operation of ConnectionManagerFS"""
def setUp(self):
......@@ -255,6 +255,7 @@ class DisconnectingFS(WrapFS):
if random.choice([True,False]):
raise RemoteConnectionError("")
self._bounce_thread = threading.Thread(target=self._bounce)
self._bounce_thread.daemon = True
self._bounce_thread.start()
def __getstate__(self):
......@@ -265,6 +266,7 @@ class DisconnectingFS(WrapFS):
def __setstate__(self,state):
super(DisconnectingFS,self).__setstate__(state)
self._bounce_thread = threading.Thread(target=self._bounce)
self._bounce_thread.daemon = True
self._bounce_thread.start()
def _bounce(self):
......
......@@ -168,7 +168,7 @@ def copystructure(src_fs, dst_fs):
"""
for path in src_fs.walkdirs(wildcard="depth"):
for path in src_fs.walkdirs():
dst_fs.makedir(path, allow_recreate=True)
......@@ -291,7 +291,7 @@ def find_duplicates(fs,
return
def identical(p1, p2):
""" Returns True if the contests of two files are identical. """
""" Returns True if the contents of two files are identical. """
f1, f2 = None, None
try:
f1 = fs.open(p1, 'rb')
......@@ -397,7 +397,7 @@ def print_fs(fs, path='/', max_levels=5, file_out=None, terminal_colors=None, hi
try:
dir_listing = ( [(True, p) for p in fs.listdir(path, dirs_only=True)] +
[(False, p) for p in fs.listdir(path, files_only=True)] )
[(False, p) for p in fs.listdir(path, files_only=True)] )
except Exception, e:
prefix = ''.join([('| ', ' ')[last] for last in levels]) + ' '
write(wrap_prefix(prefix[:-1] + ' ') + wrap_error("unabled to retrieve directory list (%s) ..." % str(e)))
......
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