summaryrefslogtreecommitdiffstats
path: root/tests/features
diff options
context:
space:
mode:
Diffstat (limited to 'tests/features')
-rw-r--r--tests/features/db_utils.py4
-rw-r--r--tests/features/environment.py13
-rw-r--r--tests/features/fixture_utils.py2
-rw-r--r--tests/features/steps/basic_commands.py13
-rw-r--r--tests/features/steps/crud_database.py8
-rw-r--r--tests/features/steps/expanded.py2
-rw-r--r--tests/features/steps/iocommands.py6
-rw-r--r--tests/features/steps/specials.py7
-rw-r--r--tests/features/steps/wrappers.py10
-rw-r--r--[-rwxr-xr-x]tests/features/wrappager.py0
10 files changed, 39 insertions, 26 deletions
diff --git a/tests/features/db_utils.py b/tests/features/db_utils.py
index f57bc3b..6898394 100644
--- a/tests/features/db_utils.py
+++ b/tests/features/db_utils.py
@@ -44,7 +44,7 @@ def create_cn(hostname, password, username, dbname, port):
host=hostname, user=username, database=dbname, password=password, port=port
)
- print("Created connection: {0}.".format(cn.dsn))
+ print(f"Created connection: {cn.dsn}.")
return cn
@@ -75,4 +75,4 @@ def close_cn(cn=None):
"""
if cn:
cn.close()
- print("Closed connection: {0}.".format(cn.dsn))
+ print(f"Closed connection: {cn.dsn}.")
diff --git a/tests/features/environment.py b/tests/features/environment.py
index 049c2f2..215c85c 100644
--- a/tests/features/environment.py
+++ b/tests/features/environment.py
@@ -38,7 +38,7 @@ def before_all(context):
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)
+ db_name_full = f"{db_name}_{vi}"
# Store get params from config.
context.conf = {
@@ -63,7 +63,7 @@ def before_all(context):
"import coverage",
"coverage.process_startup()",
"import pgcli.main",
- "pgcli.main.cli()",
+ "pgcli.main.cli(auto_envvar_prefix='BEHAVE')",
]
),
)
@@ -102,6 +102,7 @@ def before_all(context):
else:
if "PGPASSWORD" in os.environ:
del os.environ["PGPASSWORD"]
+ os.environ["BEHAVE_WARN"] = "moderate"
context.cn = dbutils.create_db(
context.conf["host"],
@@ -122,12 +123,12 @@ def before_all(context):
def show_env_changes(env_old, env_new):
"""Print out all test-specific env values."""
print("--- os.environ changed values: ---")
- all_keys = set(list(env_old.keys()) + list(env_new.keys()))
+ all_keys = env_old.keys() | env_new.keys()
for k in sorted(all_keys):
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(f'{k}="{new_value}"')
print("-" * 20)
@@ -173,13 +174,13 @@ def after_scenario(context, scenario):
# Quit nicely.
if not context.atprompt:
dbname = context.currentdb
- context.cli.expect_exact("{0}> ".format(dbname), timeout=15)
+ context.cli.expect_exact(f"{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(f"--- after_scenario {scenario.name}: kill cli")
context.cli.kill(signal.SIGKILL)
if hasattr(context, "tmpfile_sql_help") and context.tmpfile_sql_help:
context.tmpfile_sql_help.close()
diff --git a/tests/features/fixture_utils.py b/tests/features/fixture_utils.py
index 16f123a..70b603d 100644
--- a/tests/features/fixture_utils.py
+++ b/tests/features/fixture_utils.py
@@ -18,7 +18,7 @@ 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))
+ print(f"reading fixture data: {fixture_dir}")
fixture_dict = {}
for filename in os.listdir(fixture_dir):
if filename not in [".", ".."]:
diff --git a/tests/features/steps/basic_commands.py b/tests/features/steps/basic_commands.py
index 1069662..07e9ec1 100644
--- a/tests/features/steps/basic_commands.py
+++ b/tests/features/steps/basic_commands.py
@@ -65,19 +65,20 @@ def step_ctrl_d(context):
Send Ctrl + D to hopefully exit.
"""
# turn off pager before exiting
- context.cli.sendline("\pset pager off")
+ context.cli.sendcontrol("c")
+ context.cli.sendline(r"\pset pager off")
wrappers.wait_prompt(context)
context.cli.sendcontrol("d")
context.cli.expect(pexpect.EOF, timeout=15)
context.exit_sent = True
-@when('we send "\?" command')
+@when(r'we send "\?" command')
def step_send_help(context):
- """
+ r"""
Send \? to see help.
"""
- context.cli.sendline("\?")
+ context.cli.sendline(r"\?")
@when("we send partial select command")
@@ -96,9 +97,9 @@ def step_see_error_message(context):
@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.write(br"\?")
context.tmpfile_sql_help.flush()
- context.cli.sendline("\i {0}".format(context.tmpfile_sql_help.name))
+ context.cli.sendline(fr"\i {context.tmpfile_sql_help.name}")
wrappers.expect_exact(context, context.conf["pager_boundary"] + "\r\n", timeout=5)
diff --git a/tests/features/steps/crud_database.py b/tests/features/steps/crud_database.py
index 3fd8b7a..3f5d0e7 100644
--- a/tests/features/steps/crud_database.py
+++ b/tests/features/steps/crud_database.py
@@ -14,7 +14,7 @@ def step_db_create(context):
"""
Send create database.
"""
- context.cli.sendline("create database {0};".format(context.conf["dbname_tmp"]))
+ context.cli.sendline("create database {};".format(context.conf["dbname_tmp"]))
context.response = {"database_name": context.conf["dbname_tmp"]}
@@ -24,7 +24,7 @@ def step_db_drop(context):
"""
Send drop database.
"""
- context.cli.sendline("drop database {0};".format(context.conf["dbname_tmp"]))
+ context.cli.sendline("drop database {};".format(context.conf["dbname_tmp"]))
@when("we connect to test database")
@@ -33,7 +33,7 @@ def step_db_connect_test(context):
Send connect to database.
"""
db_name = context.conf["dbname"]
- context.cli.sendline("\\connect {0}".format(db_name))
+ context.cli.sendline(f"\\connect {db_name}")
@when("we connect to dbserver")
@@ -59,7 +59,7 @@ 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)
+ wrappers.expect_exact(context, f"{db_name}> ", timeout=5)
context.atprompt = True
diff --git a/tests/features/steps/expanded.py b/tests/features/steps/expanded.py
index f34fcf0..265ea39 100644
--- a/tests/features/steps/expanded.py
+++ b/tests/features/steps/expanded.py
@@ -31,7 +31,7 @@ def step_prepare_data(context):
@when("we set expanded {mode}")
def step_set_expanded(context, mode):
"""Set expanded to mode."""
- context.cli.sendline("\\" + "x {}".format(mode))
+ context.cli.sendline("\\" + f"x {mode}")
wrappers.expect_exact(context, "Expanded display is", timeout=2)
wrappers.wait_prompt(context)
diff --git a/tests/features/steps/iocommands.py b/tests/features/steps/iocommands.py
index 613aeb2..a614490 100644
--- a/tests/features/steps/iocommands.py
+++ b/tests/features/steps/iocommands.py
@@ -13,7 +13,7 @@ def step_edit_file(context):
)
if os.path.exists(context.editor_file_name):
os.remove(context.editor_file_name)
- context.cli.sendline("\e {0}".format(os.path.basename(context.editor_file_name)))
+ context.cli.sendline(r"\e {}".format(os.path.basename(context.editor_file_name)))
wrappers.expect_exact(
context, 'Entering Ex mode. Type "visual" to go to Normal mode.', timeout=2
)
@@ -53,7 +53,7 @@ def step_tee_ouptut(context):
)
if os.path.exists(context.tee_file_name):
os.remove(context.tee_file_name)
- context.cli.sendline("\o {0}".format(os.path.basename(context.tee_file_name)))
+ context.cli.sendline(r"\o {}".format(os.path.basename(context.tee_file_name)))
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)
@@ -67,7 +67,7 @@ def step_query_select_123456(context):
@when("we stop teeing output")
def step_notee_output(context):
- context.cli.sendline("\o")
+ context.cli.sendline(r"\o")
wrappers.expect_exact(context, "Time", timeout=5)
diff --git a/tests/features/steps/specials.py b/tests/features/steps/specials.py
index 813292c..a85f371 100644
--- a/tests/features/steps/specials.py
+++ b/tests/features/steps/specials.py
@@ -22,5 +22,10 @@ def step_see_refresh_started(context):
Wait to see refresh output.
"""
wrappers.expect_pager(
- context, "Auto-completion refresh started in the background.\r\n", timeout=2
+ context,
+ [
+ "Auto-completion refresh started in the background.\r\n",
+ "Auto-completion refresh restarted.\r\n",
+ ],
+ timeout=2,
)
diff --git a/tests/features/steps/wrappers.py b/tests/features/steps/wrappers.py
index e0f5a20..0ca8366 100644
--- a/tests/features/steps/wrappers.py
+++ b/tests/features/steps/wrappers.py
@@ -39,9 +39,15 @@ def expect_exact(context, expected, timeout):
def expect_pager(context, expected, timeout):
+ formatted = expected if isinstance(expected, list) else [expected]
+ formatted = [
+ f"{context.conf['pager_boundary']}\r\n{t}{context.conf['pager_boundary']}\r\n"
+ for t in formatted
+ ]
+
expect_exact(
context,
- "{0}\r\n{1}{0}\r\n".format(context.conf["pager_boundary"], expected),
+ formatted,
timeout=timeout,
)
@@ -57,7 +63,7 @@ def run_cli(context, run_args=None, prompt_check=True, currentdb=None):
context.cli.logfile = context.logfile
context.exit_sent = False
context.currentdb = currentdb or context.conf["dbname"]
- context.cli.sendline("\pset pager always")
+ context.cli.sendline(r"\pset pager always")
if prompt_check:
wait_prompt(context)
diff --git a/tests/features/wrappager.py b/tests/features/wrappager.py
index 51d4909..51d4909 100755..100644
--- a/tests/features/wrappager.py
+++ b/tests/features/wrappager.py