4848pssh_logger .setLevel (logging .DEBUG )
4949logging .basicConfig ()
5050
51+
52+ try :
53+ xrange
54+ except NameError :
55+ xrange = range
56+
57+
5158class ParallelSSHClientTest (unittest .TestCase ):
5259
5360 def setUp (self ):
@@ -280,7 +287,7 @@ def test_pssh_client_retries(self):
280287 self .assertRaises (ConnectionErrorException , client .run_command , 'blah' )
281288 try :
282289 client .run_command ('blah' )
283- except ConnectionErrorException , ex :
290+ except ConnectionErrorException as ex :
284291 num_tries = ex .args [- 1 :][0 ]
285292 self .assertEqual (expected_num_tries , num_tries ,
286293 msg = "Got unexpected number of retries %s - "
@@ -377,7 +384,7 @@ def test_pssh_client_copy_file_failure(self):
377384 test_file .write ('testing\n ' )
378385 test_file .close ()
379386 # 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
381388 os .chmod (remote_test_path , mask )
382389 client = ParallelSSHClient ([self .host ], port = self .listen_port ,
383390 pkey = self .user_key )
@@ -692,7 +699,7 @@ def test_connection_error_exception(self):
692699 host ,))
693700 try :
694701 raise output [host ]['exception' ]
695- except ConnectionErrorException , ex :
702+ except ConnectionErrorException as ex :
696703 self .assertEqual (ex .args [1 ], host ,
697704 msg = "Exception host argument is %s, should be %s" % (
698705 ex .args [1 ], host ,))
@@ -717,7 +724,7 @@ def test_authentication_exception(self):
717724 self .host ,))
718725 try :
719726 raise output [self .host ]['exception' ]
720- except AuthenticationException , ex :
727+ except AuthenticationException as ex :
721728 self .assertEqual (ex .args [1 ], self .host ,
722729 msg = "Exception host argument is %s, should be %s" % (
723730 ex .args [1 ], self .host ,))
@@ -744,7 +751,7 @@ def test_ssh_exception(self):
744751 host ,))
745752 try :
746753 raise output [host ]['exception' ]
747- except SSHException , ex :
754+ except SSHException as ex :
748755 self .assertEqual (ex .args [1 ], host ,
749756 msg = "Exception host argument is %s, should be %s" % (
750757 ex .args [1 ], host ,))
@@ -824,7 +831,7 @@ def test_host_config(self):
824831 self .assertTrue (host in output )
825832 try :
826833 raise output [hosts [1 ]]['exception' ]
827- except AuthenticationException , ex :
834+ except AuthenticationException as ex :
828835 pass
829836 else :
830837 raise AssertionError ("Expected AutnenticationException on host %s" ,
@@ -952,11 +959,15 @@ def test_ssh_client_utf_encoding(self):
952959 client = ParallelSSHClient ([self .host ], port = server_port ,
953960 pkey = self .user_key )
954961 # 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
956964 output = client .run_command (self .fake_cmd , encoding = 'utf-16' )
957965 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 )
960971
961972 def test_pty (self ):
962973 cmd = "exit 0"
0 commit comments