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

Skip to content

Commit 2ceabc0

Browse files
authored
Merge pull request #36 from ildus/master
Use kwargs for several functions to move through all possible arguments
2 parents 04e74ab + 9b06dc2 commit 2ceabc0

File tree

1 file changed

+14
-30
lines changed

1 file changed

+14
-30
lines changed

testgres/node.py

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
HBA_CONF_FILE, \
3131
RECOVERY_CONF_FILE, \
3232
PG_LOG_FILE, \
33-
UTILS_LOG_FILE, \
34-
DEFAULT_XLOG_METHOD
33+
UTILS_LOG_FILE
3534

3635
from .decorators import \
3736
method_decorator, \
@@ -112,7 +111,7 @@ def __enter__(self):
112111
def __exit__(self, type, value, traceback):
113112
self.free_port()
114113

115-
# NOTE: ctrl+C does not count!
114+
# NOTE: Ctrl+C does not count!
116115
got_exception = type is not None and type != KeyboardInterrupt
117116

118117
c1 = self.cleanup_on_good_exit and not got_exception
@@ -254,19 +253,15 @@ def _collect_special_files(self):
254253

255254
return result
256255

257-
def init(self,
258-
fsync=False,
259-
unix_sockets=True,
260-
allow_streaming=True,
261-
initdb_params=None):
256+
def init(self, initdb_params=None, **kwargs):
262257
"""
263258
Perform initdb for this node.
264259
265260
Args:
261+
initdb_params: parameters for initdb (list).
266262
fsync: should this node use fsync to keep data safe?
267263
unix_sockets: should we enable UNIX sockets?
268264
allow_streaming: should this node add a hba entry for replication?
269-
initdb_params: parameters for initdb (list).
270265
271266
Returns:
272267
This instance of PostgresNode.
@@ -281,9 +276,7 @@ def init(self,
281276
params=initdb_params)
282277

283278
# initialize default config files
284-
self.default_conf(fsync=fsync,
285-
unix_sockets=unix_sockets,
286-
allow_streaming=allow_streaming)
279+
self.default_conf(**kwargs)
287280

288281
return self
289282

@@ -682,16 +675,13 @@ def psql(self,
682675
return process.returncode, out, err
683676

684677
@method_decorator(positional_args_hack(['dbname', 'query']))
685-
def safe_psql(self,
686-
query,
687-
dbname=None,
688-
username=None,
689-
input=None):
678+
def safe_psql(self, query=None, **kwargs):
690679
"""
691680
Execute a query using psql.
692681
693682
Args:
694683
query: query to be executed.
684+
filename: file with a query.
695685
dbname: database name to connect to.
696686
username: database user name.
697687
input: raw input to be passed.
@@ -700,10 +690,7 @@ def safe_psql(self,
700690
psql's output as str.
701691
"""
702692

703-
ret, out, err = self.psql(query=query,
704-
dbname=dbname,
705-
username=username,
706-
input=input)
693+
ret, out, err = self.psql(query=query, **kwargs)
707694
if ret:
708695
raise QueryException((err or b'').decode('utf-8'), query)
709696

@@ -859,37 +846,34 @@ def execute(self,
859846

860847
return res
861848

862-
def backup(self, username=None, xlog_method=DEFAULT_XLOG_METHOD):
849+
def backup(self, **kwargs):
863850
"""
864851
Perform pg_basebackup.
865852
866853
Args:
867854
username: database user name.
868855
xlog_method: a method for collecting the logs ('fetch' | 'stream').
856+
base_dir: the base directory for data files and logs
869857
870858
Returns:
871859
A smart object of type NodeBackup.
872860
"""
873861

874862
from .backup import NodeBackup
875-
return NodeBackup(node=self,
876-
username=username,
877-
xlog_method=xlog_method)
863+
return NodeBackup(node=self, **kwargs)
878864

879-
def replicate(self,
880-
name=None,
881-
username=None,
882-
xlog_method=DEFAULT_XLOG_METHOD):
865+
def replicate(self, name=None, **kwargs):
883866
"""
884867
Create a binary replica of this node.
885868
886869
Args:
887870
name: replica's application name.
888871
username: database user name.
889872
xlog_method: a method for collecting the logs ('fetch' | 'stream').
873+
base_dir: the base directory for data files and logs
890874
"""
891875

892-
backup = self.backup(username=username, xlog_method=xlog_method)
876+
backup = self.backup(**kwargs)
893877

894878
# transform backup into a replica
895879
return backup.spawn_replica(name=name, destroy=True)

0 commit comments

Comments
 (0)