8
8
9
9
module_name = 'init'
10
10
11
- DIR_PERMISSION = 0o700
11
+ DIR_PERMISSION = 0o700 if os . name != 'nt' else 0o777
12
12
13
13
CATALOG_DIRS = ['backups' , 'wal' ]
14
14
@@ -175,13 +175,12 @@ def test_init_backup_catalog_no_access(self):
175
175
os .makedirs (no_access_dir )
176
176
os .chmod (no_access_dir , stat .S_IREAD )
177
177
178
- try :
178
+ expected = 'ERROR: cannot open backup catalog directory "{0}": Permission denied' .format (backup_dir )
179
+ with self .assertRaisesRegex (ProbackupException , expected ):
179
180
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 )
185
184
186
185
def test_init_backup_catalog_no_write (self ):
187
186
""" 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):
193
192
os .makedirs (no_access_dir )
194
193
os .chmod (no_access_dir , stat .S_IREAD | stat .S_IEXEC )
195
194
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 ):
197
197
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 )
203
201
204
202
def test_init_backup_catalog_no_create (self ):
205
203
""" 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):
211
209
os .makedirs (backup_dir )
212
210
os .chmod (backup_dir , stat .S_IREAD | stat .S_IEXEC )
213
211
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 ):
215
215
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 )
222
219
223
220
def test_init_backup_catalog_exists_not_empty (self ):
224
221
""" 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):
228
225
'parent' )
229
226
backup_dir = os .path .join (parent_dir , 'backup' )
230
227
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
233
230
234
- try :
231
+ with self . assertRaisesRegex ( ProbackupException , "ERROR: backup catalog already exist and it's not empty" ) :
235
232
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