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

Commit5508425

Browse files
committed
Merge branch 'master' of github.com:postgrespro/testgres
2 parents7a7dfdd +19bbb72 commit5508425

File tree

7 files changed

+47
-33
lines changed

7 files changed

+47
-33
lines changed

‎README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
[![codecov](https://codecov.io/gh/postgrespro/testgres/branch/master/graph/badge.svg)](https://codecov.io/gh/postgrespro/testgres)
33
[![PyPI version](https://badge.fury.io/py/testgres.svg)](https://badge.fury.io/py/testgres)
44

5+
[Documentation](https://postgrespro.github.io/testgres/)
6+
57
#testgres
68

79
PostgreSQL testing utility. Both Python 2.7 and 3.3+ are supported.

‎setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
readme=f.read()
2222

2323
setup(
24-
version='1.7.0',
24+
version='1.8.2',
2525
name='testgres',
2626
packages=['testgres'],
2727
description='Testing utility for PostgreSQL and its extensions',

‎testgres/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010

1111
from .connectionimport \
1212
NodeConnection, \
13+
DatabaseError, \
1314
InternalError, \
14-
ProgrammingError
15+
ProgrammingError, \
16+
OperationalError
1517

1618
from .exceptionsimport*
1719
from .enumsimport*

‎testgres/backup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ def spawn_primary(self, name=None, destroy=True):
143143
base_dir=self._prepare_dir(destroy)
144144

145145
# Build a new PostgresNode
146-
from .nodeimportPostgresNode
147-
withclean_on_error(PostgresNode(name=name,base_dir=base_dir))asnode:
146+
NodeClass=self.original_node.__class__
147+
withclean_on_error(NodeClass(name=name,base_dir=base_dir))asnode:
148148

149149
# New nodes should always remove dir tree
150150
node._should_rm_dirs=True

‎testgres/connection.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717

1818
from .exceptionsimportQueryException
1919

20-
# export these exceptions
20+
# export some exceptions
21+
DatabaseError=pglib.DatabaseError
2122
InternalError=pglib.InternalError
2223
ProgrammingError=pglib.ProgrammingError
24+
OperationalError=pglib.OperationalError
2325

2426

2527
classNodeConnection(object):

‎testgres/node.py

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919

2020
from .configimporttestgres_config
2121

22-
from .connectionimport \
23-
NodeConnection, \
24-
InternalError, \
25-
ProgrammingError
22+
from .connectionimportNodeConnection
2623

2724
from .constsimport \
2825
DATA_DIR, \
@@ -541,10 +538,10 @@ def append_conf(self, line='', filename=PG_CONF_FILE, **kwargs):
541538
This instance of :class:`.PostgresNode`.
542539
543540
Examples:
544-
append_conf(fsync=False)
545-
append_conf('log_connections = yes')
546-
append_conf(random_page_cost=1.5, fsync=True, ...)
547-
append_conf('postgresql.conf', 'synchronous_commit = off')
541+
>>>append_conf(fsync=False)
542+
>>>append_conf('log_connections = yes')
543+
>>>append_conf(random_page_cost=1.5, fsync=True, ...)
544+
>>>append_conf('postgresql.conf', 'synchronous_commit = off')
548545
"""
549546

550547
lines= [line]
@@ -815,7 +812,8 @@ def psql(self,
815812
filename=None,
816813
dbname=None,
817814
username=None,
818-
input=None):
815+
input=None,
816+
**variables):
819817
"""
820818
Execute a query using psql.
821819
@@ -825,9 +823,15 @@ def psql(self,
825823
dbname: database name to connect to.
826824
username: database user name.
827825
input: raw input to be passed.
826+
**variables: vars to be set before execution.
828827
829828
Returns:
830829
A tuple of (code, stdout, stderr).
830+
831+
Examples:
832+
>>> psql('select 1')
833+
>>> psql('postgres', 'select 2')
834+
>>> psql(query='select 3', ON_ERROR_STOP=1)
831835
"""
832836

833837
# Set default arguments
@@ -846,6 +850,10 @@ def psql(self,
846850
dbname
847851
]# yapf: disable
848852

853+
# set variables before execution
854+
forkey,valueiniteritems(variables):
855+
psql_params.extend(["--set",'{}={}'.format(key,value)])
856+
849857
# select query source
850858
ifquery:
851859
psql_params.extend(("-c",query))
@@ -877,10 +885,15 @@ def safe_psql(self, query=None, **kwargs):
877885
username: database user name.
878886
input: raw input to be passed.
879887
888+
**kwargs are passed to psql().
889+
880890
Returns:
881891
psql's output as str.
882892
"""
883893

894+
# force this setting
895+
kwargs['ON_ERROR_STOP']=1
896+
884897
ret,out,err=self.psql(query=query,**kwargs)
885898
ifret:
886899
raiseQueryException((errorb'').decode('utf-8'),query)
@@ -980,8 +993,7 @@ def poll_query_until(self,
980993
sleep_time=1,
981994
expected=True,
982995
commit=True,
983-
raise_programming_error=True,
984-
raise_internal_error=True):
996+
suppress=None):
985997
"""
986998
Run a query once per second until it returns 'expected'.
987999
Query should return a single value (1 row, 1 column).
@@ -994,13 +1006,13 @@ def poll_query_until(self,
9941006
sleep_time: how much should we sleep after a failure?
9951007
expected: what should be returned to break the cycle?
9961008
commit: should (possible) changes be committed?
997-
raise_programming_error: enable ProgrammingError?
998-
raise_internal_error: enable InternalError?
1009+
suppress: a collection of exceptions to be suppressed.
9991010
10001011
Examples:
1001-
poll_query_until('select true')
1002-
poll_query_until('postgres', "select now() > '01.01.2018'")
1003-
poll_query_until('select false', expected=True, max_attempts=4)
1012+
>>> poll_query_until('select true')
1013+
>>> poll_query_until('postgres', "select now() > '01.01.2018'")
1014+
>>> poll_query_until('select false', expected=True, max_attempts=4)
1015+
>>> poll_query_until('select 1', suppress={testgres.OperationalError})
10041016
"""
10051017

10061018
# sanity checks
@@ -1032,13 +1044,8 @@ def poll_query_until(self,
10321044
elifexpectedisNone:
10331045
return# done
10341046

1035-
exceptProgrammingErrorase:
1036-
ifraise_programming_error:
1037-
raisee
1038-
1039-
exceptInternalErrorase:
1040-
ifraise_internal_error:
1041-
raisee
1047+
excepttuple(suppressor []):
1048+
pass# we're suppressing them
10421049

10431050
time.sleep(sleep_time)
10441051
attempts+=1
@@ -1229,13 +1236,14 @@ def pgbench_run(self, dbname=None, username=None, options=[], **kwargs):
12291236
options: additional options for pgbench (list).
12301237
12311238
**kwargs: named options for pgbench.
1232-
Examples:
1233-
pgbench_run(initialize=True, scale=2)
1234-
pgbench_run(time=10)
12351239
Run pgbench --help to learn more.
12361240
12371241
Returns:
12381242
Stdout produced by pgbench.
1243+
1244+
Examples:
1245+
>>> pgbench_run(initialize=True, scale=2)
1246+
>>> pgbench_run(time=10)
12391247
"""
12401248

12411249
# Set default arguments

‎tests/test_simple.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ def test_poll_query_until(self):
626626
query='dummy2',
627627
max_attempts=3,
628628
sleep_time=0.01,
629-
raise_programming_error=False)
629+
suppress={testgres.ProgrammingError})
630630

631631
# check 1 arg, ok
632632
node.poll_query_until('select true')
@@ -862,7 +862,7 @@ def test_version_management(self):
862862
withget_new_node()asnode:
863863
self.assertTrue(isinstance(version,six.string_types))
864864
self.assertTrue(isinstance(node.version,PgVer))
865-
self.assertTrue(node.version==version)
865+
self.assertEqual(node.version,str(version))
866866

867867
deftest_child_pids(self):
868868
master_processes= [

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp