Skip to content

Commit 4d2035f

Browse files
author
Dan
committed
Updated tests to be python 2.6 compatible
1 parent ecf56fc commit 4d2035f

File tree

2 files changed

+18
-26
lines changed

2 files changed

+18
-26
lines changed

tests/test_pssh_client.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -252,16 +252,19 @@ def test_pssh_client_long_running_command(self):
252252
def test_pssh_client_retries(self):
253253
"""Test connection error retries"""
254254
expected_num_tries = 2
255-
with self.assertRaises(ConnectionErrorException) as cm:
256-
client = ParallelSSHClient(['127.0.0.1'], port=self.listen_port,
257-
pkey=self.user_key,
258-
num_retries=expected_num_tries)
259-
cmd = client.exec_command('blah')[0]
260-
cmd.get()
261-
num_tries = cm.exception.args[-1:][0]
262-
self.assertEqual(expected_num_tries, num_tries,
263-
msg="Got unexpected number of retries %s - expected %s"
264-
% (num_tries, expected_num_tries,))
255+
client = ParallelSSHClient(['127.0.0.1'], port=self.listen_port,
256+
pkey=self.user_key,
257+
num_retries=expected_num_tries)
258+
self.assertRaises(ConnectionErrorException, client.run_command, 'blah')
259+
try:
260+
client.run_command('blah')
261+
except ConnectionErrorException, ex:
262+
num_tries = ex.args[-1:][0]
263+
self.assertEqual(expected_num_tries, num_tries,
264+
msg="Got unexpected number of retries %s - expected %s"
265+
% (num_tries, expected_num_tries,))
266+
else:
267+
raise Exception('No ConnectionErrorException')
265268

266269
def test_pssh_copy_file(self):
267270
"""Test parallel copy file"""

tests/test_ssh_client.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -111,23 +111,12 @@ def test_ssh_client_conn_failure(self):
111111
pkey=self.user_key, num_retries=0)
112112

113113
def test_ssh_client_retries(self):
114-
"""Test connection error retries"""
115-
expected_num_tries = 2
116-
with self.assertRaises(ConnectionErrorException) as cm:
117-
SSHClient('127.0.0.1', port=self.listen_port,
118-
pkey=self.user_key, num_retries=expected_num_tries)
119-
num_tries = cm.exception.args[-1:][0]
120-
self.assertEqual(expected_num_tries, num_tries,
121-
msg="Got unexpected number of retries %s - expected %s"
122-
% (num_tries, expected_num_tries,))
114+
"""Test connection error exceptions"""
115+
self.assertRaises(ConnectionErrorException, SSHClient, '127.0.0.1', port=self.listen_port,
116+
pkey=self.user_key, num_retries=1)
123117
host = ''.join([random.choice(string.ascii_letters) for n in xrange(8)])
124-
with self.assertRaises(UnknownHostException) as cm:
125-
SSHClient(host, port=self.listen_port,
126-
pkey=self.user_key, num_retries=expected_num_tries)
127-
num_tries = cm.exception.args[-1:][0]
128-
self.assertEqual(expected_num_tries, num_tries,
129-
msg="Got unexpected number of retries %s - expected %s"
130-
% (num_tries, expected_num_tries,))
118+
self.assertRaises(UnknownHostException, SSHClient, host, port=self.listen_port,
119+
pkey=self.user_key, num_retries=1)
131120

132121
def test_ssh_client_unknown_host_failure(self):
133122
"""Test connection error failure case - ConnectionErrorException"""

0 commit comments

Comments
 (0)