diff options
author | Dick Marinus <dick@mrns.nl> | 2017-05-22 20:45:55 +0200 |
---|---|---|
committer | Dick Marinus <dick@mrns.nl> | 2017-05-22 20:45:55 +0200 |
commit | c6ae43a39825f7f3fb96677bf44d9feed5358d8f (patch) | |
tree | a6fa9689029ff516242f699143081d58613fa725 /tests/features/steps/wrappers.py | |
parent | bbb0866806917dd5a162587d1b95ed00c6fbceec (diff) | |
parent | bc6883a308055bd76f6ec82d5d2afdd3d911d528 (diff) |
Merge remote-tracking branch 'upstream/master' into feature/tox_behave
Diffstat (limited to 'tests/features/steps/wrappers.py')
-rw-r--r-- | tests/features/steps/wrappers.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/features/steps/wrappers.py b/tests/features/steps/wrappers.py new file mode 100644 index 00000000..2444ef0d --- /dev/null +++ b/tests/features/steps/wrappers.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 +from __future__ import unicode_literals + +import re +import pexpect + + +def expect_exact(context, expected, timeout): + try: + context.cli.expect_exact(expected, timeout=timeout) + except: + # Strip color codes out of the output. + actual = re.sub(r'\x1b\[([0-9A-Za-z;?])+[m|K]?', '', context.cli.before) + raise Exception('Expected:\n---\n{0!r}\n---\n\nActual:\n---\n{1!r}\n---'.format( + expected, + actual)) + + +def expect_pager(context, expected, timeout): + expect_exact(context, "{0}\r\n{1}{0}\r\n".format( + context.conf['pager_boundary'], expected), timeout=timeout) + + +def run_cli(context): + """Run the process using pexpect.""" + cli_cmd = context.conf.get('cli_command') + context.cli = pexpect.spawnu(cli_cmd, cwd=context.package_root) + context.exit_sent = False + context.currentdb = context.conf['dbname'] + + +def wait_prompt(context): + """Make sure prompt is displayed.""" + expect_exact(context, '{0}> '.format(context.conf['dbname']), timeout=5) |