summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorScott Maxwell <scott@codecobblers.com>2013-10-30 16:46:33 -0700
committerScott Maxwell <scott@codecobblers.com>2013-10-30 16:46:33 -0700
commit2ea352b8baf1037bd22fc79146ef646c163a7692 (patch)
tree439892d24b7659bb4345790af09582aaa0162377 /tests
parent6bd1e42b43017c8df3edd826fad5aca798538b10 (diff)
Fix dict iters, sorts, exceptions, bytes renames and tuple args
Diffstat (limited to 'tests')
-rw-r--r--tests/stub_sftp.py42
-rw-r--r--tests/test_transport.py14
-rw-r--r--tests/test_util.py6
3 files changed, 39 insertions, 23 deletions
diff --git a/tests/stub_sftp.py b/tests/stub_sftp.py
index e5f44543..b8bea9b5 100644
--- a/tests/stub_sftp.py
+++ b/tests/stub_sftp.py
@@ -40,7 +40,8 @@ class StubSFTPHandle (SFTPHandle):
def stat(self):
try:
return SFTPAttributes.from_stat(os.fstat(self.readfile.fileno()))
- except OSError, e:
+ except OSError:
+ e = sys.exc_info()[1]
return SFTPServer.convert_errno(e.errno)
def chattr(self, attr):
@@ -49,7 +50,8 @@ class StubSFTPHandle (SFTPHandle):
try:
SFTPServer.set_file_attr(self.filename, attr)
return SFTP_OK
- except OSError, e:
+ except OSError:
+ e = sys.exc_info()[1]
return SFTPServer.convert_errno(e.errno)
@@ -71,21 +73,24 @@ class StubSFTPServer (SFTPServerInterface):
attr.filename = fname
out.append(attr)
return out
- except OSError, e:
+ except OSError:
+ e = sys.exc_info()[1]
return SFTPServer.convert_errno(e.errno)
def stat(self, path):
path = self._realpath(path)
try:
return SFTPAttributes.from_stat(os.stat(path))
- except OSError, e:
+ except OSError:
+ e = sys.exc_info()[1]
return SFTPServer.convert_errno(e.errno)
def lstat(self, path):
path = self._realpath(path)
try:
return SFTPAttributes.from_stat(os.lstat(path))
- except OSError, e:
+ except OSError:
+ e = sys.exc_info()[1]
return SFTPServer.convert_errno(e.errno)
def open(self, path, flags, attr):
@@ -100,7 +105,8 @@ class StubSFTPServer (SFTPServerInterface):
# os.open() defaults to 0777 which is
# an odd default mode for files
fd = os.open(path, flags, 0666)
- except OSError, e:
+ except OSError:
+ e = sys.exc_info()[1]
return SFTPServer.convert_errno(e.errno)
if (flags & os.O_CREAT) and (attr is not None):
attr._flags &= ~attr.FLAG_PERMISSIONS
@@ -120,7 +126,8 @@ class StubSFTPServer (SFTPServerInterface):
fstr = 'rb'
try:
f = os.fdopen(fd, fstr)
- except OSError, e:
+ except OSError:
+ e = sys.exc_info()[1]
return SFTPServer.convert_errno(e.errno)
fobj = StubSFTPHandle(flags)
fobj.filename = path
@@ -132,7 +139,8 @@ class StubSFTPServer (SFTPServerInterface):
path = self._realpath(path)
try:
os.remove(path)
- except OSError, e:
+ except OSError:
+ e = sys.exc_info()[1]
return SFTPServer.convert_errno(e.errno)
return SFTP_OK
@@ -141,7 +149,8 @@ class StubSFTPServer (SFTPServerInterface):
newpath = self._realpath(newpath)
try:
os.rename(oldpath, newpath)
- except OSError, e:
+ except OSError:
+ e = sys.exc_info()[1]
return SFTPServer.convert_errno(e.errno)
return SFTP_OK
@@ -151,7 +160,8 @@ class StubSFTPServer (SFTPServerInterface):
os.mkdir(path)
if attr is not None:
SFTPServer.set_file_attr(path, attr)
- except OSError, e:
+ except OSError:
+ e = sys.exc_info()[1]
return SFTPServer.convert_errno(e.errno)
return SFTP_OK
@@ -159,7 +169,8 @@ class StubSFTPServer (SFTPServerInterface):
path = self._realpath(path)
try:
os.rmdir(path)
- except OSError, e:
+ except OSError:
+ e = sys.exc_info()[1]
return SFTPServer.convert_errno(e.errno)
return SFTP_OK
@@ -167,7 +178,8 @@ class StubSFTPServer (SFTPServerInterface):
path = self._realpath(path)
try:
SFTPServer.set_file_attr(path, attr)
- except OSError, e:
+ except OSError:
+ e = sys.exc_info()[1]
return SFTPServer.convert_errno(e.errno)
return SFTP_OK
@@ -187,7 +199,8 @@ class StubSFTPServer (SFTPServerInterface):
target_path = '<error>'
try:
os.symlink(target_path, path)
- except OSError, e:
+ except OSError:
+ e = sys.exc_info()[1]
return SFTPServer.convert_errno(e.errno)
return SFTP_OK
@@ -195,7 +208,8 @@ class StubSFTPServer (SFTPServerInterface):
path = self._realpath(path)
try:
symlink = os.readlink(path)
- except OSError, e:
+ except OSError:
+ e = sys.exc_info()[1]
return SFTPServer.convert_errno(e.errno)
# if it's absolute, remove the root
if os.path.isabs(symlink):
diff --git a/tests/test_transport.py b/tests/test_transport.py
index ccd3f0c8..d8cd10d5 100644
--- a/tests/test_transport.py
+++ b/tests/test_transport.py
@@ -249,7 +249,7 @@ class TransportTest(ParamikoTest):
try:
chan.exec_command('no')
self.assert_(False)
- except SSHException, x:
+ except SSHException:
pass
chan = self.tc.open_session()
@@ -302,7 +302,8 @@ class TransportTest(ParamikoTest):
try:
chan = self.tc.open_channel('bogus')
self.fail('expected exception')
- except ChannelException, x:
+ except ChannelException:
+ x = sys.exc_info()[1]
self.assert_(x.code == OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED)
def test_9_exit_status(self):
@@ -444,7 +445,8 @@ class TransportTest(ParamikoTest):
schan = self.ts.accept(1.0)
requested = []
- def handler(c, (addr, port)):
+ def handler(c, addr_port):
+ addr, port = addr_port
requested.append((addr, port))
self.tc._queue_incoming_channel(c)
@@ -479,9 +481,9 @@ class TransportTest(ParamikoTest):
schan = self.ts.accept(1.0)
requested = []
- def handler(c, (origin_addr, origin_port), (server_addr, server_port)):
- requested.append((origin_addr, origin_port))
- requested.append((server_addr, server_port))
+ def handler(c, origin_addr_port, server_addr_port):
+ requested.append(origin_addr_port)
+ requested.append(server_addr_port)
self.tc._queue_incoming_channel(c)
port = self.tc.request_port_forward('127.0.0.1', 0, handler)
diff --git a/tests/test_util.py b/tests/test_util.py
index 12575f84..7e656df8 100644
--- a/tests/test_util.py
+++ b/tests/test_util.py
@@ -65,7 +65,7 @@ class UtilTest(ParamikoTest):
"""
verify that all the classes can be imported from paramiko.
"""
- symbols = globals().keys()
+ symbols = list(globals().keys())
self.assertTrue('Transport' in symbols)
self.assertTrue('SSHClient' in symbols)
self.assertTrue('MissingHostKeyPolicy' in symbols)
@@ -148,8 +148,8 @@ class UtilTest(ParamikoTest):
try:
hostdict = paramiko.util.load_host_keys('hostfile.temp')
self.assertEquals(2, len(hostdict))
- self.assertEquals(1, len(hostdict.values()[0]))
- self.assertEquals(1, len(hostdict.values()[1]))
+ self.assertEquals(1, len(list(hostdict.values())[0]))
+ self.assertEquals(1, len(list(hostdict.values())[1]))
fp = hexlify(hostdict['secure.example.com']['ssh-rsa'].get_fingerprint()).upper()
self.assertEquals('E6684DB30E109B67B70FF1DC5C7F1363', fp)
finally: