8000 Use kwargs for several functions to move through all possible arguments by ildus · Pull Request #36 · postgrespro/testgres · GitHub
[go: up one dir, main page]

Skip to content

Use kwargs for several functions to move through all possible arguments #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 28, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Use kwargs for several functions to move through all possible arguments
  • Loading branch information
ildus committed Feb 28, 2018
commit 8e5b09d66ca3fd5bad0c380aea5086e44f71f59c
29 changes: 10 additions & 19 deletions testgres/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def __enter__(self):
def __exit__(self, type, value, traceback):
self.free_port()

# NOTE: ctrl+C does not count!
# NOTE: Ctrl+C does not count!
got_exception = type is not None and type != KeyboardInterrupt

c1 = self.cleanup_on_good_exit and not got_exception
Expand Down Expand Up @@ -681,16 +681,13 @@ def psql(self,
return process.returncode, out, err

@method_decorator(positional_args_hack(['dbname', 'query']))
def safe_psql(self,
query,
dbname=None,
username=None,
input=None):
def safe_psql(self, query=None, **kwargs):
"""
Execute a query using psql.

Args:
query: query to be executed.
filename: file with a query.
dbname: database name to connect to.
username: database user name.
input: raw input to be passed.
Expand All @@ -699,10 +696,7 @@ def safe_psql(self,
psql's output as str.
"""

ret, out, err = self.psql(query=query,
dbname=dbname,
username=username,
input=input)
ret, out, err = self.psql(query=query, **kwargs)
if ret:
raise QueryException((err or b'').decode('utf-8'), query)

Expand Down Expand Up @@ -858,37 +852,34 @@ def execute(self,

return res

def backup(self, username=None, xlog_method=DEFAULT_XLOG_METHOD):
def backup(self, **kwargs):
"""
Perform pg_basebackup.

Args:
username: database user name.
xlog_method: a method for collecting the logs ('fetch' | 'stream').
base_dir: the base directory for data files and logs

Returns:
A smart object of type NodeBackup.
"""

from .backup import NodeBackup
return NodeBackup(node=self,
username=username,
xlog_method=xlog_method)
return NodeBackup(node=self, **kwargs)

def replicate(self,
name=None,
username=None,
xlog_method=DEFAULT_XLOG_METHOD):
def replicate(self, name=None, **kwargs):
"""
Create a binary replica of this node.

Args:
name: replica's application name.
username: database user name.
xlog_method: a method for collecting the logs ('fetch' | 'stream').
base_dir: the base directory for data files and logs
"""

backup = self.backup(username=username, xlog_method=xlog_method)
backup = self.backup(**kwargs)

# transform backup into a replica
return backup.spawn_replica(name=name, destroy=True)
Expand Down
0