48
48
pssh_logger .setLevel (logging .DEBUG )
49
49
logging .basicConfig ()
50
50
51
+
52
+ try :
53
+ xrange
54
+ except NameError :
55
+ xrange = range
56
+
57
+
51
58
class ParallelSSHClientTest (unittest .TestCase ):
52
59
53
60
def setUp (self ):
@@ -280,7 +287,7 @@ def test_pssh_client_retries(self):
280
287
self .assertRaises (ConnectionErrorException , client .run_command , 'blah' )
281
288
try :
282
289
client .run_command ('blah' )
283
- except ConnectionErrorException , ex :
290
+ except ConnectionErrorException as ex :
284
291
num_tries = ex .args [- 1 :][0 ]
285
292
self .assertEqual (expected_num_tries , num_tries ,
286
293
msg = "Got unexpected number of retries %s - "
@@ -377,7 +384,7 @@ def test_pssh_client_copy_file_failure(self):
377
384
test_file .write ('testing\n ' )
378
385
test_file .close ()
379
386
# Permission errors on writing into dir
380
- mask = 0111 if sys .version_info <= (2 ,) else 0o111
387
+ mask = int ( ' 0111' ) if sys .version_info <= (2 ,) else 0o111
381
388
os .chmod (remote_test_path , mask )
382
389
client = ParallelSSHClient ([self .host ], port = self .listen_port ,
383
390
pkey = self .user_key )
@@ -692,7 +699,7 @@ def test_connection_error_exception(self):
692
699
host ,))
693
700
try :
694
701
raise output [host ]['exception' ]
695
- except ConnectionErrorException , ex :
702
+ except ConnectionErrorException as ex :
696
703
self .assertEqual (ex .args [1 ], host ,
697
704
msg = "Exception host argument is %s, should be %s" % (
698
705
ex .args [1 ], host ,))
@@ -717,7 +724,7 @@ def test_authentication_exception(self):
717
724
self .host ,))
718
725
try :
719
726
raise output [self .host ]['exception' ]
720
- except AuthenticationException , ex :
727
+ except AuthenticationException as ex :
721
728
self .assertEqual (ex .args [1 ], self .host ,
722
729
msg = "Exception host argument is %s, should be %s" % (
723
730
ex .args [1 ], self .host ,))
@@ -744,7 +751,7 @@ def test_ssh_exception(self):
744
751
host ,))
745
752
try :
746
753
raise output [host ]['exception' ]
747
- except SSHException , ex :
754
+ except SSHException as ex :
748
755
self .assertEqual (ex .args [1 ], host ,
749
756
msg = "Exception host argument is %s, should be %s" % (
750
757
ex .args [1 ], host ,))
@@ -824,7 +831,7 @@ def test_host_config(self):
824
831
self .assertTrue (host in output )
825
832
try :
826
833
raise output [hosts [1 ]]['exception' ]
827
- except AuthenticationException , ex :
834
+ except AuthenticationException as ex :
828
835
pass
829
836
else :
830
837
raise AssertionError ("Expected AutnenticationException on host %s" ,
@@ -952,11 +959,15 @@ def test_ssh_client_utf_encoding(self):
952
959
client = ParallelSSHClient ([self .host ], port = server_port ,
953
960
pkey = self .user_key )
954
961
# File is already set to utf-8, cannot use utf-16 only representations
955
- # Using ascii characters encoded as utf-16 instead
962
+ # Using ascii characters decoded as utf-16 on py2
963
+ # and utf-8 encoded ascii decoded to utf-16 on py3
956
964
output = client .run_command (self .fake_cmd , encoding = 'utf-16' )
957
965
stdout = list (output [self .host ]['stdout' ])
958
- # import ipdb; ipdb.set_trace()
959
- self .assertEqual ([self .fake_resp .decode ('utf-16' )], stdout )
966
+ if type (self .fake_resp ) == bytes :
967
+ self .assertEqual ([self .fake_resp .decode ('utf-16' )], stdout )
968
+ else :
969
+ self .assertEqual ([self .fake_resp .encode ('utf-8' ).decode ('utf-16' )],
970
+ stdout )
960
971
961
972
def test_pty (self ):
962
973
cmd = "exit 0"
0 commit comments