diff options
author | bjornasm <bjornasm@gmail.com> | 2023-05-11 12:53:17 +0200 |
---|---|---|
committer | bjornasm <bjornasm@gmail.com> | 2023-05-11 12:53:17 +0200 |
commit | c32f424571fad361b1681d3aa19faae16d255c05 (patch) | |
tree | b9ddb41aad05de64894461b0661f95be3ded0912 | |
parent | 6c204e06dc789dc62341f31c931f5ac32d095f2d (diff) |
Added simple tests and refactored sqlitedotcommand
-rw-r--r-- | litecli/packages/special/utils.py | 10 | ||||
-rw-r--r-- | litecli/sqlexecute.py | 3 | ||||
-rw-r--r-- | tests/test_dbspecial.py | 13 | ||||
-rw-r--r-- | tests/test_main.py | 7 |
4 files changed, 29 insertions, 4 deletions
diff --git a/litecli/packages/special/utils.py b/litecli/packages/special/utils.py index ae45597..d9e45b5 100644 --- a/litecli/packages/special/utils.py +++ b/litecli/packages/special/utils.py @@ -51,8 +51,14 @@ def format_uptime(uptime_in_seconds): def check_if_sqlitedotcommand(command): """Does a check if the command supplied is in the list of SQLite dot commands. - :param command: A command supplied from the user + :param command: A command (str) supplied from the user :returns: True/False """ + sqlite3dotcommands = ['.archive','.auth','.backup','.bail','.binary','.cd','.changes','.check','.clone','.connection','.databases','.dbconfig','.dbinfo','.dump','.echo','.eqp','.excel','.exit','.expert','.explain','.filectrl','.fullschema','.headers','.help','.import','.imposter','.indexes','.limit','.lint','.load','.log','.mode','.nonce','.nullvalue','.once','.open','.output','.parameter','.print','.progress','.prompt','.quit','.read','.recover','.restore','.save','.scanstats','.schema','.selftest','.separator','.session','.sha3sum','.shell','.show','.stats','.system','.tables','.testcase','.testctrl','.timeout','.timer','.trace','.vfsinfo','.vfslist','.vfsname','.width'] - return (command.lower() in sqlite3dotcommands) + + if isinstance(command, str): + command = command.split(' ', 1)[0].lower() + return (command in sqlite3dotcommands) + else: + return False
\ No newline at end of file diff --git a/litecli/sqlexecute.py b/litecli/sqlexecute.py index dd05240..348ee17 100644 --- a/litecli/sqlexecute.py +++ b/litecli/sqlexecute.py @@ -129,8 +129,7 @@ class SQLExecute(object): for result in special.execute(cur, sql): yield result except special.CommandNotFound: # Regular SQL - basecommand = sql.split(' ', 1)[0] - if check_if_sqlitedotcommand(basecommand): + if check_if_sqlitedotcommand(sql): yield ('dot command not implemented', None, None, None) else: _logger.debug("Regular sql statement. sql: %r", sql) diff --git a/tests/test_dbspecial.py b/tests/test_dbspecial.py index 5128b5b..7c561b2 100644 --- a/tests/test_dbspecial.py +++ b/tests/test_dbspecial.py @@ -1,6 +1,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 def test_import_first_argument(): @@ -74,3 +75,15 @@ def test_indexes(): {"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
\ No newline at end of file diff --git a/tests/test_main.py b/tests/test_main.py index d4d52af..1f9fe85 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -260,3 +260,10 @@ def test_import_command(executor): """ assert result.exit_code == 0 assert expected in "".join(result.output) + + +def test_startup_commands(executor): + m = LiteCli(liteclirc=default_config_file) + assert m.startup_commands['commands'] == ['create table startupcommands(a text)', "insert into startupcommands values('abc')"] + + # implement tests on executions of the startupcommands
\ No newline at end of file |