1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
# mypy: ignore-errors
from test_completion_engine import sorted_dicts
from utils import assert_result_equal, dbtest, run
from litecli.packages.completion_engine import suggest_type
from litecli.packages.special.utils import check_if_sqlitedotcommand, format_uptime
def test_import_first_argument():
test_cases = [
# text, expecting_arg_idx
[".import ", 1],
[".import ./da", 1],
[".import ./data.csv ", 2],
[".import ./data.csv t", 2],
[".import ./data.csv `t", 2],
['.import ./data.csv "t', 2],
]
for text, expecting_arg_idx in test_cases:
suggestions = suggest_type(text, text)
if expecting_arg_idx == 1:
assert suggestions == [{"type": "file_name"}]
else:
assert suggestions == [{"type": "table", "schema": []}]
def test_u_suggests_databases():
suggestions = suggest_type("\\u ", "\\u ")
assert sorted_dicts(suggestions) == sorted_dicts([{"type": "database"}])
def test_describe_table():
suggestions = suggest_type("\\dt", "\\dt ")
assert sorted_dicts(suggestions) == sorted_dicts(
[
{"type": "table", "schema": []},
{"type": "view", "schema": []},
{"type": "schema"},
]
)
def test_list_or_show_create_tables():
suggestions = suggest_type("\\dt+", "\\dt+ ")
assert sorted_dicts(suggestions) == sorted_dicts(
[
{"type": "table", "schema": []},
{"type": "view", "schema": []},
{"type": "schema"},
]
)
def test_format_uptime():
seconds = 59
assert "59 sec" == format_uptime(seconds)
seconds = 120
assert "2 min 0 sec" == format_uptime(seconds)
seconds = 54890
assert "15 hours 14 min 50 sec" == format_uptime(seconds)
seconds = 598244
assert "6 days 22 hours 10 min 44 sec" == format_uptime(seconds)
seconds = 522600
assert "6 days 1 hour 10 min 0 sec" == format_uptime(seconds)
def test_indexes():
suggestions = suggest_type(".indexes", ".indexes ")
assert sorted_dicts(suggestions) == sorted_dicts(
[
{"type": "table", "schema": []},
{"type": "view", "schema": []},
{"type": "schema"},
]
)
def test_check_if_sqlitedotcommand():
test_cases = [
[".tables", True],
[".BiNarY", True],
["binary", False],
[234, False],
[".changes test! test", True],
["NotDotcommand", False],
]
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=""
)
|