Skip to content

Commit 0972233

Browse files
committed
run tests through autopep8
1 parent ee119a9 commit 0972233

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+786
-470
lines changed

demos/multiple/multiple.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/usr/bin/env python
2-
from Exscript import Host
3-
from Exscript.util.file import get_hosts_from_file, get_accounts_from_file
2+
from Exscript import Host
3+
from Exscript.util.file import get_hosts_from_file, get_accounts_from_file
44
from Exscript.util.start import start
55

6+
67
def one(job, host, conn):
78
# You can add a safehold based on the guess_os() method.
89
if conn.guess_os() != 'ios':
@@ -17,6 +18,7 @@ def one(job, host, conn):
1718
conn.execute('show ip int brie')
1819
print "myvariable is", conn.get_host().get('myvariable')
1920

21+
2022
def two(job, host, conn):
2123
conn.autoinit()
2224
conn.execute('show interface POS1/0')
@@ -33,4 +35,4 @@ def two(job, host, conn):
3335
# The "max_threads" keyword indicates the maximum number of concurrent
3436
# connections.
3537
hosts = get_hosts_from_file('hostlist.txt')
36-
start(accounts, hosts, two, max_threads = 2)
38+
start(accounts, hosts, two, max_threads=2)

demos/quickstart/quickstart.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env python
2-
from Exscript.util.match import any_match
2+
from Exscript.util.match import any_match
33
from Exscript.util.template import eval_file
4-
from Exscript.util.start import quickstart
4+
from Exscript.util.start import quickstart
5+
56

67
def do_something(job, host, conn):
78
conn.execute('ls -1')

demos/report/report.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from Exscript.util.file import get_hosts_from_file, get_accounts_from_file
66
from Exscript.util.report import status, summarize
77

8-
logger = Logger() # Logs everything to memory.
8+
logger = Logger() # Logs everything to memory.
9+
910

1011
@log_to(logger)
1112
@autologin()

demos/template/template.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/usr/bin/env python
22
from Exscript.util.template import eval_file
3-
from Exscript.util.start import quickstart
3+
from Exscript.util.start import quickstart
4+
45

56
def do_something(job, host, conn):
67
assert conn.guess_os() == 'shell'
78
conn.execute('ls -1')
8-
eval_file(conn, 'template.exscript', foobar = 'hello-world')
9+
eval_file(conn, 'template.exscript', foobar='hello-world')
910

1011
quickstart('ssh://xpc3', do_something)

tests/Exscript/AccountManagerTest.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
import sys, unittest, re, os.path, warnings
1+
import sys
2+
import unittest
3+
import re
4+
import os.path
5+
import warnings
26
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
37

48
from Exscript.Account import Account
59
from Exscript.AccountPool import AccountPool
610
from Exscript.AccountManager import AccountManager
711

12+
813
class AccountManagerTest(unittest.TestCase):
914
CORRELATE = AccountManager
1015

1116
def setUp(self):
12-
self.am = AccountManager()
13-
self.data = {}
17+
self.am = AccountManager()
18+
self.data = {}
1419
self.account = Account('user', 'test')
1520

1621
def testConstructor(self):
@@ -52,7 +57,7 @@ def match_cb(host):
5257

5358
def testGetAccountFromHash(self):
5459
pool1 = AccountPool()
55-
acc1 = Account('user1')
60+
acc1 = Account('user1')
5661
pool1.add_account(acc1)
5762
self.am.add_pool(pool1)
5863

@@ -123,7 +128,8 @@ def testReleaseAccounts(self):
123128
self.assert_(account1 in pool.unlocked_accounts)
124129
self.assert_(account2 in self.am.default_pool.unlocked_accounts)
125130

131+
126132
def suite():
127133
return unittest.TestLoader().loadTestsFromTestCase(AccountManagerTest)
128134
if __name__ == '__main__':
129-
unittest.TextTestRunner(verbosity = 2).run(suite())
135+
unittest.TextTestRunner(verbosity=2).run(suite())

tests/Exscript/AccountPoolTest.py

+15-10
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
import sys, unittest, re, os.path
1+
import sys
2+
import unittest
3+
import re
4+
import os.path
25
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
36

4-
from Exscript import Account
7+
from Exscript import Account
58
from Exscript.AccountPool import AccountPool
6-
from Exscript.util.file import get_accounts_from_file
9+
from Exscript.util.file import get_accounts_from_file
10+
711

812
class AccountPoolTest(unittest.TestCase):
913
CORRELATE = AccountPool
1014

1115
def setUp(self):
12-
self.user1 = 'testuser1'
16+
self.user1 = 'testuser1'
1317
self.password1 = 'test1'
14-
self.account1 = Account(self.user1, self.password1)
15-
self.user2 = 'testuser2'
18+
self.account1 = Account(self.user1, self.password1)
19+
self.user2 = 'testuser2'
1620
self.password2 = 'test2'
17-
self.account2 = Account(self.user2, self.password2)
18-
self.accm = AccountPool()
21+
self.account2 = Account(self.user2, self.password2)
22+
self.accm = AccountPool()
1923

