summaryrefslogtreecommitdiffstats
path: root/test/features/steps/wrappers.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/features/steps/wrappers.py')
-rw-r--r--test/features/steps/wrappers.py55
1 files changed, 39 insertions, 16 deletions
diff --git a/test/features/steps/wrappers.py b/test/features/steps/wrappers.py
index de833dd..6408f23 100644
--- a/test/features/steps/wrappers.py
+++ b/test/features/steps/wrappers.py
@@ -3,6 +3,7 @@ import pexpect
import sys
import textwrap
+
try:
from StringIO import StringIO
except ImportError:
@@ -13,7 +14,7 @@ def expect_exact(context, expected, timeout):
timedout = False
try:
context.cli.expect_exact(expected, timeout=timeout)
- except pexpect.exceptions.TIMEOUT:
+ except pexpect.TIMEOUT:
timedout = True
if timedout:
# Strip color codes out of the output.
@@ -46,21 +47,43 @@ def expect_pager(context, expected, timeout):
context.conf['pager_boundary'], expected), timeout=timeout)
-def run_cli(context, run_args=None):
+def run_cli(context, run_args=None, exclude_args=None):
"""Run the process using pexpect."""
- run_args = run_args or []
- if context.conf.get('host', None):
- run_args.extend(('-h', context.conf['host']))
- if context.conf.get('user', None):
- run_args.extend(('-u', context.conf['user']))
- if context.conf.get('pass', None):
- run_args.extend(('-p', context.conf['pass']))
- if context.conf.get('dbname', None):
- run_args.extend(('-D', context.conf['dbname']))
- if context.conf.get('defaults-file', None):
- run_args.extend(('--defaults-file', context.conf['defaults-file']))
- if context.conf.get('myclirc', None):
- run_args.extend(('--myclirc', context.conf['myclirc']))
+ run_args = run_args or {}
+ rendered_args = []
+ exclude_args = set(exclude_args) if exclude_args else set()
+
+ conf = dict(**context.conf)
+ conf.update(run_args)
+
+ def add_arg(name, key, value):
+ if name not in exclude_args:
+ if value is not None:
+ rendered_args.extend((key, value))
+ else:
+ rendered_args.append(key)
+
+ if conf.get('host', None):
+ add_arg('host', '-h', conf['host'])
+ if conf.get('user', None):
+ add_arg('user', '-u', conf['user'])
+ if conf.get('pass', None):
+ add_arg('pass', '-p', conf['pass'])
+ if conf.get('port', None):
+ add_arg('port', '-P', str(conf['port']))
+ if conf.get('dbname', None):
+ add_arg('dbname', '-D', conf['dbname'])
+ if conf.get('defaults-file', None):
+ add_arg('defaults_file', '--defaults-file', conf['defaults-file'])
+ if conf.get('myclirc', None):
+ add_arg('myclirc', '--myclirc', conf['myclirc'])
+ if conf.get('login_path'):
+ add_arg('login_path', '--login-path', conf['login_path'])
+
+ for arg_name, arg_value in conf.items():
+ if arg_name.startswith('-'):
+ add_arg(arg_name, arg_name, arg_value)
+
try:
cli_cmd = context.conf['cli_command']
except KeyError:
@@ -73,7 +96,7 @@ def run_cli(context, run_args=None):
'"'
).format(sys.executable)
- cmd_parts = [cli_cmd] + run_args
+ cmd_parts = [cli_cmd] + rendered_args
cmd = ' '.join(cmd_parts)
context.cli = pexpect.spawnu(cmd, cwd=context.package_root)
context.logfile = StringIO()