Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1c90723

Browse files
committed
fix rm files on cleanup()
1 parentbd428b0 commit1c90723

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

‎testgres/testgres.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,11 @@ def __init__(self,
292292
ifnotnode.status():
293293
raiseBackupException('Node must be running')
294294

295-
#set default arguments
295+
#Set default arguments
296296
username=usernameordefault_username()
297297
base_dir=base_dirortempfile.mkdtemp()
298298

299-
#create directory if needed
299+
#Create directory if needed
300300
ifbase_dirandnotos.path.exists(base_dir):
301301
os.makedirs(base_dir)
302302

@@ -350,7 +350,7 @@ def _prepare_dir(self, destroy):
350350
else:
351351
base_dir=self.base_dir
352352

353-
#update value
353+
#Update value
354354
self.available=available
355355

356356
returnbase_dir
@@ -370,12 +370,15 @@ def spawn_primary(self, name, destroy=True, use_logging=False):
370370

371371
base_dir=self._prepare_dir(destroy)
372372

373-
#build a new PostgresNode
373+
#Build a new PostgresNode
374374
node=PostgresNode(name=name,
375375
base_dir=base_dir,
376376
master=self.original_node,
377377
use_logging=use_logging)
378378

379+
# New nodes should always remove dir tree
380+
node.should_rm_dirs=True
381+
379382
node.append_conf("postgresql.conf","\n")
380383
node.append_conf("postgresql.conf","port = {}".format(node.port))
381384

@@ -1149,13 +1152,14 @@ def _execute_utility(util, args, logfile, write_to_pipe=True):
11491152
util: utility to be executed (str).
11501153
args: arguments for utility (list).
11511154
logfile: stores stdout and stderr (str).
1155+
write_to_pipe: do we care about stdout?
11521156
11531157
Returns:
11541158
stdout of executed utility.
11551159
"""
11561160

1157-
withopen(logfile,"a")asfile_out, \
1158-
open(os.devnull,"w")asdevnull:# hack for 2.7
1161+
# we can't use subprocess.DEVNULL on 2.7
1162+
withopen(os.devnull,"w")asdevnull:
11591163

11601164
# choose file according to options
11611165
stdout_file=subprocess.PIPEifwrite_to_pipeelsedevnull
@@ -1169,10 +1173,16 @@ def _execute_utility(util, args, logfile, write_to_pipe=True):
11691173
out,_=process.communicate()
11701174
out=''ifnotoutelseout.decode('utf-8')
11711175

1172-
# write new log entry
1173-
file_out.write(''.join(map(lambdax:str(x)+' ', [util]+args)))
1174-
file_out.write('\n')
1175-
file_out.write(out)
1176+
# write new log entry if possible
1177+
try:
1178+
withopen(logfile,"a")asfile_out:
1179+
# write util name + args
1180+
file_out.write(''.join(map(lambdax:str(x)+' ',
1181+
[util]+args)))
1182+
file_out.write('\n')
1183+
file_out.write(out)
1184+
exceptFileNotFoundError:
1185+
pass
11761186

11771187
ifprocess.returncode:
11781188
error_text= (

‎tests/test_simple.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
#!/usr/bin/env python
22

3-
importunittest
3+
importos
44
importre
55
importsix
6-
importtempfile
7-
importlogging.config
86
importsubprocess
7+
importtempfile
98
importtestgres
9+
importunittest
10+
11+
importlogging.config
1012

1113
fromdistutils.versionimportLooseVersion
1214

13-
fromtestgresimportInitNodeException, \
14-
StartNodeException,ExecUtilException, \
15-
BackupException,QueryException,CatchUpException
15+
fromtestgresimport \
16+
InitNodeException, \
17+
StartNodeException, \
18+
ExecUtilException, \
19+
BackupException, \
20+
QueryException, \
21+
CatchUpException
1622

1723
fromtestgresimportget_new_node,get_pg_config,configure_testgres
1824
fromtestgresimportbound_ports
@@ -266,6 +272,7 @@ def test_dump(self):
266272

267273
# take a new dump
268274
dump=node1.dump('postgres')
275+
self.assertTrue(os.path.isfile(dump))
269276

270277
withget_new_node('node2')asnode2:
271278
node2.init().start().restore('postgres',dump)
@@ -274,6 +281,9 @@ def test_dump(self):
274281
'select * from test order by val asc')
275282
self.assertListEqual(res, [(1, ), (2, )])
276283

284+
# finally, remove dump
285+
os.remove(dump)
286+
277287
deftest_users(self):
278288
withget_new_node('master')asnode:
279289
node.init().start()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp