1from litecli.packages.completion_engine import suggest_type 2from test_completion_engine import sorted_dicts 3from litecli.packages.special.utils import format_uptime 4 5 6def test_import_first_argument(): 7 test_cases = [ 8 # text, expecting_arg_idx 9 [".import ", 1], 10 [".import ./da", 1], 11 [".import ./data.csv ", 2], 12 [".import ./data.csv t", 2], 13 [".import ./data.csv `t", 2], 14 ['.import ./data.csv "t', 2], 15 ] 16 for text, expecting_arg_idx in test_cases: 17 suggestions = suggest_type(text, text) 18 if expecting_arg_idx == 1: 19 assert suggestions == [{"type": "file_name"}] 20 else: 21 assert suggestions == [{"type": "table", "schema": []}] 22 23 24def test_u_suggests_databases(): 25 suggestions = suggest_type("\\u ", "\\u ") 26 assert sorted_dicts(suggestions) == sorted_dicts([{"type": "database"}]) 27 28 29def test_describe_table(): 30 suggestions = suggest_type("\\dt", "\\dt ") 31 assert sorted_dicts(suggestions) == sorted_dicts( 32 [ 33 {"type": "table", "schema": []}, 34 {"type": "view", "schema": []}, 35 {"type": "schema"}, 36 ] 37 ) 38 39 40def test_list_or_show_create_tables(): 41 suggestions = suggest_type("\\dt+", "\\dt+ ") 42 assert sorted_dicts(suggestions) == sorted_dicts( 43 [ 44 {"type": "table", "schema": []}, 45 {"type": "view", "schema": []}, 46 {"type": "schema"}, 47 ] 48 ) 49 50 51def test_format_uptime(): 52 seconds = 59 53 assert "59 sec" == format_uptime(seconds) 54 55 seconds = 120 56 assert "2 min 0 sec" == format_uptime(seconds) 57 58 seconds = 54890 59 assert "15 hours 14 min 50 sec" == format_uptime(seconds) 60 61 seconds = 598244 62 assert "6 days 22 hours 10 min 44 sec" == format_uptime(seconds) 63 64 seconds = 522600 65 assert "6 days 1 hour 10 min 0 sec" == format_uptime(seconds) 66