88
99module_name = 'init'
1010
11- DIR_PERMISSION = 0o700
11+ DIR_PERMISSION = 0o700 if os . name != 'nt' else 0o777
1212
1313CATALOG_DIRS = ['backups' , 'wal' ]
1414
@@ -175,13 +175,12 @@ def test_init_backup_catalog_no_access(self):
175175 os .makedirs (no_access_dir )
176176 os .chmod (no_access_dir , stat .S_IREAD )
177177
178- try :
178+ expected = 'ERROR: cannot open backup catalog directory "{0}": Permission denied' .format (backup_dir )
179+ with self .assertRaisesRegex (ProbackupException , expected ):
179180 self .init_pb (backup_dir , cleanup = False )
180- except ProbackupException as e :
181- self .assertEqual (f'ERROR: cannot open backup catalog directory "{ backup_dir } ": Permission denied\n ' ,
182- e .message )
183- finally :
184- self .del_test_dir (module_name , fname )
181+
182+ # Clean after yourself
183+ self .del_test_dir (module_name , fname )
185184
186185 def test_init_backup_catalog_no_write (self ):
187186 """ Test pg_probackup init -B backup_dir to a dir with no write access. """
@@ -193,13 +192,12 @@ def test_init_backup_catalog_no_write(self):
193192 os .makedirs (no_access_dir )
194193 os .chmod (no_access_dir , stat .S_IREAD | stat .S_IEXEC )
195194
196- try :
195+ expected = 'ERROR: Can not create backup catalog root directory: Cannot make dir "{0}": Permission denied' .format (backup_dir )
196+ with self .assertRaisesRegex (ProbackupException , expected ):
197197 self .init_pb (backup_dir , cleanup = False )
198- except ProbackupException as e :
199- self .assertEqual (f'ERROR: Can not create backup catalog root directory: Cannot make dir "{ backup_dir } ": Permission denied\n ' ,
200- e .message )
201- finally :
202- self .del_test_dir (module_name , fname )
198+
199+ # Clean after yourself
200+ self .del_test_dir (module_name , fname )
203201
204202 def test_init_backup_catalog_no_create (self ):
205203 """ Test pg_probackup init -B backup_dir to a dir when backup dir exists but not writeable. """
@@ -211,14 +209,13 @@ def test_init_backup_catalog_no_create(self):
211209 os .makedirs (backup_dir )
212210 os .chmod (backup_dir , stat .S_IREAD | stat .S_IEXEC )
213211
214- try :
212+ backups_dir = os .path .join (backup_dir , 'backups' )
213+ expected = 'ERROR: Can not create backup catalog data directory: Cannot make dir "{0}": Permission denied' .format (backups_dir )
214+ with self .assertRaisesRegex (ProbackupException , expected ):
215215 self .init_pb (backup_dir , cleanup = False )
216- except ProbackupException as e :
217- backups_dir = os .path .join (backup_dir , 'backups' )
218- self .assertEqual (f'ERROR: Can not create backup catalog data directory: Cannot make dir "{ backups_dir } ": Permission denied\n ' ,
219- e .message )
220- finally :
221- self .del_test_dir (module_name , fname )
216+
217+ # Clean after yourself
218+ self .del_test_dir (module_name , fname )
222219
223220 def test_init_backup_catalog_exists_not_empty (self ):
224221 """ Test pg_probackup init -B backup_dir which exists and not empty. """
@@ -228,14 +225,11 @@ def test_init_backup_catalog_exists_not_empty(self):
228225 'parent' )
229226 backup_dir = os .path .join (parent_dir , 'backup' )
230227 os .makedirs (backup_dir )
231- with open (os .path .join (backup_dir , 'somefile.txt' ), 'w' ) as fout :
232- fout . write ( "42 \n " )
228+ with open (os .path .join (backup_dir , 'somefile.txt' ), 'wb' ) :
229+ pass
233230
234- try :
231+ with self . assertRaisesRegex ( ProbackupException , "ERROR: backup catalog already exist and it's not empty" ) :
235232 self .init_pb (backup_dir , cleanup = False )
236- self .fail ("This should have failed due to non empty catalog dir." )
237- except ProbackupException as e :
238- self .assertEqual ("ERROR: backup catalog already exist and it's not empty\n " ,
239- e .message )
240- finally :
241- self .del_test_dir (module_name , fname )
233+
234+ # Clean after yourself
235+ self .del_test_dir (module_name , fname )
0 commit comments