summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorIrina Truong <i.chernyavska@gmail.com>2019-05-25 13:08:56 -0700
committerGitHub <noreply@github.com>2019-05-25 13:08:56 -0700
commit8cb7009bcd0f0062942932c853706a36178f566c (patch)
treecb5bb42674ccce90b173e7a2f09bf72157ae4a86 /tests
parenta5e607b6fc889afd3f8960ca3903ae16b641c304 (diff)
black all the things. (#1049)
* added black to develop guide * no need for pep8radius. * changelog. * Add pre-commit checkbox. * Add pre-commit to dev reqs. * Add pyproject.toml for black. * Pre-commit config. * Add black to travis and dev reqs. * Install and run black in travis. * Remove black from dev reqs. * Lower black target version. * Re-format with black.
Diffstat (limited to 'tests')
-rw-r--r--tests/conftest.py27
-rw-r--r--tests/features/db_utils.py26
-rw-r--r--tests/features/environment.py168
-rw-r--r--tests/features/fixture_utils.py8
-rw-r--r--tests/features/steps/auto_vertical.py37
-rw-r--r--tests/features/steps/basic_commands.py88
-rw-r--r--tests/features/steps/crud_database.py50
-rw-r--r--tests/features/steps/crud_table.py55
-rw-r--r--tests/features/steps/expanded.py48
-rw-r--r--tests/features/steps/iocommands.py59
-rw-r--r--tests/features/steps/named_queries.py26
-rw-r--r--tests/features/steps/specials.py9
-rw-r--r--tests/features/steps/wrappers.py30
-rwxr-xr-xtests/features/wrappager.py4
-rw-r--r--tests/metadata.py176
-rw-r--r--tests/parseutils/test_ctes.py128
-rw-r--r--tests/parseutils/test_function_metadata.py9
-rw-r--r--tests/parseutils/test_parseutils.py244
-rw-r--r--tests/test_completion_refresher.py27
-rw-r--r--tests/test_fuzzy_completion.py24
-rw-r--r--tests/test_main.py282
-rw-r--r--tests/test_naive_completion.py112
-rw-r--r--tests/test_pgexecute.py382
-rw-r--r--tests/test_pgspecial.py82
-rw-r--r--tests/test_prioritization.py10
-rw-r--r--tests/test_prompt_utils.py4
-rw-r--r--tests/test_rowlimit.py5
-rw-r--r--tests/test_smart_completion_multiple_schemata.py767
-rw-r--r--tests/test_smart_completion_public_schema_only.py1181
-rw-r--r--tests/test_sqlcompletion.py1229
-rw-r--r--tests/utils.py60
31 files changed, 2910 insertions, 2447 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index 26a40816..315e3de8 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -2,15 +2,22 @@ from __future__ import print_function
import os
import pytest
-from utils import (POSTGRES_HOST, POSTGRES_PORT, POSTGRES_USER, POSTGRES_PASSWORD, create_db, db_connection,
- drop_tables)
+from utils import (
+ POSTGRES_HOST,
+ POSTGRES_PORT,
+ POSTGRES_USER,
+ POSTGRES_PASSWORD,
+ create_db,
+ db_connection,
+ drop_tables,
+)
import pgcli.pgexecute
@pytest.yield_fixture(scope="function")
def connection():
- create_db('_test_db')
- connection = db_connection('_test_db')
+ create_db("_test_db")
+ connection = db_connection("_test_db")
yield connection
drop_tables(connection)
@@ -25,8 +32,14 @@ def cursor(connection):
@pytest.fixture
def executor(connection):
- return pgcli.pgexecute.PGExecute(database='_test_db', user=POSTGRES_USER, host=POSTGRES_HOST,
- password=POSTGRES_PASSWORD, port=POSTGRES_PORT, dsn=None)
+ return pgcli.pgexecute.PGExecute(
+ database="_test_db",
+ user=POSTGRES_USER,
+ host=POSTGRES_HOST,
+ password=POSTGRES_PASSWORD,
+ port=POSTGRES_PORT,
+ dsn=None,
+ )
@pytest.fixture
@@ -38,4 +51,4 @@ def exception_formatter():
def temp_config(tmpdir_factory):
# this function runs on start of test session.
# use temporary directory for config home so user config will not be used
- os.environ['XDG_CONFIG_HOME'] = str(tmpdir_factory.mktemp('data'))
+ os.environ["XDG_CONFIG_HOME"] = str(tmpdir_factory.mktemp("data"))
diff --git a/tests/features/db_utils.py b/tests/features/db_utils.py
index e0b2035d..4eba6063 100644
--- a/tests/features/db_utils.py
+++ b/tests/features/db_utils.py
@@ -6,7 +6,9 @@ from psycopg2 import connect
from psycopg2.extensions import AsIs
-def create_db(hostname='localhost', username=None, password=None, dbname=None, port=None):
+def create_db(
+ hostname="localhost", username=None, password=None, dbname=None, port=None
+):
"""Create test database.
:param hostname: string
@@ -17,15 +19,15 @@ def create_db(hostname='localhost', username=None, password=None, dbname=None, p
:return:
"""
- cn = create_cn(hostname, password, username, 'postgres', port)
+ cn = create_cn(hostname, password, username, "postgres", port)
# ISOLATION_LEVEL_AUTOCOMMIT = 0
# Needed for DB creation.
cn.set_isolation_level(0)
with cn.cursor() as cr:
- cr.execute('drop database if exists %s', (AsIs(dbname),))
- cr.execute('create database %s', (AsIs(dbname),))
+ cr.execute("drop database if exists %s", (AsIs(dbname),))
+ cr.execute("create database %s", (AsIs(dbname),))
cn.close()
@@ -42,15 +44,15 @@ def create_cn(hostname, password, username, dbname, port):
:param dbname: string
:return: psycopg2.connection
"""
- cn = connect(host=hostname, user=username, database=dbname,
- password=password, port=port)
+ cn = connect(
+ host=hostname, user=username, database=dbname, password=password, port=port
+ )
- print('Created connection: {0}.'.format(cn.dsn))
+ print ("Created connection: {0}.".format(cn.dsn))
return cn
-def drop_db(hostname='localhost', username=None, password=None,
- dbname=None, port=None):
+def drop_db(hostname="localhost", username=None, password=None, dbname=None, port=None):
"""
Drop database.
:param hostname: string
@@ -58,14 +60,14 @@ def drop_db(hostname='localhost', username=None, password=None,
:param password: string
:param dbname: string
"""
- cn = create_cn(hostname, password, username, 'postgres', port)
+ cn = create_cn(hostname, password, username, "postgres", port)
# ISOLATION_LEVEL_AUTOCOMMIT = 0
# Needed for DB drop.
cn.set_isolation_level(0)
with cn.cursor() as cr:
- cr.execute('drop database if exists %s', (AsIs(dbname),))
+ cr.execute("drop database if exists %s", (AsIs(dbname),))
close_cn(cn)
@@ -77,4 +79,4 @@ def close_cn(cn=None):
"""
if cn:
cn.close()
- print('Closed connection: {0}.'.format(cn.dsn))
+ print ("Closed connection: {0}.".format(cn.dsn))
diff --git a/tests/features/environment.py b/tests/features/environment.py
index 6b4d4241..0133ab01 100644
--- a/tests/features/environment.py
+++ b/tests/features/environment.py
@@ -18,113 +18,119 @@ from steps import wrappers
def before_all(context):
"""Set env parameters."""
env_old = copy.deepcopy(dict(os.environ))
- os.environ['LINES'] = "100"
- os.environ['COLUMNS'] = "100"
- os.environ['PAGER'] = 'cat'
- os.environ['EDITOR'] = 'ex'
- os.environ['VISUAL'] = 'ex'
+ os.environ["LINES"] = "100"
+ os.environ["COLUMNS"] = "100"
+ os.environ["PAGER"] = "cat"
+ os.environ["EDITOR"] = "ex"
+ os.environ["VISUAL"] = "ex"
context.package_root = os.path.abspath(
- os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
- fixture_dir = os.path.join(
- context.package_root, 'tests/features/fixture_data')
+ os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
+ )
+ fixture_dir = os.path.join(context.package_root, "tests/features/fixture_data")
- print('package root:', context.package_root)
- print('fixture dir:', fixture_dir)
+ print ("package root:", context.package_root)
+ print ("fixture dir:", fixture_dir)
- os.environ["COVERAGE_PROCESS_START"] = os.path.join(context.package_root,
- '.coveragerc')
+ os.environ["COVERAGE_PROCESS_START"] = os.path.join(
+ context.package_root, ".coveragerc"
+ )
context.exit_sent = False
- vi = '_'.join([str(x) for x in sys.version_info[:3]])
- db_name = context.config.userdata.get('pg_test_db', 'pgcli_behave_tests')
- db_name_full = '{0}_{1}'.format(db_name, vi)
+ vi = "_".join([str(x) for x in sys.version_info[:3]])
+ db_name = context.config.userdata.get("pg_test_db", "pgcli_behave_tests")
+ db_name_full = "{0}_{1}".format(db_name, vi)
# Store get params from config.
context.conf = {
- 'host': context.config.userdata.get(
- 'pg_test_host',
- os.getenv('PGHOST', 'localhost')
+ "host": context.config.userdata.get(
+ "pg_test_host", os.getenv("PGHOST", "localhost")
),
- 'user': context.config.userdata.get(
- 'pg_test_user',
- os.getenv('PGUSER', 'postgres')
+ "user": context.config.userdata.get(
+ "pg_test_user", os.getenv("PGUSER", "postgres")
),
- 'pass': context.config.userdata.get(
- 'pg_test_pass',
- os.getenv('PGPASSWORD', None)
+ "pass": context.config.userdata.get(
+ "pg_test_pass", os.getenv("PGPASSWORD", None)
),
- 'port': context.config.userdata.get(
- 'pg_test_port',
- os.getenv('PGPORT', '5432')
+ "port": context.config.userdata.get(
+ "pg_test_port", os.getenv("PGPORT", "5432")
),
- 'cli_command': (
- context.config.userdata.get('pg_cli_command', None) or
- '{python} -c "{startup}"'.format(
+ "cli_command": (
+ context.config.userdata.get("pg_cli_command", None)
+ or '{python} -c "{startup}"'.format(
python=sys.executable,
- startup='; '.join([
- "import coverage",
- "coverage.process_startup()",
- "import pgcli.main",
- "pgcli.main.cli()"]))),
- 'dbname': db_name_full,
- 'dbname_tmp': db_name_full + '_tmp',
- 'vi': vi,
- 'pager_boundary': '---boundary---',
+ startup="; ".join(
+ [
+ "import coverage",
+ "coverage.process_startup()",
+ "import pgcli.main",
+ "pgcli.main.cli()",
+ ]
+ ),
+ )
+ ),
+ "dbname": db_name_full,
+ "dbname_tmp": db_name_full + "_tmp",
+ "vi": vi,
+ "pager_boundary": "---boundary---",
}
- os.environ['PAGER'] = "{0} {1} {2}".format(
+ os.environ["PAGER"] = "{0} {1} {2}".format(
sys.executable,
os.path.join(context.package_root, "tests/features/wrappager.py"),
- context.conf['pager_boundary'])
+ context.conf["pager_boundary"],
+ )
# Store old env vars.
context.pgenv = {
- 'PGDATABASE': os.environ.get('PGDATABASE', None),
- 'PGUSER': os.environ.get('PGUSER', None),
- 'PGHOST': os.environ.get('PGHOST', None),
- 'PGPASSWORD': os.environ.get('PGPASSWORD', None),
- 'PGPORT': os.environ.get('PGPORT', None),
- 'XDG_CONFIG_HOME': os.environ.get('XDG_CONFIG_HOME', None),
- 'PGSERVICEFILE': os.environ.get('PGSERVICEFILE', None),
+ "PGDATABASE": os.environ.get("PGDATABASE", None),
+ "PGUSER": os.environ.get("PGUSER", None),
+ "PGHOST": os.environ.get("PGHOST", None),
+ "PGPASSWORD": os.environ.get("PGPASSWORD", None),
+ "PGPORT": os.environ.get("PGPORT", None),
+ "XDG_CONFIG_HOME": os.environ.get("XDG_CONFIG_HOME", None),
+ "PGSERVICEFILE": os.environ.get("PGSERVICEFILE", None),
}
# Set new env vars.
- os.environ['PGDATABASE'] = context.conf['dbname']
- os.environ['PGUSER'] = context.conf['user']
- os.environ['PGHOST'] = context.conf['host']
- os.environ['PGPORT'] = context.conf['port']
- os.environ['PGSERVICEFILE'] = os.path.join(
- fixture_dir, 'mock_pg_service.conf')
-
- if context.conf['pass']:
- os.environ['PGPASSWORD'] = context.conf['pass']
+ os.environ["PGDATABASE"] = context.conf["dbname"]
+ os.environ["PGUSER"] = context.conf["user"]
+ os.environ["PGHOST"] = context.conf["host"]
+ os.environ["PGPORT"] = context.conf["port"]
+ os.environ["PGSERVICEFILE"] = os.path.join(fixture_dir, "mock_pg_service.conf")
+
+ if context.conf["pass"]:
+ os.environ["PGPASSWORD"] = context.conf["pass"]
else:
- if 'PGPASSWORD' in os.environ:
- del os.environ['PGPASSWORD']
+ if "PGPASSWORD" in os.environ:
+ del os.environ["PGPASSWORD"]
- context.cn = dbutils.create_db(context.conf['host'], context.conf['user'],
- context.conf['pass'], context.conf['dbname'],
- context.conf['port'])
+ context.cn = dbutils.create_db(
+ context.conf["host"],
+ context.conf["user"],
+ context.conf["pass"],
+ context.conf["dbname"],
+ context.conf["port"],
+ )
context.fixture_data = fixutils.read_fixture_files()
# use temporary directory as config home
- context.env_config_home = tempfile.mkdtemp(prefix='pgcli_home_')
- os.environ['XDG_CONFIG_HOME'] = context.env_config_home
+ context.env_config_home = tempfile.mkdtemp(prefix="pgcli_home_")
+ os.environ["XDG_CONFIG_HOME"] = context.env_config_home
show_env_changes(env_old, dict(os.environ))
def show_env_changes(env_old, env_new):
"""Print out all test-specific env values."""
- print('--- os.environ changed values: ---')
+ print ("--- os.environ changed values: ---")
all_keys = set(list(env_old.keys()) + list(env_new.keys()))
for k in sorted(all_keys):
- old_value = env_old.get(k, '')
- new_value = env_new.get(k, '')
+ old_value = env_old.get(k, "")
+ new_value = env_new.get(k, "")
if new_value and old_value != new_value:
- print('{}="{}"'.format(k, new_value))
- print('-' * 20)
+ print ('{}="{}"'.format(k, new_value))
+ print ("-" * 20)
def after_all(context):
@@ -132,9 +138,13 @@ def after_all(context):
Unset env parameters.
"""
dbutils.close_cn(context.cn)
- dbutils.drop_db(context.conf['host'], context.conf['user'],
- context.conf['pass'], context.conf['dbname'],
- context.conf['port'])
+ dbutils.drop_db(
+ context.conf["host"],
+ context.conf["user"],
+ context.conf["pass"],
+ context.conf["dbname"],
+ context.conf["port"],
+ )
# Remove temp config direcotry
shutil.rmtree(context.env_config_home)
@@ -152,7 +162,7 @@ def before_step(context, _):
def before_scenario(context, scenario):
- if scenario.name == 'list databases':
+ if scenario.name == "list databases":
# not using the cli for that
return
wrappers.run_cli(context)
@@ -161,19 +171,19 @@ def before_scenario(context, scenario):
def after_scenario(context, scenario):
"""Cleans up after each scenario completes."""
- if hasattr(context, 'cli') and 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=15)
- context.cli.sendcontrol('c')
- context.cli.sendcontrol('d')
+ context.cli.expect_exact("{0}> ".format(dbname), timeout=15)
+ context.cli.sendcontrol("c")
+ context.cli.sendcontrol("d")
try:
context.cli.expect_exact(pexpect.EOF, timeout=15)
except pexpect.TIMEOUT:
- print('--- after_scenario {}: kill cli'.format(scenario.name))
+ print ("--- after_scenario {}: kill cli".format(scenario.name))
context.cli.kill(signal.SIGKILL)
- if hasattr(context, 'tmpfile_sql_help') and context.tmpfile_sql_help:
+ 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/fixture_utils.py b/tests/features/fixture_utils.py
index af10596a..6cb74b2d 100644
--- a/tests/features/fixture_utils.py
+++ b/tests/features/fixture_utils.py
@@ -13,7 +13,7 @@ def read_fixture_lines(filename):
:return: list of strings
"""
lines = []
- for line in codecs.open(filename, 'rb', encoding='utf-8'):
+ for line in codecs.open(filename, "rb", encoding="utf-8"):
lines.append(line.strip())
return lines
@@ -21,11 +21,11 @@ def read_fixture_lines(filename):
def read_fixture_files():
"""Read all files inside fixture_data directory."""
current_dir = os.path.dirname(__file__)
- fixture_dir = os.path.join(current_dir, 'fixture_data/')
- print('reading fixture data: {}'.format(fixture_dir))
+ fixture_dir = os.path.join(current_dir, "fixture_data/")
+ print ("reading fixture data: {}".format(fixture_dir))
fixture_dict = {}
for filename in os.listdir(fixture_dir):
- if filename not in ['.', '..']:
+ if filename not in [".", ".."]:
fullname = os.path.join(fixture_dir, filename)
fixture_dict[filename] = read_fixture_lines(fullname)
diff --git a/tests/features/steps/auto_vertical.py b/tests/features/steps/auto_vertical.py
index 18a51faf..2bb89870 100644
--- a/tests/features/steps/auto_vertical.py
+++ b/tests/features/steps/auto_vertical.py
@@ -6,37 +6,45 @@ from behave import then, when
import wrappers
-@when('we run dbcli with {arg}')
+@when("we run dbcli with {arg}")
def step_run_cli_with_arg(context, arg):
- wrappers.run_cli(context, run_args=arg.split('='))
+ wrappers.run_cli(context, run_args=arg.split("="))
-@when('we execute a small query')
+@when("we execute a small query")
def step_execute_small_query(context):
- context.cli.sendline('select 1')
+ context.cli.sendline("select 1")
-@when('we execute a large query')
+@when("we execute a large query")
def step_execute_large_query(context):
- context.cli.sendline(
- 'select {}'.format(','.join([str(n) for n in range(1, 50)])))
+ context.cli.sendline("select {}".format(",".join([str(n) for n in range(1, 50)])))
-@then('we see small results in horizontal format')
+@then("we see small results in horizontal format")
def step_see_small_results(context):
- wrappers.expect_pager(context, dedent("""\
+ wrappers.expect_pager(
+ context,
+ dedent(
+ """\
+------------+\r
| ?column? |\r
|------------|\r
| 1 |\r
+------------+\r
SELECT 1\r
- """), timeout=5)
+ """
+ ),
+ timeout=5,
+ )
-@then('we see large results in vertical format')
+@then("we see large results in vertical format")
def step_see_large_results(context):
- wrappers.expect_pager(context, dedent("""\
+ wrappers.expect_pager(
+ context,
+ dedent(
+ """\
-[ RECORD 1 ]-------------------------\r
?column? | 1\r
?column? | 2\r
@@ -88,4 +96,7 @@ def step_see_large_results(context):
?column? | 48\r
?column? | 49\r
SELECT 1\r
- """), timeout=5)
+ """
+ ),
+ timeout=5,
+ )
diff --git a/tests/features/steps/basic_commands.py b/tests/features/steps/basic_commands.py
index 71b591a0..b9ab0046 100644
--- a/tests/features/steps/basic_commands.py
+++ b/tests/features/steps/basic_commands.py
@@ -15,47 +15,48 @@ from textwrap import dedent
import wrappers
-@when('we list databases')
+@when("we list databases")
def step_list_databases(context):
- cmd = ['pgcli', '--list']
+ cmd = ["pgcli", "--list"]
context.cmd_output = subprocess.check_output(cmd, cwd=context.package_root)
-@then('we see list of databases')
+@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
+ assert b"List of databases" in context.cmd_output
+ assert b"postgres" in context.cmd_output
context.cmd_output = None
-@when('we run dbcli')
+@when("we run dbcli")
def step_run_cli(context):
wrappers.run_cli(context)
-@when('we launch dbcli using {arg}')
+@when("we launch dbcli using {arg}")
def step_run_cli_using_arg(context, arg):
prompt_check = False
currentdb = None
- if arg == '--username':
- arg = '--username={}'.format(context.conf['user'])
- if arg == '--user':
- arg = '--user={}'.format(context.conf['user'])
- if arg == '--port':
- arg = '--port={}'.format(context.conf['port'])
- if arg == '--password':
- arg = '--password'
+ if arg == "--username":
+ arg = "--username={}".format(context.conf["user"])
+ if arg == "--user":
+ arg = "--user={}".format(context.conf["user"])
+ if arg == "--port":
+ arg = "--port={}".format(context.conf["port"])
+ if arg == "--password":
+ arg = "--password"
prompt_check = False
# This uses the mock_pg_service.conf file in fixtures folder.
- if arg == 'dsn_password':
- arg = 'service=mock_postgres --password'
+ if arg == "dsn_password":
+ arg = "service=mock_postgres --password"
prompt_check = False
currentdb = "postgres"
- wrappers.run_cli(context, run_args=[
- arg], prompt_check=prompt_check, currentdb=currentdb)
+ wrappers.run_cli(
+ context, run_args=[arg], prompt_check=prompt_check, currentdb=currentdb
+ )
-@when('we wait for prompt')
+@when("we wait for prompt")
def step_wait_prompt(context):
wrappers.wait_prompt(context)
@@ -66,9 +67,9 @@ def step_ctrl_d(context):
Send Ctrl + D to hopefully exit.
"""
# turn off pager before exiting
- context.cli.sendline('\pset pager off')
+ context.cli.sendline("\pset pager off")
wrappers.wait_prompt(context)
- context.cli.sendcontrol('d')
+ context.cli.sendcontrol("d")
context.cli.expect_exact(pexpect.EOF, timeout=15)
context.exit_sent = True
@@ -78,51 +79,58 @@ def step_send_help(context):
"""
Send \? to see help.
"""
- context.cli.sendline('\?')
+ context.cli.sendline("\?")
-@when(u'we send source command')
+@when("we send source command")
def step_send_source_command(context):
- context.tmpfile_sql_help = tempfile.NamedTemporaryFile(prefix='pgcli_')
- context.tmpfile_sql_help.write(b'\?')
+ context.tmpfile_sql_help = tempfile.NamedTemporaryFile(prefix="pgcli_")
+ context.tmpfile_sql_help.write(b"\?")
context.tmpfile_sql_help.flush()
- context.cli.sendline('\i {0}'.format(context.tmpfile_sql_help.name))
- wrappers.expect_exact(
- context, context.conf['pager_boundary'] + '\r\n', timeout=5)
+ context.cli.sendline("\i {0}".format(context.tmpfile_sql_help.name))
+ wrappers.expect_exact(context, context.conf["pager_boundary"] + "\r\n", timeout=5)
-@when(u'we run query to check application_name')
+@when("we run query to check application_name")
def step_check_application_name(context):
context.cli.sendline(
"SELECT 'found' FROM pg_stat_activity WHERE application_name = 'pgcli' HAVING COUNT(*) > 0;"
)
-@then(u'we see found')
+@then("we see found")
def step_see_found(context):
wrappers.expect_exact(
context,
- context.conf['pager_boundary'] + '\r' + dedent('''
+ context.conf["pager_boundary"]
+ + "\r"
+ + dedent(
+ """
+------------+\r
| ?column? |\r
|------------|\r
| found |\r
+------------+\r
SELECT 1\r
- ''') + context.conf['pager_boundary'],
- timeout=5
+ """
+ )
+ + context.conf["pager_boundary"],
+ timeout=5,
)
-@then(u'we confirm the destructive warning')
+@then("we confirm the destructive warning")
def step_confirm_destructive_command(context):
"""Confirm destructive command."""
wrappers.expect_exact(
- context, 'You\'re about to run a destructive command.\r\nDo you want to proceed? (y/n):', timeout=2)
- context.cli.sendline('y')
+ context,
+ "You're about to run a destructive command.\r\nDo you want to proceed? (y/n):",
+ timeout=2,
+ )
+ context.cli.sendline("y")
-@then(u'we send password')
+@then("we send password")
def step_send_password(context):
- wrappers.expect_exact(context, 'Password for', timeout=5)
- context.cli.sendline(context.conf['pass'] or 'DOES NOT MATTER')
+ wrappers.expect_exact(context, "Password for", timeout=5)
+ context.cli.sendline(context.conf["pass"] or "DOES NOT MATTER")
diff --git a/tests/features/steps/crud_database.py b/tests/features/steps/crud_database.py
index 3ec27c96..9eab4f45 100644
--- a/tests/features/steps/crud_database.py
+++ b/tests/features/steps/crud_database.py
@@ -12,47 +12,43 @@ from behave import when, then
import wrappers
-@when('we create database')
+@when("we create database")
def step_db_create(context):
"""
Send create database.
"""
- context.cli.sendline('create database {0};'.format(
- context.conf['dbname_tmp']))
+ context.cli.sendline("create database {0};".format(context.conf["dbname_tmp"]))
- context.response = {
- 'database_name': context.conf['dbname_tmp']
- }
+ context.response = {"database_name": context.conf["dbname_tmp"]}
-@when('we drop database')
+@when("we drop database")
def step_db_drop(context):
"""
Send drop database.
"""
- context.cli.sendline('drop database {0};'.format(
- context.conf['dbname_tmp']))
+ context.cli.sendline("drop database {0};".format(context.conf["dbname_tmp"]))
-@when('we connect to test database')
+@when("we connect to test database")
def step_db_connect_test(context):
"""
Send connect to database.
"""
- db_name = context.conf['dbname']
- context.cli.sendline('\\connect {0}'.format(db_name))
+ db_name = context.conf["dbname"]
+ context.cli.sendline("\\connect {0}".format(db_name))
-@when('we connect to dbserver')
+@when("we connect to dbserver")
def step_db_connect_dbserver(context):
"""
Send connect to database.
"""
- context.cli.sendline('\\connect postgres')
- context.currentdb = 'postgres'
+ context.cli.sendline("\\connect postgres")
+ context.currentdb = "postgres"
-@then('dbcli exits')
+@then("dbcli exits")
def step_wait_exit(context):
"""
Make sure the cli exits.
@@ -60,41 +56,41 @@ def step_wait_exit(context):
wrappers.expect_exact(context, pexpect.EOF, timeout=5)
-@then('we see dbcli prompt')
+@then("we see dbcli prompt")
def step_see_prompt(context):
"""
Wait to see the prompt.
"""
- db_name = getattr(context, "currentdb", context.conf['dbname'])
- wrappers.expect_exact(context, '{0}> '.format(db_name), timeout=5)
+ db_name = getattr(context, "currentdb", context.conf["dbname"])
+ wrappers.expect_exact(context, "{0}> ".format(db_name), timeout=5)
context.atprompt = True
-@then('we see help output')
+@then("we see help output")
def step_see_help(context):
- for expected_line in context.fixture_data['help_commands.txt']:
+ for expected_line in context.fixture_data["help_commands.txt"]:
wrappers.expect_exact(context, expected_line, timeout=2)
-@then('we see database created')
+@then("we see database created")
def step_see_db_created(context):
"""
Wait to see create database output.
"""
- wrappers.expect_pager(context, 'CREATE DATABASE\r\n', timeout=5)
+ wrappers.expect_pager(context, "CREATE DATABASE\r\n", timeout=5)
-@then('we see database dropped')
+@then("we see database dropped")
def step_see_db_dropped(context):
"""
Wait to see drop database output.
"""
- wrappers.expect_pager(context, 'DROP DATABASE\r\n', timeout=2)
+ wrappers.expect_pager(context, "DROP DATABASE\r\n", timeout=2)
-@then('we see database connected')
+@then("we see database connected")
def step_see_db_connected(context):
"""
Wait to see drop database output.
"""
- wrappers.expect_exact(context, 'You are now connected to database', timeout=2)