@@ -43,7 +43,6 @@ def setUpClass(cls):
4343 )
4444 modify_pg_hba (cls .node )
4545
46- cls .backup_dir = os .path .join (tempfile .tempdir , "backups" )
4746 cls .pb .init_pb (cls .backup_dir )
4847 cls .pb .add_instance (cls .backup_dir , cls .node .name , cls .node )
4948 cls .pb .set_archiving (cls .backup_dir , cls .node .name , cls .node )
@@ -86,7 +85,7 @@ def setUp(self):
8685 self .pgpass_file = os .path .join (os .path .expanduser ('~' ), '.pgpass' )
8786 try :
8887 os .remove (self .pgpass_file )
89- except FileNotFoundError :
88+ except OSError :
9089 pass
9190
9291 def tearDown (self ):
@@ -96,9 +95,7 @@ def test_empty_password(self):
9695 """ Test case: PGPB_AUTH03 - zero password length """
9796 try :
9897 self .assertIn ("ERROR: no password supplied" ,
99- "" .join (map (lambda x : x .decode ("utf-8" ),
100- run_pb_with_auth ([self .pb .probackup_path ] + self .cmd , '\0 \r \n ' ))
101- )
98+ str (run_pb_with_auth ([self .pb .probackup_path ] + self .cmd , '\0 \r \n ' ))
10299 )
103100 except (TIMEOUT , ExceptionPexpect ) as e :
104101 self .fail (e .value )
@@ -107,9 +104,7 @@ def test_wrong_password(self):
107104 """ Test case: PGPB_AUTH04 - incorrect password """
108105 try :
109106 self .assertIn ("password authentication failed" ,
110- "" .join (map (lambda x : x .decode ("utf-8" ),
111- run_pb_with_auth ([self .pb .probackup_path ] + self .cmd , 'wrong_password\r \n ' ))
112- )
107+ str (run_pb_with_auth ([self .pb .probackup_path ] + self .cmd , 'wrong_password\r \n ' ))
113108 )
114109 except (TIMEOUT , ExceptionPexpect ) as e :
115110 self .fail (e .value )
@@ -118,9 +113,7 @@ def test_right_password(self):
118113 """ Test case: PGPB_AUTH01 - correct password """
119114 try :
120115 self .assertIn ("completed" ,
121- "" .join (map (lambda x : x .decode ("utf-8" ),
122- run_pb_with_auth ([self .pb .probackup_path ] + self .cmd , 'password\r \n ' ))
123- )
116+ str (run_pb_with_auth ([self .pb .probackup_path ] + self .cmd , 'password\r \n ' ))
124117 )
125118 except (TIMEOUT , ExceptionPexpect ) as e :
126119 self .fail (e .value )
@@ -161,7 +154,7 @@ def test_pgpass(self):
161154 def test_pgpassword (self ):
162155 line = ":" .join (['127.0.0.1' , str (self .node .port ), 'postgres' , 'backup' , 'wrong_password' ])
163156 create_pgpass (self .pgpass_file , line )
164- os .environ ["PGPASSWORD" ] = ' password'
157+ os .environ ["PGPASSWORD" ] = " password"
165158 try :
166159 self .assertEqual (
167160 "OK" ,
@@ -174,15 +167,16 @@ def test_pgpassword(self):
174167
175168def run_pb_with_auth (cmd , password = None , kill = False ):
176169 try :
177- with spawn (" " .join (cmd ), timeout = 10 ) as probackup :
170+ with spawn (" " .join (cmd ), encoding = 'utf-8' , timeout = 10 ) as probackup :
178171 result = probackup .expect ("Password for user .*:" , 5 )
179172 if kill :
180173 probackup .kill (signal .SIGINT )
181174 elif result == 0 :
182175 probackup .sendline (password )
183- return probackup .readlines ()
176+ probackup .expect (EOF )
177+ return probackup .before
184178 else :
185- raise TIMEOUT ( " " )
179+ raise ExceptionPexpect ( "Other pexpect errors. " )
186180 except TIMEOUT :
187181 raise TIMEOUT ("Timeout error." )
188182 except ExceptionPexpect :
0 commit comments