diff options
author | Scott Maxwell <scott@codecobblers.com> | 2014-03-07 20:45:26 -0800 |
---|---|---|
committer | Scott Maxwell <scott@codecobblers.com> | 2014-03-07 20:45:26 -0800 |
commit | f0017b83309899bf6fffc0fa90093c36f1a7f7ea (patch) | |
tree | 582d35dee4b32f022bddc2245731a76112f7ac8e /tests | |
parent | 073c71a8223ff77cacd8c555ef63ce24f0c3d50c (diff) |
Fix import * and a bunch of PEP8 formatting
Diffstat (limited to 'tests')
-rw-r--r-- | tests/stub_sftp.py | 5 | ||||
-rw-r--r-- | tests/test_auth.py | 3 | ||||
-rw-r--r-- | tests/test_buffered_pipe.py | 15 | ||||
-rw-r--r-- | tests/test_client.py | 2 | ||||
-rw-r--r-- | tests/test_hostkeys.py | 3 | ||||
-rw-r--r-- | tests/test_kex.py | 10 | ||||
-rw-r--r-- | tests/test_packetizer.py | 6 | ||||
-rw-r--r-- | tests/test_pkey.py | 3 | ||||
-rwxr-xr-x | tests/test_sftp.py | 5 | ||||
-rw-r--r-- | tests/test_sftp_big.py | 5 | ||||
-rw-r--r-- | tests/test_transport.py | 9 | ||||
-rw-r--r-- | tests/test_util.py | 5 |
12 files changed, 36 insertions, 35 deletions
diff --git a/tests/stub_sftp.py b/tests/stub_sftp.py index 4fbcead8..47644433 100644 --- a/tests/stub_sftp.py +++ b/tests/stub_sftp.py @@ -21,7 +21,6 @@ A stub SFTP server for loopback SFTP testing. """ import os -import sys from paramiko import ServerInterface, SFTPServerInterface, SFTPServer, SFTPAttributes, \ SFTPHandle, SFTP_OK, AUTH_SUCCESSFUL, OPEN_SUCCEEDED from paramiko.common import o666 @@ -64,7 +63,7 @@ class StubSFTPServer (SFTPServerInterface): def list_folder(self, path): path = self._realpath(path) try: - out = [ ] + out = [] flist = os.listdir(path) for fname in flist: attr = SFTPAttributes.from_stat(os.stat(os.path.join(path, fname))) @@ -91,7 +90,7 @@ class StubSFTPServer (SFTPServerInterface): def open(self, path, flags, attr): path = self._realpath(path) try: - binary_flag = getattr(os, 'O_BINARY', 0) + binary_flag = getattr(os, 'O_BINARY', 0) flags |= binary_flag mode = getattr(attr, 'st_mode', None) if mode is not None: diff --git a/tests/test_auth.py b/tests/test_auth.py index d26b1807..1d972d53 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -25,10 +25,9 @@ import threading import unittest from paramiko import Transport, ServerInterface, RSAKey, DSSKey, \ - SSHException, BadAuthenticationType, InteractiveQuery, ChannelException, \ + BadAuthenticationType, InteractiveQuery, \ AuthenticationException from paramiko import AUTH_FAILED, AUTH_PARTIALLY_SUCCESSFUL, AUTH_SUCCESSFUL -from paramiko import OPEN_SUCCEEDED, OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED from paramiko.py3compat import u from tests.loop import LoopSocket from tests.util import test_path diff --git a/tests/test_buffered_pipe.py b/tests/test_buffered_pipe.py index b9d2bef4..a53081a9 100644 --- a/tests/test_buffered_pipe.py +++ b/tests/test_buffered_pipe.py @@ -22,24 +22,22 @@ Some unit tests for BufferedPipe. import threading import time -import unittest from paramiko.buffered_pipe import BufferedPipe, PipeTimeout from paramiko import pipe -from paramiko.py3compat import b from tests.util import ParamikoTest -def delay_thread(pipe): - pipe.feed('a') +def delay_thread(p): + p.feed('a') time.sleep(0.5) - pipe.feed('b') - pipe.close() + p.feed('b') + p.close() -def close_thread(pipe): +def close_thread(p): time.sleep(0.2) - pipe.close() + p.close() class BufferedPipeTest(ParamikoTest): @@ -91,4 +89,3 @@ class BufferedPipeTest(ParamikoTest): self.assertTrue(p._set) p2.clear() self.assertFalse(p._set) - diff --git a/tests/test_client.py b/tests/test_client.py index af292c32..7e5c80b4 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -158,7 +158,7 @@ class SSHClientTest (unittest.TestCase): self.tc = paramiko.SSHClient() self.tc.get_host_keys().add('[%s]:%d' % (self.addr, self.port), 'ssh-rsa', public_host_key) - self.tc.connect(self.addr, self.port, username='slowdive', key_filename=[ test_path('test_rsa.key'), test_path('test_dss.key') ]) + self.tc.connect(self.addr, self.port, username='slowdive', key_filename=[test_path('test_rsa.key'), test_path('test_dss.key')]) self.event.wait(1.0) self.assertTrue(self.event.isSet()) diff --git a/tests/test_hostkeys.py b/tests/test_hostkeys.py index 9a7e3689..0ee1bbf0 100644 --- a/tests/test_hostkeys.py +++ b/tests/test_hostkeys.py @@ -20,12 +20,11 @@ Some unit tests for HostKeys. """ -import base64 from binascii import hexlify import os import unittest import paramiko -from paramiko.py3compat import b, decodebytes +from paramiko.py3compat import decodebytes test_hosts_file = """\ diff --git a/tests/test_kex.py b/tests/test_kex.py index 4286d6e8..c522be46 100644 --- a/tests/test_kex.py +++ b/tests/test_kex.py @@ -37,8 +37,10 @@ class FakeRng (object): class FakeKey (object): def __str__(self): return 'fake-key' + def asbytes(self): return b'fake-key' + def sign_ssh_data(self, rng, H): return b'fake-sig' @@ -46,6 +48,7 @@ class FakeKey (object): class FakeModulusPack (object): P = 0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF G = 2 + def get_modulus(self, min, ask, max): return self.G, self.P @@ -59,19 +62,26 @@ class FakeTransport (object): def _send_message(self, m): self._message = m + def _expect_packet(self, *t): self._expect = t + def _set_K_H(self, K, H): self._K = K self._H = H + def _verify_key(self, host_key, sig): self._verify = (host_key, sig) + def _activate_outbound(self): self._activated = True + def _log(self, level, s): pass + def get_server_key(self): return FakeKey() + def _get_modulus_pack(self): return FakeModulusPack() diff --git a/tests/test_packetizer.py b/tests/test_packetizer.py index 09d7fcc3..d4d5544e 100644 --- a/tests/test_packetizer.py +++ b/tests/test_packetizer.py @@ -23,7 +23,7 @@ Some unit tests for the ssh2 protocol in Transport. import unittest from tests.loop import LoopSocket from Crypto.Cipher import AES -from Crypto.Hash import SHA, HMAC +from Crypto.Hash import SHA from paramiko import Message, Packetizer, util from paramiko.common import byte_chr, zero_byte @@ -33,7 +33,7 @@ x1f = byte_chr(0x1f) class PacketizerTest (unittest.TestCase): - def test_1_write (self): + def test_1_write(self): rsock = LoopSocket() wsock = LoopSocket() rsock.link(wsock) @@ -56,7 +56,7 @@ class PacketizerTest (unittest.TestCase): self.assertEqual(44, len(data)) self.assertEqual(b'\x43\x91\x97\xbd\x5b\x50\xac\x25\x87\xc2\xc4\x6b\xc7\xe9\x38\xc0', data[:16]) - def test_2_read (self): + def test_2_read(self): rsock = LoopSocket() wsock = LoopSocket() rsock.link(wsock) diff --git a/tests/test_pkey.py b/tests/test_pkey.py index 2e565a5f..6ff68fc2 100644 --- a/tests/test_pkey.py +++ b/tests/test_pkey.py @@ -23,7 +23,8 @@ Some unit tests for public/private key objects. from binascii import hexlify import unittest from paramiko import RSAKey, DSSKey, ECDSAKey, Message, util -from paramiko.common import rng, StringIO, byte_chr, b, bytes +from paramiko.py3compat import StringIO, byte_chr, b, bytes +from paramiko.common import rng from tests.util import test_path # from openssh's ssh-keygen diff --git a/tests/test_sftp.py b/tests/test_sftp.py index 82422019..6417ac90 100755 --- a/tests/test_sftp.py +++ b/tests/test_sftp.py @@ -32,7 +32,8 @@ import unittest from tempfile import mkstemp import paramiko -from paramiko.common import PY2, b, u, StringIO, o777, o600 +from paramiko.py3compat import PY2, b, u, StringIO +from paramiko.common import o777, o600, o666, o644 from tests.stub_sftp import StubServer, StubSFTPServer from tests.loop import LoopSocket from tests.util import test_path @@ -554,6 +555,7 @@ class SFTPTest (unittest.TestCase): with open(localname, 'wb') as f: f.write(text) saved_progress = [] + def progress_callback(x, y): saved_progress.append((x, y)) sftp.put(localname, FOLDER + '/bunny.txt', progress_callback) @@ -663,6 +665,7 @@ class SFTPTest (unittest.TestCase): with open(localname, 'w') as f: f.write(text) saved_progress = [] + def progress_callback(x, y): saved_progress.append((x, y)) res = sftp.put(localname, FOLDER + '/bunny.txt', progress_callback, False) diff --git a/tests/test_sftp_big.py b/tests/test_sftp_big.py index b1b13d58..521fbdc8 100644 --- a/tests/test_sftp_big.py +++ b/tests/test_sftp_big.py @@ -23,19 +23,14 @@ a real actual sftp server is contacted, and a new folder is created there to do test file operations in (so no existing files will be harmed). """ -import logging import os import random import struct import sys -import threading import time import unittest -import paramiko from paramiko.common import o660 -from tests.stub_sftp import StubServer, StubSFTPServer -from tests.loop import LoopSocket from tests.test_sftp import get_sftp FOLDER = os.environ.get('TEST_FOLDER', 'temp-testing000') diff --git a/tests/test_transport.py b/tests/test_transport.py index 876759c8..485a18e8 100644 --- a/tests/test_transport.py +++ b/tests/test_transport.py @@ -23,17 +23,16 @@ Some unit tests for the ssh2 protocol in Transport. from binascii import hexlify import select import socket -import sys import time import threading -import unittest import random from paramiko import Transport, SecurityOptions, ServerInterface, RSAKey, DSSKey, \ - SSHException, BadAuthenticationType, InteractiveQuery, ChannelException -from paramiko import AUTH_FAILED, AUTH_PARTIALLY_SUCCESSFUL, AUTH_SUCCESSFUL + SSHException, ChannelException +from paramiko import AUTH_FAILED, AUTH_SUCCESSFUL from paramiko import OPEN_SUCCEEDED, OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED -from paramiko.common import MSG_KEXINIT, MSG_CHANNEL_WINDOW_ADJUST, b, bytes +from paramiko.common import MSG_KEXINIT, cMSG_CHANNEL_WINDOW_ADJUST +from paramiko.py3compat import bytes from paramiko.message import Message from tests.loop import LoopSocket from tests.util import ParamikoTest, test_path diff --git a/tests/test_util.py b/tests/test_util.py index 4f85c391..6bde4045 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -23,11 +23,10 @@ Some unit tests for utility functions. from binascii import hexlify import errno import os -import unittest from Crypto.Hash import SHA import paramiko.util from paramiko.util import lookup_ssh_host_config as host_config -from paramiko.py3compat import StringIO, byte_ord, b +from paramiko.py3compat import StringIO, byte_ord from tests.util import ParamikoTest @@ -338,4 +337,4 @@ AddressFamily inet IdentityFile something_%l_using_fqdn """ config = paramiko.util.parse_ssh_config(StringIO(test_config)) - assert config.lookup('meh') # will die during lookup() if bug regresses + assert config.lookup('meh') # will die during lookup() if bug regresses |