1
0
Fork 0

behave quit pgcli nicely

This commit is contained in:
Dick Marinus 2017-04-28 18:00:51 +02:00
parent 7858cbc473
commit 6f1f4bfa8e
5 changed files with 22 additions and 8 deletions

View File

@ -17,6 +17,7 @@ Internal changes:
-----------------
* Run pep8 checks in travis (Thanks: `Irina Truong`_).
* Add pager wrapper for behave tests (Thanks: `Dick Marinus`_).
* Behave quit pgcli nicely (Thanks: `Dick Marinus`_).
1.5.1
=====

View File

@ -6,6 +6,7 @@ import os
import sys
import db_utils as dbutils
import fixture_utils as fixutils
import pexpect
def before_all(context):
@ -86,14 +87,23 @@ def after_all(context):
os.environ[k] = v
def before_step(context, _):
context.atprompt = False
def after_scenario(context, _):
"""
Cleans up after each test complete.
"""
"""Cleans up after each test complete."""
if hasattr(context, 'cli') and not context.exit_sent:
# Terminate nicely.
context.cli.terminate()
# Quit nicely.
if not context.atprompt:
dbname = context.currentdb
context.cli.expect_exact(
'{0}> '.format(dbname),
timeout=5
)
context.cli.sendcontrol('d')
context.cli.expect_exact(pexpect.EOF, timeout=5)
# TODO: uncomment to debug a failure
# def after_step(context, step):

View File

@ -20,6 +20,7 @@ def step_run_cli(context):
cli_cmd = context.conf.get('cli_command')
context.cli = pexpect.spawnu(cli_cmd, cwd='..')
context.exit_sent = False
context.currentdb = context.conf['dbname']
@when('we wait for prompt')

View File

@ -49,6 +49,7 @@ def step_db_connect_dbserver(context):
Send connect to database.
"""
context.cli.sendline('\\connect postgres')
context.currentdb = 'postgres'
@then('dbcli exits')
@ -65,6 +66,7 @@ def step_see_prompt(context):
Wait to see the prompt.
"""
wrappers.expect_exact(context, '{0}> '.format(context.conf['dbname']), timeout=5)
context.atprompt = True
@then('we see help output')
@ -78,7 +80,7 @@ def step_see_db_created(context):
"""
Wait to see create database output.
"""
wrappers.expect_exact(context, 'CREATE DATABASE', timeout=2)
wrappers.expect_pager(context, 'CREATE DATABASE\r\n', timeout=5)
@then('we see database dropped')
@ -86,7 +88,7 @@ def step_see_db_dropped(context):
"""
Wait to see drop database output.
"""
wrappers.expect_exact(context, 'DROP DATABASE', timeout=2)
wrappers.expect_pager(context, 'DROP DATABASE\r\n', timeout=2)
@then('we see database connected')

View File

@ -38,7 +38,7 @@ def step_edit_done_sql(context):
for match in 'select * from abc'.split(' '):
wrappers.expect_exact(context, match, timeout=1)
# Cleanup the command line.
context.cli.sendcontrol('u')
context.cli.sendcontrol('c')
# Cleanup the edited file.
if context.editor_file_name and os.path.exists(context.editor_file_name):
os.remove(context.editor_file_name)