summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/liteclirc7
-rw-r--r--tests/test_dbspecial.py14
-rw-r--r--tests/test_main.py10
-rw-r--r--tests/test_smart_completion_public_schema_only.py21
-rw-r--r--tests/test_sqlexecute.py18
5 files changed, 49 insertions, 21 deletions
diff --git a/tests/liteclirc b/tests/liteclirc
index da9b061..21a3ef9 100644
--- a/tests/liteclirc
+++ b/tests/liteclirc
@@ -135,3 +135,10 @@ Token.Toolbar.Arg.Text = nobold
[favorite_queries]
q_param = select * from test where name=?
sh_param = select * from test where id=$1
+
+# Startup commands
+# litecli commands or sqlite commands to be executed on startup.
+# some of them will require you to have a database attached.
+# they will be executed in the same order as they appear in the list.
+[startup_commands]
+commands = "create table startupcommands(a text)", "insert into startupcommands values('abc')"
diff --git a/tests/test_dbspecial.py b/tests/test_dbspecial.py
index 5128b5b..d3c7c07 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,16 @@ 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
diff --git a/tests/test_main.py b/tests/test_main.py
index d4d52af..e2f183a 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -260,3 +260,13 @@ 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
diff --git a/tests/test_smart_completion_public_schema_only.py b/tests/test_smart_completion_public_schema_only.py
index e532118..c8e1be4 100644
--- a/tests/test_smart_completion_public_schema_only.py
+++ b/tests/test_smart_completion_public_schema_only.py
@@ -15,7 +15,6 @@ metadata = {
@pytest.fixture
def completer():
-
import litecli.sqlcompleter as sqlcompleter
comp = sqlcompleter.SQLCompleter()
@@ -367,17 +366,15 @@ def test_auto_escaped_col_names(completer, complete_event):
Document(text=text, cursor_position=position), complete_event
)
)
- assert (
- result
- == [
- Completion(text="*", start_position=0),
- Completion(text="`ABC`", start_position=0),
- Completion(text="`insert`", start_position=0),
- Completion(text="id", start_position=0),
- ]
- + list(map(Completion, completer.functions))
- + [Completion(text="`select`", start_position=0)]
- + list(map(Completion, sorted(completer.keywords)))
+ assert result == [
+ Completion(text="*", start_position=0),
+ Completion(text="`ABC`", start_position=0),
+ Completion(text="`insert`", start_position=0),
+ Completion(text="id", start_position=0),
+ ] + list(map(Completion, completer.functions)) + [
+ Completion(text="select", start_position=0)
+ ] + list(
+ map(Completion, sorted(completer.keywords))
)
diff --git a/tests/test_sqlexecute.py b/tests/test_sqlexecute.py
index e559bc6..16bad74 100644
--- a/tests/test_sqlexecute.py
+++ b/tests/test_sqlexecute.py
@@ -94,11 +94,11 @@ def test_invalid_column_name(executor):
@dbtest
def test_unicode_support_in_output(executor):
run(executor, "create table unicodechars(t text)")
- run(executor, u"insert into unicodechars (t) values ('é')")
+ run(executor, "insert into unicodechars (t) values ('é')")
# See issue #24, this raises an exception without proper handling
- results = run(executor, u"select * from unicodechars")
- assert_result_equal(results, headers=["t"], rows=[(u"é",)])
+ results = run(executor, "select * from unicodechars")
+ assert_result_equal(results, headers=["t"], rows=[("é",)])
@dbtest
@@ -106,9 +106,9 @@ def test_invalid_unicode_values_dont_choke(executor):
run(executor, "create table unicodechars(t text)")
# \xc3 is not a valid utf-8 char. But we can insert it into the database
# which can break querying if not handled correctly.
- run(executor, u"insert into unicodechars (t) values (cast(x'c3' as text))")
+ run(executor, "insert into unicodechars (t) values (cast(x'c3' as text))")
- results = run(executor, u"select * from unicodechars")
+ results = run(executor, "select * from unicodechars")
assert_result_equal(results, headers=["t"], rows=[("\\xc3",)])
@@ -120,13 +120,13 @@ def test_multiple_queries_same_line(executor):
{
"title": None,
"headers": ["'foo'"],
- "rows": [(u"foo",)],
+ "rows": [("foo",)],
"status": "1 row in set",
},
{
"title": None,
"headers": ["'bar'"],
- "rows": [(u"bar",)],
+ "rows": [("bar",)],
"status": "1 row in set",
},
]
@@ -369,8 +369,8 @@ def test_cd_command_current_dir(executor):
@dbtest
def test_unicode_support(executor):
- results = run(executor, u"SELECT '日本語' AS japanese;")
- assert_result_equal(results, headers=["japanese"], rows=[(u"日本語",)])
+ results = run(executor, "SELECT '日本語' AS japanese;")
+ assert_result_equal(results, headers=["japanese"], rows=[("日本語",)])
@dbtest