2024
def testConstructor(self):
2125
accm = AccountPool()
@@ -69,7 +73,7 @@ def testAcquireAccount(self):
6973
self.assert_(self.accm.n_accounts() == 5)
7074

7175
for i in range(0, 2000):
72-
# Each time an account is acquired a different one should be
76+
# Each time an account is acquired a different one should be
7377
# returned.
7478
acquired = {}
7579
for n in range(0, 5):
@@ -110,7 +114,8 @@ def testReleaseAccounts(self):
110114
self.assert_(account1 in pool.unlocked_accounts)
111115
self.assert_(account2 in pool.unlocked_accounts)
112116

117+
113118
def suite():
114119
return unittest.TestLoader().loadTestsFromTestCase(AccountPoolTest)
115120
if __name__ == '__main__':
116-
unittest.TextTestRunner(verbosity = 2).run(suite())
121+
unittest.TextTestRunner(verbosity=2).run(suite())

tests/Exscript/AccountTest.py

+15-10
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
1-
import sys, unittest, re, os.path
1+
import sys
2+
import unittest
3+
import re
4+
import os.path
25
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
36

47
from Exscript import Account, PrivateKey
58

9+
610
class AccountTest(unittest.TestCase):
711
CORRELATE = Account
812

913
def setUp(self):
10-
self.user = 'testuser'
14+
self.user = 'testuser'
1115
self.password1 = 'test1'
1216
self.password2 = 'test2'
13-
self.key = PrivateKey()
14-
self.account = Account(self.user,
15-
self.password1,
16-
self.password2,
17-
self.key)
17+
self.key = PrivateKey()
18+
self.account = Account(self.user,
19+
self.password1,
20+
self.password2,
21+
self.key)
1822

1923
def testConstructor(self):
20-
key = PrivateKey()
21-
account = Account(self.user, self.password1, key = key)
24+
key = PrivateKey()
25+
account = Account(self.user, self.password1, key=key)
2226
self.assertEqual(account.get_key(), key)
2327
self.assertEqual(account.get_password(),
2428
account.get_authorization_password())
@@ -84,7 +88,8 @@ def testGetAuthorizationPassword(self):
8488
def testGetKey(self):
8589
self.assertEqual(self.key, self.account.get_key())
8690

91+
8792
def suite():
8893
return unittest.TestLoader().loadTestsFromTestCase(AccountTest)
8994
if __name__ == '__main__':
90-
unittest.TextTestRunner(verbosity = 2).run(suite())
95+
unittest.TextTestRunner(verbosity=2).run(suite())

tests/Exscript/FileLoggerTest.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import sys, unittest, re, os.path
1+
import sys
2+
import unittest
3+
import re
4+
import os.path
25
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
36

47
from tempfile import mkdtemp
@@ -7,17 +10,19 @@
710
from Exscript.FileLogger import FileLogger
811
from LoggerTest import LoggerTest, FakeJob
912

13+
1014
class FakeError(Exception):
1115
pass
1216

17+
1318
class FileLoggerTest(LoggerTest):
1419
CORRELATE = FileLogger
1520

1621
def setUp(self):
1722
self.tempdir = mkdtemp()
18-
self.logdir = os.path.join(self.tempdir, 'non-existent')
19-
self.logger = FileLogger(self.logdir, clearmem = False)
20-
self.job = FakeJob('fake')
23+
self.logdir = os.path.join(self.tempdir, 'non-existent')
24+
self.logger = FileLogger(self.logdir, clearmem=False)
25+
self.job = FakeJob('fake')
2126
self.logfile = os.path.join(self.logdir, 'fake.log')
2227
self.errfile = self.logfile + '.error'
2328

@@ -32,7 +37,8 @@ def testConstructor(self):
3237

3338
def testAddLog(self):
3439
log = LoggerTest.testAddLog(self)
35-
self.assert_(os.path.isfile(self.logfile), 'No such file: ' + self.logfile)
40+
self.assert_(
41+
os.path.isfile(self.logfile), 'No such file: ' + self.logfile)
3642
self.failIf(os.path.exists(self.errfile))
3743
return log
3844

@@ -82,7 +88,8 @@ def testLogSucceeded2(self):
8288
self.assert_(os.path.isfile(self.logfile))
8389
self.failIf(os.path.exists(self.errfile))
8490

91+
8592
def suite():
8693
return unittest.TestLoader().loadTestsFromTestCase(FileLoggerTest)
8794
if __name__ == '__main__':
88-
unittest.TextTestRunner(verbosity = 2).run(suite())
95+
unittest.TextTestRunner(verbosity=2).run(suite())

tests/Exscript/HostTest.py

+21-15
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
1-
import sys, unittest, re, os.path
1+
import sys
2+
import unittest
3+
import re
4+
import os.path
25
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
36

4-
from Exscript import Host, Account
7+
from Exscript import Host, Account
58
from Exscript.util.url import Url
6-
from util.urlTest import urls
9+
from util.urlTest import urls
10+
711

