Skip to content

Commit 5f08f2e

Browse files
committed
reformat code, add 'commit' arg to poll_query_until()
1 parent f59150b commit 5f08f2e

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

testgres/testgres.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def run(self):
154154
# work until we're asked to stop
155155
while not self._stop_event.is_set():
156156
# do we have new lines?
157-
import select # used only here
157+
import select # used only here
158158
if fd in select.select([fd], [], [], 0)[0]:
159159
for line in fd.readlines():
160160
line = line.strip()
@@ -982,6 +982,7 @@ def poll_query_until(self,
982982
max_attempts=0,
983983
sleep_time=1,
984984
expected=True,
985+
commit=True,
985986
raise_programming_error=True,
986987
raise_internal_error=True):
987988
"""
@@ -1009,7 +1010,7 @@ def poll_query_until(self,
10091010
res = self.execute(dbname=dbname,
10101011
query=query,
10111012
username=username,
1012-
commit=True)
1013+
commit=commit)
10131014

10141015
if expected is None and res is None:
10151016
return # done

tests/test_simple.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,23 +360,35 @@ def test_poll_query_until(self):
360360
check_time = 'select extract(epoch from now()) - {} >= 5'
361361

362362
start_time = node.execute('postgres', get_time)[0][0]
363-
node.poll_query_until('postgres', check_time.format(start_time))
363+
node.poll_query_until(
364+
dbname='postgres', query=check_time.format(start_time))
364365
end_time = node.execute('postgres', get_time)[0][0]
365366

366367
self.assertTrue(end_time - start_time >= 5)
367368

368369
# check 0 rows
369370
with self.assertRaises(QueryException):
370371
node.poll_query_until(
371-
'postgres', 'select * from pg_class where true = false')
372+
dbname='postgres',
373+
query='select * from pg_class where true = false')
372374

373375
# check 0 columns
374376
with self.assertRaises(QueryException):
375-
node.poll_query_until('postgres',
376-
'select from pg_class limit 1')
377-
# check None
377+
node.poll_query_until(
378+
dbname='postgres', query='select from pg_class limit 1')
379+
# check None, fail
378380
with self.assertRaises(QueryException):
379-
node.poll_query_until('postgres', 'create table abc (val int)')
381+
node.poll_query_until(
382+
dbname='postgres', query='create table abc (val int)')
383+
384+
# check None, ok
385+
node.poll_query_until(
386+
dbname='postgres', query='create table def()',
387+
expected=None) # returns nothing
388+
389+
# check arbitrary expected value
390+
node.poll_query_until(
391+
dbname='postgres', query='select 1', expected=1)
380392

381393
# check timeout
382394
with self.assertRaises(TimeoutException):

0 commit comments

Comments
 (0)