Skip to content

Commit 71e390a

Browse files
committed
Add a test for the \d special command.
1 parent 3126eeb commit 71e390a

3 files changed

Lines changed: 44 additions & 25 deletions

File tree

tests/test_dbspecial.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from test_completion_engine import sorted_dicts
33
from litecli.packages.special.utils import format_uptime
44
from litecli.packages.special.utils import check_if_sqlitedotcommand
5+
from utils import run, dbtest, assert_result_equal
56

67

78
def test_import_first_argument():
@@ -88,3 +89,21 @@ def test_check_if_sqlitedotcommand():
8889
]
8990
for command, expected_result in test_cases:
9091
assert check_if_sqlitedotcommand(command) == expected_result
92+
93+
94+
@dbtest
95+
def test_special_d(executor):
96+
run(executor, """create table tst_tbl1(a text)""")
97+
results = run(executor, """\\d""")
98+
99+
assert_result_equal(results, headers=["name"], rows=[("tst_tbl1",)], status="")
100+
101+
102+
@dbtest
103+
def test_special_d_w_arg(executor):
104+
run(executor, """create table tst_tbl1(a text)""")
105+
results = run(executor, """\\d tst_tbl1""")
106+
107+
assert_result_equal(
108+
results, headers=["cid", "name", "type", "notnull", "dflt_value", "pk"], rows=[(0, "a", "TEXT", 0, None, 0)], status=""
109+
)

tests/test_sqlexecute.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,10 @@
44

55
import pytest
66

7-
from utils import run, dbtest, set_expanded_output, is_expanded_output
7+
from utils import run, dbtest, set_expanded_output, is_expanded_output, assert_result_equal
88
from sqlite3 import OperationalError, ProgrammingError
99

1010

11-
def assert_result_equal(
12-
result,
13-
title=None,
14-
rows=None,
15-
headers=None,
16-
status=None,
17-
auto_status=True,
18-
assert_contains=False,
19-
):
20-
"""Assert that an sqlexecute.run() result matches the expected values."""
21-
if status is None and auto_status and rows:
22-
status = "{} row{} in set".format(len(rows), "s" if len(rows) > 1 else "")
23-
fields = {"title": title, "rows": rows, "headers": headers, "status": status}
24-
25-
if assert_contains:
26-
# Do a loose match on the results using the *in* operator.
27-
for key, field in fields.items():
28-
if field:
29-
assert field in result[0][key]
30-
else:
31-
# Do an exact match on the fields.
32-
assert result == [fields]
33-
34-
3511
@dbtest
3612
def test_conn(executor):
3713
run(executor, """create table test(a text)""")

tests/utils.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,27 @@ def send_ctrl_c(wait_seconds):
8888
ctrl_c_process = multiprocessing.Process(target=send_ctrl_c_to_pid, args=(os.getpid(), wait_seconds))
8989
ctrl_c_process.start()
9090
return ctrl_c_process
91+
92+
93+
def assert_result_equal(
94+
result,
95+
title=None,
96+
rows=None,
97+
headers=None,
98+
status=None,
99+
auto_status=True,
100+
assert_contains=False,
101+
):
102+
"""Assert that an sqlexecute.run() result matches the expected values."""
103+
if status is None and auto_status and rows:
104+
status = "{} row{} in set".format(len(rows), "s" if len(rows) > 1 else "")
105+
fields = {"title": title, "rows": rows, "headers": headers, "status": status}
106+
107+
if assert_contains:
108+
# Do a loose match on the results using the *in* operator.
109+
for key, field in fields.items():
110+
if field:
111+
assert field in result[0][key]
112+
else:
113+
# Do an exact match on the fields.
114+
assert result == [fields]

0 commit comments

Comments
 (0)