Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f949313

Browse files
committed
Merge branch 'master' into gh-pages
2 parents 4de6f7a + 25cf688 commit f949313

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
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.8.0',
24+
version='1.8.2',
2525
name='testgres',
2626
packages=['testgres'],
2727
description='Testing utility for PostgreSQL and its extensions',

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 .node import PostgresNode
147-
with clean_on_error(PostgresNode(name=name, base_dir=base_dir)) as node:
146+
NodeClass = self.original_node.__class__
147+
with clean_on_error(NodeClass(name=name, base_dir=base_dir)) as node:
148148

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

testgres/node.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,8 @@ def psql(self,
812812
filename=None,
813813
dbname=None,
814814
username=None,
815-
input=None):
815+
input=None,
816+
**variables):
816817
"""
817818
Execute a query using psql.
818819
@@ -822,9 +823,18 @@ def psql(self,
822823
dbname: database name to connect to.
823824
username: database user name.
824825
input: raw input to be passed.
826+
**variables: vars to be set before execution.
825827
826828
Returns:
827829
A tuple of (code, stdout, stderr).
830+
831+
Examples:
832+
>>> psql('select 1')
833+
(0, b'1\n', b'')
834+
>>> psql('postgres', 'select 2')
835+
(0, b'2\n', b'')
836+
>>> psql(query='select 3', ON_ERROR_STOP=1)
837+
(0, b'3\n', b'')
828838
"""
829839

830840
# Set default arguments
@@ -843,6 +853,10 @@ def psql(self,
843853
dbname
844854
] # yapf: disable
845855

856+
# set variables before execution
857+
for key, value in iteritems(variables):
858+
psql_params.extend(["--set", '{}={}'.format(key, value)])
859+
846860
# select query source
847861
if query:
848862
psql_params.extend(("-c", query))
@@ -874,10 +888,15 @@ def safe_psql(self, query=None, **kwargs):
874888
username: database user name.
875889
input: raw input to be passed.
876890
891+
**kwargs are passed to psql().
892+
877893
Returns:
878894
psql's output as str.
879895
"""
880896

897+
# force this setting
898+
kwargs['ON_ERROR_STOP'] = 1
899+
881900
ret, out, err = self.psql(query=query, **kwargs)
882901
if ret:
883902
raise QueryException((err or b'').decode('utf-8'), query)

0 commit comments

Comments
 (0)