From 5a604026493ba8dc36eb13306d389cc428994982 Mon Sep 17 00:00:00 2001 From: Dick Marinus Date: Sat, 29 Apr 2017 21:35:06 +0200 Subject: [PATCH] Test using behave the tee command --- changelog.rst | 1 + tests/features/iocommands.feature | 11 +++++++++ tests/features/steps/iocommands.py | 37 ++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/changelog.rst b/changelog.rst index 2f0ebe2e..0b2bbbf7 100644 --- a/changelog.rst +++ b/changelog.rst @@ -19,6 +19,7 @@ Internal changes: * Add pager wrapper for behave tests (Thanks: `Dick Marinus`_). * Behave quit pgcli nicely (Thanks: `Dick Marinus`_). * Behave test source command (Thanks: `Dick Marinus`_). +* Test using behave the tee command (Thanks: `Dick Marinus`_). 1.5.1 ===== diff --git a/tests/features/iocommands.feature b/tests/features/iocommands.feature index d043dc2e..4bcdf6e6 100644 --- a/tests/features/iocommands.feature +++ b/tests/features/iocommands.feature @@ -8,3 +8,14 @@ Feature: I/O commands and we exit the editor then we see dbcli prompt and we see the sql in prompt + + Scenario: tee output from query + When we run dbcli + and we wait for prompt + and we tee output + and we wait for prompt + and we query "select 123456" + and we wait for prompt + and we notee output + and we wait for prompt + then we see 123456 in tee output diff --git a/tests/features/steps/iocommands.py b/tests/features/steps/iocommands.py index 951c1dc6..7393bc4e 100644 --- a/tests/features/steps/iocommands.py +++ b/tests/features/steps/iocommands.py @@ -42,3 +42,40 @@ def step_edit_done_sql(context): # Cleanup the edited file. if context.editor_file_name and os.path.exists(context.editor_file_name): os.remove(context.editor_file_name) + + +@when(u'we tee output') +def step_tee_ouptut(context): + context.tee_file_name = [ + '..', + 'tee_file_{0}.sql'.format(context.conf['vi']) + ] + if os.path.exists(os.path.join(*context.tee_file_name)): + os.remove(os.path.join(*context.tee_file_name)) + context.cli.sendline('\o {0}'.format(context.tee_file_name[1])) + wrappers.expect_exact( + context, context.conf['pager_boundary'] + '\r\n', timeout=5) + wrappers.expect_exact(context, "Writing to file", timeout=5) + wrappers.expect_exact( + context, context.conf['pager_boundary'] + '\r\n', timeout=5) + wrappers.expect_exact(context, "Time", timeout=5) + + +@when(u'we query "select 123456"') +def step_query_select_123456(context): + context.cli.sendline('select 123456') + + +@when(u'we notee output') +def step_notee_output(context): + context.cli.sendline('notee') + wrappers.expect_exact(context, "Time", timeout=5) + + +@then(u'we see 123456 in tee output') +def step_see_123456_in_ouput(context): + with open(os.path.join(*context.tee_file_name)) as f: + assert '123456' in f.read() + if os.path.exists(os.path.join(*context.tee_file_name)): + os.remove(os.path.join(*context.tee_file_name)) + context.atprompt = True