812
class HostTest(unittest.TestCase):
913
CORRELATE = Host
1014

1115
def setUp(self):
1216
self.host = Host('localhost')
13-
self.host.set_all(dict(testarg = 1))
17+
self.host.set_all(dict(testarg=1))
1418

1519
def testConstructor(self):
1620
host = Host('localhost')
1721
self.assertEqual(host.get_protocol(), 'telnet')
18-
host = Host('localhost', default_protocol = 'foo')
22+
host = Host('localhost', default_protocol='foo')
1923
self.assertEqual(host.get_protocol(), 'foo')
2024

2125
for url, result in urls:
2226
host = Host(url)
23-
uri = Url.from_string(url)
27+
uri = Url.from_string(url)
2428
self.assertEqual(host.get_name(), uri.hostname)
2529
self.assertEqual(host.get_address(), uri.hostname)
2630
self.assertEqual(host.get_uri(), str(uri))
@@ -35,7 +39,7 @@ def testSetUri(self):
3539
def testGetUri(self):
3640
for url, result in urls:
3741
host = Host(url)
38-
uri = Url.from_string(url)
42+
uri = Url.from_string(url)
3943
self.assertEqual(host.get_uri(), str(uri))
4044

4145
def testGetDict(self):
@@ -73,30 +77,31 @@ def testSetName(self):
7377
self.assertEqual(self.host.get_name(), 'testhost')
7478

7579
def testGetName(self):
76-
pass # Tested in testSetName().
80+
pass # Tested in testSetName().
7781

7882
def testSetProtocol(self):
7983
self.assertEqual(self.host.get_protocol(), 'telnet')
8084
self.host.set_protocol('dummy')
8185
self.assertEqual(self.host.get_protocol(), 'dummy')
8286

8387
def testGetProtocol(self):
84-
pass # Tested in testSetProtocol().
88+
pass # Tested in testSetProtocol().
8589

8690
def testSetOption(self):
8791
self.assertRaises(TypeError, self.host.set_option, 'test', True)
8892
self.assertEqual(self.host.get_options(), {})
8993
self.assertEqual(self.host.get_option('verify_fingerprint'), None)
90-
self.assertEqual(self.host.get_option('verify_fingerprint', False), False)
94+
self.assertEqual(
95+
self.host.get_option('verify_fingerprint', False), False)
9196
self.host.set_option('verify_fingerprint', True)
9297
self.assertEqual(self.host.get_option('verify_fingerprint'), True)
9398
self.assertEqual(self.host.get_options(), {'verify_fingerprint': True})
9499

95100
def testGetOption(self):
96-
pass # Tested in testSetOption().
101+
pass # Tested in testSetOption().
97102

98103
def testGetOptions(self):
99-
pass # Tested in testSetOption().
104+
pass # Tested in testSetOption().
100105

101106
def testSetTcpPort(self):
102107
self.assertEqual(self.host.get_tcp_port(), 23)
@@ -106,7 +111,7 @@ def testSetTcpPort(self):
106111
self.assertEqual(self.host.get_tcp_port(), 123)
107112

108113
def testGetTcpPort(self):
109-
pass # Tested in testSetTcpPort().
114+
pass # Tested in testSetTcpPort().
110115

111116
def testSetAccount(self):
112117
account = Account('test')
@@ -115,7 +120,7 @@ def testSetAccount(self):
115120
self.assertEqual(self.host.get_account(), account)
116121

117122
def testGetAccount(self):
118-
pass # Tested in testSetAccount().
123+
pass # Tested in testSetAccount().
119124

120125
def testSet(self):
121126
self.assertEqual(self.host.get('test'), None)
@@ -165,7 +170,8 @@ def testGet(self):
165170
self.assertEqual(self.host.get('test', 1), 3)
166171
self.assertEqual(self.host.get('test2', 1), 1)
167172

173+
168174
def suite():
169175
return unittest.TestLoader().loadTestsFromTestCase(HostTest)
170176
if __name__ == '__main__':
171-
unittest.TextTestRunner(verbosity = 2).run(suite())
177+
unittest.TextTestRunner(verbosity=2).run(suite())

tests/Exscript/LogTest.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
import sys, unittest, re, os.path
1+
import sys
2+
import unittest
3+
import re
4+
import os.path
25
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
36

4-
from Exscript.Log import Log
5-
from Exscript import Host
7+
from Exscript.Log import Log
8+
from Exscript import Host
69
from util.reportTest import FakeError
710

11+
812
class LogTest(unittest.TestCase):
913
CORRELATE = Log
1014

@@ -68,7 +72,8 @@ def testHasEnded(self):
6872
self.testSucceeded()
6973
self.assert_(self.log.has_ended())
7074

75+
7176
def suite():
7277
return unittest.TestLoader().loadTestsFromTestCase(LogTest)
7378
if __name__ == '__main__':
74-
unittest.TextTestRunner(verbosity = 2).run(suite())
79+
unittest.TextTestRunner(verbosity=2).run(suite())

0 commit comments

Comments
 (0)