Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3378f28

Browse files
committed
small fixes, improve tests
1 parent dd8c500 commit 3378f28

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

testgres/config.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def copy(self):
9898
TestgresConfig = testgres_config
9999

100100
# stack of GlobalConfigs
101-
config_stack = [testgres_config]
101+
config_stack = []
102102

103103

104104
def rm_cached_initdb_dirs():
@@ -123,7 +123,7 @@ def pop_config():
123123
Set previous GlobalConfig options from stack.
124124
"""
125125

126-
if len(config_stack) <= 1:
126+
if len(config_stack) == 0:
127127
raise IndexError('Reached initial config')
128128

129129
# restore popped config
@@ -141,9 +141,10 @@ def scoped_config(**options):
141141
... print(node.execute('select 1'))
142142
"""
143143

144-
# set a new config with options
145-
config = push_config(**options)
146144
try:
145+
# set a new config with options
146+
config = push_config(**options)
147+
147148
# return it
148149
yield config
149150
finally:

tests/test_simple.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,16 @@ def test_config_stack(self):
549549
self.assertEqual(c1.cached_initdb_dir, d1)
550550

551551
with scoped_config(cached_initdb_dir=d2) as c2:
552+
553+
stack_size = len(testgres.config.config_stack)
554+
555+
# try to break a stack
556+
with self.assertRaises(TypeError):
557+
with scoped_config(dummy=True):
558+
pass
559+
552560
self.assertEqual(c2.cached_initdb_dir, d2)
561+
self.assertEqual(len(testgres.config.config_stack), stack_size)
553562

554563
self.assertEqual(c1.cached_initdb_dir, d1)
555564

0 commit comments

Comments
 (0)