1
0
Fork 0

Merging upstream version 1.12.4.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-09 17:55:47 +01:00
parent 93e5ab7520
commit 7c408cdf3d
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
7 changed files with 71 additions and 66 deletions

View file

@ -2,6 +2,7 @@ from litecli.packages.completion_engine import suggest_type
from test_completion_engine import sorted_dicts
from litecli.packages.special.utils import format_uptime
from litecli.packages.special.utils import check_if_sqlitedotcommand
from utils import run, dbtest, assert_result_equal
def test_import_first_argument():
@ -88,3 +89,21 @@ def test_check_if_sqlitedotcommand():
]
for command, expected_result in test_cases:
assert check_if_sqlitedotcommand(command) == expected_result
@dbtest
def test_special_d(executor):
run(executor, """create table tst_tbl1(a text)""")
results = run(executor, """\\d""")
assert_result_equal(results, headers=["name"], rows=[("tst_tbl1",)], status="")
@dbtest
def test_special_d_w_arg(executor):
run(executor, """create table tst_tbl1(a text)""")
results = run(executor, """\\d tst_tbl1""")
assert_result_equal(
results, headers=["cid", "name", "type", "notnull", "dflt_value", "pk"], rows=[(0, "a", "TEXT", 0, None, 0)], status=""
)

View file

@ -4,34 +4,10 @@ import os
import pytest
from utils import run, dbtest, set_expanded_output, is_expanded_output
from utils import run, dbtest, set_expanded_output, is_expanded_output, assert_result_equal
from sqlite3 import OperationalError, ProgrammingError
def assert_result_equal(
result,
title=None,
rows=None,
headers=None,
status=None,
auto_status=True,
assert_contains=False,
):
"""Assert that an sqlexecute.run() result matches the expected values."""
if status is None and auto_status and rows:
status = "{} row{} in set".format(len(rows), "s" if len(rows) > 1 else "")
fields = {"title": title, "rows": rows, "headers": headers, "status": status}
if assert_contains:
# Do a loose match on the results using the *in* operator.
for key, field in fields.items():
if field:
assert field in result[0][key]
else:
# Do an exact match on the fields.
assert result == [fields]
@dbtest
def test_conn(executor):
run(executor, """create table test(a text)""")

View file

@ -88,3 +88,27 @@ def send_ctrl_c(wait_seconds):
ctrl_c_process = multiprocessing.Process(target=send_ctrl_c_to_pid, args=(os.getpid(), wait_seconds))
ctrl_c_process.start()
return ctrl_c_process
def assert_result_equal(
result,
title=None,
rows=None,
headers=None,
status=None,
auto_status=True,
assert_contains=False,
):
"""Assert that an sqlexecute.run() result matches the expected values."""
if status is None and auto_status and rows:
status = "{} row{} in set".format(len(rows), "s" if len(rows) > 1 else "")
fields = {"title": title, "rows": rows, "headers": headers, "status": status}
if assert_contains:
# Do a loose match on the results using the *in* operator.
for key, field in fields.items():
if field:
assert field in result[0][key]
else:
# Do an exact match on the fields.
assert result == [fields]