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

Commit7c4e14f

Browse files
committed
Add method for deeper configuration of testgres
1 parent30af983 commit7c4e14f

File tree

3 files changed

+53
-18
lines changed

3 files changed

+53
-18
lines changed

‎.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ tags
55
Dockerfile
66
.coverage
77
env
8+
/build
9+
coverage.xml

‎testgres/testgres.py

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@
7575
DEFAULT_XLOG_METHOD="fetch"
7676

7777

78+
classTestgresConfig:
79+
cache_pg_config=True
80+
cache_initdb=True
81+
82+
7883
classTestgresException(Exception):
7984
"""
8085
Base exception
@@ -1081,7 +1086,7 @@ def call_initdb(_data_dir):
10811086
raiseInitNodeException(str(e))
10821087

10831088
# Call initdb if we have custom params
1084-
ifinitdb_params:
1089+
ifinitdb_paramsornotTestgresConfig.cache_initdb:
10851090
call_initdb(data_dir)
10861091
# Else we can use cached dir
10871092
else:
@@ -1190,25 +1195,31 @@ def get_pg_config():
11901195

11911196
globalpg_config_data
11921197

1193-
ifnotpg_config_data:
1194-
pg_config_cmd=os.environ.get("PG_CONFIG")or"pg_config"
1198+
ifTestgresConfig.cache_pg_configandpg_config_data:
1199+
returnpg_config_data
1200+
1201+
data= {}
1202+
pg_config_cmd=os.environ.get("PG_CONFIG")or"pg_config"
1203+
out=six.StringIO(subprocess.check_output([pg_config_cmd],
1204+
universal_newlines=True))
1205+
forlineinout:
1206+
iflineand"="inline:
1207+
key,value=line.split("=",1)
1208+
data[key.strip()]=value.strip()
11951209

1196-
out=six.StringIO(subprocess.check_output([pg_config_cmd],
1197-
universal_newlines=True))
1198-
forlineinout:
1199-
iflineand"="inline:
1200-
key,value=line.split("=",1)
1201-
pg_config_data[key.strip()]=value.strip()
1210+
# Fetch version of PostgreSQL and save it as VERSION_NUM
1211+
version=data["VERSION"]
1212+
version=version.split(" ")[-1] \
1213+
.partition('devel')[0] \
1214+
.partition('beta')[0] \
1215+
.partition('rc')[0]
1216+
data["VERSION_NUM"]=version
12021217

1203-
# Fetch version of PostgreSQL and save it as VERSION_NUM
1204-
version=pg_config_data["VERSION"]
1205-
version=version.split(" ")[-1] \
1206-
.partition('devel')[0] \
1207-
.partition('beta')[0] \
1208-
.partition('rc')[0]
1209-
pg_config_data["VERSION_NUM"]=version
1218+
ifTestgresConfig.cache_pg_config:
1219+
pg_config_data.clear()
1220+
pg_config_data.update(data)
12101221

1211-
returnpg_config_data
1222+
returndata
12121223

12131224

12141225
defget_new_node(name,base_dir=None,use_logging=False):
@@ -1225,3 +1236,11 @@ def get_new_node(name, base_dir=None, use_logging=False):
12251236
"""
12261237

12271238
returnPostgresNode(name=name,base_dir=base_dir,use_logging=use_logging)
1239+
1240+
1241+
defconfigure_testgres(**options):
1242+
'''
1243+
Configure testgres. Look for TestgresConfig to check what can be changed.
1244+
'''
1245+
forkey,optioninoptions.items():
1246+
setattr(TestgresConfig,key,option)

‎tests/test_simple.py

100644100755
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
importtempfile
77
importlogging.config
88
importsubprocess
9+
importtestgres
910

1011
fromdistutils.versionimportLooseVersion
1112

1213
fromtestgresimportInitNodeException, \
1314
StartNodeException,ExecUtilException, \
1415
BackupException,QueryException,CatchUpException
1516

16-
fromtestgresimportget_new_node,get_pg_config
17+
fromtestgresimportget_new_node,get_pg_config,configure_testgres
1718
fromtestgresimportbound_ports
1819
fromtestgresimportNodeStatus
1920

@@ -414,6 +415,19 @@ def test_version_management(self):
414415
self.assertTrue(b>c)
415416
self.assertTrue(a>c)
416417

418+
deftest_configure(self):
419+
# set global if it wasn't set
420+
pg_config=get_pg_config()
421+
configure_testgres(cache_initdb=True,cache_pg_config=True)
422+
423+
# check that is the same instance
424+
self.assertEqual(id(get_pg_config()),id(testgres.pg_config_data))
425+
configure_testgres(cache_initdb=True,cache_pg_config=False)
426+
self.assertNotEqual(id(get_pg_config()),id(testgres.pg_config_data))
427+
428+
# return to the base state
429+
configure_testgres(cache_initdb=True,cache_pg_config=True)
430+
417431

418432
if__name__=='__main__':
419433
unittest.main()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp