summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorIrina Truong <i.chernyavska@gmail.com>2018-10-02 17:10:43 -0700
committerGitHub <noreply@github.com>2018-10-02 17:10:43 -0700
commitfcf0eb022ee81cc8e961c08c4a89742a9714cd63 (patch)
tree490cb8c6e1a207316f6c1f51996d45c17f756268 /tests
parentec5131e1daf7b96549c743ba1b22d3d83657c159 (diff)
Fix for pgcli --list. (#952)
Fix for pgcli --list
Diffstat (limited to 'tests')
-rw-r--r--tests/features/basic_commands.feature5
-rw-r--r--tests/features/environment.py21
-rw-r--r--tests/features/steps/basic_commands.py16
-rw-r--r--tests/features/steps/iocommands.py1
4 files changed, 35 insertions, 8 deletions
diff --git a/tests/features/basic_commands.feature b/tests/features/basic_commands.feature
index a12e8992..8c9ce437 100644
--- a/tests/features/basic_commands.feature
+++ b/tests/features/basic_commands.feature
@@ -17,3 +17,8 @@ Feature: run the cli,
Scenario: run the cli and exit
When we send "ctrl + d"
then dbcli exits
+
+ Scenario: list databases
+ When we list databases
+ then we see list of databases
+
diff --git a/tests/features/environment.py b/tests/features/environment.py
index 5fa8b299..dedbe093 100644
--- a/tests/features/environment.py
+++ b/tests/features/environment.py
@@ -9,6 +9,7 @@ import fixture_utils as fixutils
import pexpect
import tempfile
import shutil
+import signal
from steps import wrappers
@@ -146,24 +147,28 @@ def before_step(context, _):
context.atprompt = False
-def before_scenario(context, _):
+def before_scenario(context, scenario):
+ if scenario.name == 'list databases':
+ # not using the cli for that
+ return
wrappers.run_cli(context)
wrappers.wait_prompt(context)
-def after_scenario(context, _):
+def after_scenario(context, scenario):
"""Cleans up after each scenario completes."""
- if hasattr(context, 'cli') and not context.exit_sent:
+ if hasattr(context, 'cli') and context.cli and not context.exit_sent:
# Quit nicely.
if not context.atprompt:
dbname = context.currentdb
- context.cli.expect_exact(
- '{0}> '.format(dbname),
- timeout=5
- )
+ context.cli.expect_exact('{0}> '.format(dbname), timeout=15)
context.cli.sendcontrol('c')
context.cli.sendcontrol('d')
- context.cli.expect_exact(pexpect.EOF, timeout=10)
+ try:
+ context.cli.expect_exact(pexpect.EOF, timeout=15)
+ except pexpect.TIMEOUT:
+ print('--- after_scenario {}: kill cli'.format(scenario.name))
+ context.cli.kill(signal.SIGKILL)
if hasattr(context, 'tmpfile_sql_help') and context.tmpfile_sql_help:
context.tmpfile_sql_help.close()
context.tmpfile_sql_help = None
diff --git a/tests/features/steps/basic_commands.py b/tests/features/steps/basic_commands.py
index 9bafb61d..ab46089e 100644
--- a/tests/features/steps/basic_commands.py
+++ b/tests/features/steps/basic_commands.py
@@ -6,6 +6,8 @@ This string is used to call the step in "*.feature" file.
"""
from __future__ import unicode_literals, print_function
+import pexpect
+import subprocess
import tempfile
from behave import when, then
@@ -13,6 +15,19 @@ from textwrap import dedent
import wrappers
+@when('we list databases')
+def step_list_databases(context):
+ cmd = ['pgcli', '--list']
+ context.cmd_output = subprocess.check_output(cmd, cwd=context.package_root)
+
+
+@then('we see list of databases')
+def step_see_list_databases(context):
+ assert b'List of databases' in context.cmd_output
+ assert b'postgres' in context.cmd_output
+ context.cmd_output = None
+
+
@when('we run dbcli')
def step_run_cli(context):
wrappers.run_cli(context)
@@ -32,6 +47,7 @@ def step_ctrl_d(context):
context.cli.sendline('\pset pager off')
wrappers.wait_prompt(context)
context.cli.sendcontrol('d')
+ context.cli.expect_exact(pexpect.EOF, timeout=15)
context.exit_sent = True
diff --git a/tests/features/steps/iocommands.py b/tests/features/steps/iocommands.py
index 95bf8652..1a1a4c5c 100644
--- a/tests/features/steps/iocommands.py
+++ b/tests/features/steps/iocommands.py
@@ -44,6 +44,7 @@ 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)
+ context.atprompt = True
@when(u'we tee output')