summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/conftest.py2
-rw-r--r--tests/liteclirc7
-rw-r--r--tests/test_clistyle.py1
-rw-r--r--tests/test_completion_engine.py64
-rw-r--r--tests/test_completion_refresher.py2
-rw-r--r--tests/test_main.py5
-rw-r--r--tests/test_smart_completion_public_schema_only.py126
-rw-r--r--tests/test_sqlexecute.py7
-rw-r--r--tests/utils.py20
9 files changed, 55 insertions, 179 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index dce0d7e..c6524ca 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -6,7 +6,7 @@ from utils import create_db, db_connection, drop_tables
import litecli.sqlexecute
-@pytest.yield_fixture(scope="function")
+@pytest.fixture(scope="function")
def connection():
create_db("_test_db")
connection = db_connection("_test_db")
diff --git a/tests/liteclirc b/tests/liteclirc
index 21a3ef9..91f7df9 100644
--- a/tests/liteclirc
+++ b/tests/liteclirc
@@ -135,10 +135,5 @@ 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')"
+commands = create table startupcommands(a text), insert into startupcommands values('abc')
diff --git a/tests/test_clistyle.py b/tests/test_clistyle.py
index c1177de..b2b0b92 100644
--- a/tests/test_clistyle.py
+++ b/tests/test_clistyle.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
"""Test the litecli.clistyle module."""
+
import pytest
from pygments.style import Style
diff --git a/tests/test_completion_engine.py b/tests/test_completion_engine.py
index 760f275..b04e184 100644
--- a/tests/test_completion_engine.py
+++ b/tests/test_completion_engine.py
@@ -32,9 +32,7 @@ def test_select_suggests_cols_with_qualified_table_scope():
def test_order_by_suggests_cols_with_qualified_table_scope():
- suggestions = suggest_type(
- "SELECT * FROM sch.tabl ORDER BY ", "SELECT * FROM sch.tabl ORDER BY "
- )
+ suggestions = suggest_type("SELECT * FROM sch.tabl ORDER BY ", "SELECT * FROM sch.tabl ORDER BY ")
assert sorted_dicts(suggestions) == sorted_dicts(
[
{"type": "column", "tables": [("sch", "tabl", None)]},
@@ -109,9 +107,7 @@ def test_operand_inside_function_suggests_cols1():
def test_operand_inside_function_suggests_cols2():
- suggestion = suggest_type(
- "SELECT MAX(col1 + col2 + FROM tbl", "SELECT MAX(col1 + col2 + "
- )
+ suggestion = suggest_type("SELECT MAX(col1 + col2 + FROM tbl", "SELECT MAX(col1 + col2 + ")
assert suggestion == [{"type": "column", "tables": [(None, "tbl", None)]}]
@@ -166,23 +162,17 @@ def test_expression_suggests_tables_views_and_schemas(expression):
)
def test_expression_suggests_qualified_tables_views_and_schemas(expression):
suggestions = suggest_type(expression, expression)
- assert sorted_dicts(suggestions) == sorted_dicts(
- [{"type": "table", "schema": "sch"}, {"type": "view", "schema": "sch"}]
- )
+ assert sorted_dicts(suggestions) == sorted_dicts([{"type": "table", "schema": "sch"}, {"type": "view", "schema": "sch"}])
def test_truncate_suggests_tables_and_schemas():
suggestions = suggest_type("TRUNCATE ", "TRUNCATE ")
- assert sorted_dicts(suggestions) == sorted_dicts(
- [{"type": "table", "schema": []}, {"type": "schema"}]
- )
+ assert sorted_dicts(suggestions) == sorted_dicts([{"type": "table", "schema": []}, {"type": "schema"}])
def test_truncate_suggests_qualified_tables():
suggestions = suggest_type("TRUNCATE sch.", "TRUNCATE sch.")
- assert sorted_dicts(suggestions) == sorted_dicts(
- [{"type": "table", "schema": "sch"}]
- )
+ assert sorted_dicts(suggestions) == sorted_dicts([{"type": "table", "schema": "sch"}])
def test_distinct_suggests_cols():
@@ -240,9 +230,7 @@ def test_insert_into_lparen_comma_suggests_cols():
def test_partially_typed_col_name_suggests_col_names():
- suggestions = suggest_type(
- "SELECT * FROM tabl WHERE col_n", "SELECT * FROM tabl WHERE col_n"
- )
+ suggestions = suggest_type("SELECT * FROM tabl WHERE col_n", "SELECT * FROM tabl WHERE col_n")
assert sorted_dicts(suggestions) == sorted_dicts(
[
{"type": "alias", "aliases": ["tabl"]},
@@ -278,9 +266,7 @@ def test_dot_suggests_cols_of_an_alias():
def test_dot_col_comma_suggests_cols_or_schema_qualified_table():
- suggestions = suggest_type(
- "SELECT t1.a, t2. FROM tabl1 t1, tabl2 t2", "SELECT t1.a, t2."
- )
+ suggestions = suggest_type("SELECT t1.a, t2. FROM tabl1 t1, tabl2 t2", "SELECT t1.a, t2.")
assert sorted_dicts(suggestions) == sorted_dicts(
[
{"type": "column", "tables": [(None, "tabl2", "t2")]},
@@ -349,9 +335,7 @@ def test_sub_select_table_name_completion(expression):
def test_sub_select_col_name_completion():
- suggestions = suggest_type(
- "SELECT * FROM (SELECT FROM abc", "SELECT * FROM (SELECT "
- )
+ suggestions = suggest_type("SELECT * FROM (SELECT FROM abc", "SELECT * FROM (SELECT ")
assert sorted_dicts(suggestions) == sorted_dicts(
[
{"type": "alias", "aliases": ["abc"]},
@@ -364,9 +348,7 @@ def test_sub_select_col_name_completion():
@pytest.mark.xfail
def test_sub_select_multiple_col_name_completion():
- suggestions = suggest_type(
- "SELECT * FROM (SELECT a, FROM abc", "SELECT * FROM (SELECT a, "
- )
+ suggestions = suggest_type("SELECT * FROM (SELECT a, FROM abc", "SELECT * FROM (SELECT a, ")
assert sorted_dicts(suggestions) == sorted_dicts(
[
{"type": "column", "tables": [(None, "abc", None)]},
@@ -376,9 +358,7 @@ def test_sub_select_multiple_col_name_completion():
def test_sub_select_dot_col_name_completion():
- suggestions = suggest_type(
- "SELECT * FROM (SELECT t. FROM tabl t", "SELECT * FROM (SELECT t."
- )
+ suggestions = suggest_type("SELECT * FROM (SELECT t. FROM tabl t", "SELECT * FROM (SELECT t.")
assert sorted_dicts(suggestions) == sorted_dicts(
[
{"type": "column", "tables": [(None, "tabl", "t")]},
@@ -502,9 +482,7 @@ def test_join_using_suggests_common_columns(col_list):
def test_2_statements_2nd_current():
- suggestions = suggest_type(
- "select * from a; select * from ", "select * from a; select * from "
- )
+ suggestions = suggest_type("select * from a; select * from ", "select * from a; select * from ")
assert sorted_dicts(suggestions) == sorted_dicts(
[
{"type": "table", "schema": []},
@@ -513,9 +491,7 @@ def test_2_statements_2nd_current():
]
)
- suggestions = suggest_type(
- "select * from a; select from b", "select * from a; select "
- )
+ suggestions = suggest_type("select * from a; select from b", "select * from a; select ")
assert sorted_dicts(suggestions) == sorted_dicts(
[
{"type": "alias", "aliases": ["b"]},
@@ -526,9 +502,7 @@ def test_2_statements_2nd_current():
)
# Should work even if first statement is invalid
- suggestions = suggest_type(
- "select * from; select * from ", "select * from; select * from "
- )
+ suggestions = suggest_type("select * from; select * from ", "select * from; select * from ")
assert sorted_dicts(suggestions) == sorted_dicts(
[
{"type": "table", "schema": []},
@@ -572,9 +546,7 @@ def test_3_statements_2nd_current():
]
)
- suggestions = suggest_type(
- "select * from a; select from b; select * from c", "select * from a; select "
- )
+ suggestions = suggest_type("select * from a; select from b; select * from c", "select * from a; select ")
assert sorted_dicts(suggestions) == sorted_dicts(
[
{"type": "alias", "aliases": ["b"]},
@@ -586,9 +558,7 @@ def test_3_statements_2nd_current():
def test_create_db_with_template():
- suggestions = suggest_type(
- "create database foo with template ", "create database foo with template "
- )
+ suggestions = suggest_type("create database foo with template ", "create database foo with template ")
assert sorted_dicts(suggestions) == sorted_dicts([{"type": "database"}])
@@ -597,9 +567,7 @@ def test_create_db_with_template():
def test_specials_included_for_initial_completion(initial_text):
suggestions = suggest_type(initial_text, initial_text)
- assert sorted_dicts(suggestions) == sorted_dicts(
- [{"type": "keyword"}, {"type": "special"}]
- )
+ assert sorted_dicts(suggestions) == sorted_dicts([{"type": "keyword"}, {"type": "special"}])
def test_specials_not_included_after_initial_token():
diff --git a/tests/test_completion_refresher.py b/tests/test_completion_refresher.py
index 620a364..b566b8f 100644
--- a/tests/test_completion_refresher.py
+++ b/tests/test_completion_refresher.py
@@ -1,6 +1,6 @@
import time
import pytest
-from mock import Mock, patch
+from unittest.mock import Mock, patch
@pytest.fixture
diff --git a/tests/test_main.py b/tests/test_main.py
index e2f183a..a8fa4ae 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -1,7 +1,6 @@
import os
from collections import namedtuple
from textwrap import dedent
-from tempfile import NamedTemporaryFile
import shutil
import click
@@ -180,9 +179,7 @@ def output(monkeypatch, terminal_size, testdata, explicit_pager, expect_pager):
def test_conditional_pager(monkeypatch):
- testdata = "Lorem ipsum dolor sit amet consectetur adipiscing elit sed do".split(
- " "
- )
+ testdata = "Lorem ipsum dolor sit amet consectetur adipiscing elit sed do".split(" ")
# User didn't set pager, output doesn't fit screen -> pager
output(
monkeypatch,
diff --git a/tests/test_smart_completion_public_schema_only.py b/tests/test_smart_completion_public_schema_only.py
index c8e1be4..6134ff3 100644
--- a/tests/test_smart_completion_public_schema_only.py
+++ b/tests/test_smart_completion_public_schema_only.py
@@ -1,7 +1,7 @@
# coding: utf-8
from __future__ import unicode_literals
import pytest
-from mock import patch
+from unittest.mock import patch
from prompt_toolkit.completion import Completion
from prompt_toolkit.document import Document
@@ -35,7 +35,7 @@ def completer():
@pytest.fixture
def complete_event():
- from mock import Mock
+ from unittest.mock import Mock
return Mock()
@@ -43,29 +43,21 @@ def complete_event():
def test_empty_string_completion(completer, complete_event):
text = ""
position = 0
- result = list(
- completer.get_completions(
- Document(text=text, cursor_position=position), complete_event
- )
- )
+ result = list(completer.get_completions(Document(text=text, cursor_position=position), complete_event))
assert list(map(Completion, sorted(completer.keywords))) == result
def test_select_keyword_completion(completer, complete_event):
text = "SEL"
position = len("SEL")
- result = completer.get_completions(
- Document(text=text, cursor_position=position), complete_event
- )
+ result = completer.get_completions(Document(text=text, cursor_position=position), complete_event)
assert list(result) == list([Completion(text="SELECT", start_position=-3)])
def test_table_completion(completer, complete_event):
text = "SELECT * FROM "
position = len(text)
- result = completer.get_completions(
- Document(text=text, cursor_position=position), complete_event
- )
+ result = completer.get_completions(Document(text=text, cursor_position=position), complete_event)
assert list(result) == list(
[
Completion(text="`réveillé`", start_position=0),
@@ -79,9 +71,7 @@ def test_table_completion(completer, complete_event):
def test_function_name_completion(completer, complete_event):
text = "SELECT MA"
position = len("SELECT MA")
- result = completer.get_completions(
- Document(text=text, cursor_position=position), complete_event
- )
+ result = completer.get_completions(Document(text=text, cursor_position=position), complete_event)
assert list(result) == list(
[
Completion(text="MAX", start_position=-2),
@@ -100,11 +90,7 @@ def test_suggested_column_names(completer, complete_event):
"""
text = "SELECT from users"
position = len("SELECT ")
- result = list(
- completer.get_completions(
- Document(text=text, cursor_position=position), complete_event
- )
- )
+ result = list(completer.get_completions(Document(text=text, cursor_position=position), complete_event))
assert result == list(
[
Completion(text="*", start_position=0),
@@ -130,9 +116,7 @@ def test_suggested_column_names_in_function(completer, complete_event):
"""
text = "SELECT MAX( from users"
position = len("SELECT MAX(")
- result = completer.get_completions(
- Document(text=text, cursor_position=position), complete_event
- )
+ result = completer.get_completions(Document(text=text, cursor_position=position), complete_event)
assert list(result) == list(
[
Completion(text="*", start_position=0),
@@ -154,11 +138,7 @@ def test_suggested_column_names_with_table_dot(completer, complete_event):
"""
text = "SELECT users. from users"
position = len("SELECT users.")
- result = list(
- completer.get_completions(
- Document(text=text, cursor_position=position), complete_event
- )
- )
+ result = list(completer.get_completions(Document(text=text, cursor_position=position), complete_event))
assert result == list(
[
Completion(text="*", start_position=0),
@@ -180,11 +160,7 @@ def test_suggested_column_names_with_alias(completer, complete_event):
"""
text = "SELECT u. from users u"
position = len("SELECT u.")
- result = list(
- completer.get_completions(
- Document(text=text, cursor_position=position), complete_event
- )
- )
+ result = list(completer.get_completions(Document(text=text, cursor_position=position), complete_event))
assert result == list(
[
Completion(text="*", start_position=0),
@@ -207,11 +183,7 @@ def test_suggested_multiple_column_names(completer, complete_event):
"""
text = "SELECT id, from users u"
position = len("SELECT id, ")
- result = list(
- completer.get_completions(
- Document(text=text, cursor_position=position), complete_event
- )
- )
+ result = list(completer.get_completions(Document(text=text, cursor_position=position), complete_event))
assert result == list(
[
Completion(text="*", start_position=0),
@@ -237,11 +209,7 @@ def test_suggested_multiple_column_names_with_alias(completer, complete_event):
"""
text = "SELECT u.id, u. from users u"
position = len("SELECT u.id, u.")
- result = list(
- completer.get_completions(
- Document(text=text, cursor_position=position), complete_event
- )
- )
+ result = list(completer.get_completions(Document(text=text, cursor_position=position), complete_event))
assert result == list(
[
Completion(text="*", start_position=0),
@@ -264,11 +232,7 @@ def test_suggested_multiple_column_names_with_dot(completer, complete_event):
"""
text = "SELECT users.id, users. from users u"
position = len("SELECT users.id, users.")
- result = list(
- completer.get_completions(
- Document(text=text, cursor_position=position), complete_event
- )
- )
+ result = list(completer.get_completions(Document(text=text, cursor_position=position), complete_event))
assert result == list(
[
Completion(text="*", start_position=0),
@@ -283,37 +247,21 @@ def test_suggested_multiple_column_names_with_dot(completer, complete_event):
def test_suggested_aliases_after_on(completer, complete_event):
text = "SELECT u.name, o.id FROM users u JOIN orders o ON "
position = len("SELECT u.name, o.id FROM users u JOIN orders o ON ")
- result = list(
- completer.get_completions(
- Document(text=text, cursor_position=position), complete_event
- )
- )
- assert result == list(
- [Completion(text="o", start_position=0), Completion(text="u", start_position=0)]
- )
+ result = list(completer.get_completions(Document(text=text, cursor_position=position), complete_event))
+ assert result == list([Completion(text="o", start_position=0), Completion(text="u", start_position=0)])
def test_suggested_aliases_after_on_right_side(completer, complete_event):
text = "SELECT u.name, o.id FROM users u JOIN orders o ON o.user_id = "
position = len("SELECT u.name, o.id FROM users u JOIN orders o ON o.user_id = ")
- result = list(
- completer.get_completions(
- Document(text=text, cursor_position=position), complete_event
- )
- )
- assert result == list(
- [Completion(text="o", start_position=0), Completion(text="u", start_position=0)]
- )
+ result = list(completer.get_completions(Document(text=text, cursor_position=position), complete_event))
+ assert result == list([Completion(text="o", start_position=0), Completion(text="u", start_position=0)])
def test_suggested_tables_after_on(completer, complete_event):
text = "SELECT users.name, orders.id FROM users JOIN orders ON "
position = len("SELECT users.name, orders.id FROM users JOIN orders ON ")
- result = list(
- completer.get_completions(
- Document(text=text, cursor_position=position), complete_event
- )
- )
+ result = list(completer.get_completions(Document(text=text, cursor_position=position), complete_event))
assert result == list(
[
Completion(text="orders", start_position=0),
@@ -324,14 +272,8 @@ def test_suggested_tables_after_on(completer, complete_event):
def test_suggested_tables_after_on_right_side(completer, complete_event):
text = "SELECT users.name, orders.id FROM users JOIN orders ON orders.user_id = "
- position = len(
- "SELECT users.name, orders.id FROM users JOIN orders ON orders.user_id = "
- )
- result = list(
- completer.get_completions(
- Document(text=text, cursor_position=position), complete_event
- )
- )
+ position = len("SELECT users.name, orders.id FROM users JOIN orders ON orders.user_id = ")
+ result = list(completer.get_completions(Document(text=text, cursor_position=position), complete_event))
assert list(result) == list(
[
Completion(text="orders", start_position=0),
@@ -343,11 +285,7 @@ def test_suggested_tables_after_on_right_side(completer, complete_event):
def test_table_names_after_from(completer, complete_event):
text = "SELECT * FROM "
position = len("SELECT * FROM ")
- result = list(
- completer.get_completions(
- Document(text=text, cursor_position=position), complete_event
- )
- )
+ result = list(completer.get_completions(Document(text=text, cursor_position=position), complete_event))
assert list(result) == list(
[
Completion(text="`réveillé`", start_position=0),
@@ -361,19 +299,13 @@ def test_table_names_after_from(completer, complete_event):
def test_auto_escaped_col_names(completer, complete_event):
text = "SELECT from `select`"
position = len("SELECT ")
- result = list(
- completer.get_completions(
- Document(text=text, cursor_position=position), complete_event
- )
- )
+ result = list(completer.get_completions(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(
+ ] + list(map(Completion, completer.functions)) + [Completion(text="select", start_position=0)] + list(
map(Completion, sorted(completer.keywords))
)
@@ -381,11 +313,7 @@ def test_auto_escaped_col_names(completer, complete_event):
def test_un_escaped_table_names(completer, complete_event):
text = "SELECT from réveillé"
position = len("SELECT ")
- result = list(
- completer.get_completions(
- Document(text=text, cursor_position=position), complete_event
- )
- )
+ result = list(completer.get_completions(Document(text=text, cursor_position=position), complete_event))
assert result == list(
[
Completion(text="*", start_position=0),
@@ -420,10 +348,6 @@ def dummy_list_path(dir_name):
)
def test_file_name_completion(completer, complete_event, text, expected):
position = len(text)
- result = list(
- completer.get_completions(
- Document(text=text, cursor_position=position), complete_event
- )
- )
+ result = list(completer.get_completions(Document(text=text, cursor_position=position), complete_event))
expected = list([Completion(txt, pos) for txt, pos in expected])
assert result == expected
diff --git a/tests/test_sqlexecute.py b/tests/test_sqlexecute.py
index cd56683..0181b2c 100644
--- a/tests/test_sqlexecute.py
+++ b/tests/test_sqlexecute.py
@@ -274,8 +274,7 @@ def test_favorite_query_multiple_statement(executor):
results = run(
executor,
- "\\fs test-ad select * from test where a like 'a%'; "
- "select * from test where a like 'd%'",
+ "\\fs test-ad select * from test where a like 'a%'; " "select * from test where a like 'd%'",
)
assert_result_equal(results, status="Saved.")
@@ -346,9 +345,7 @@ def test_cd_command_without_a_folder_name(executor):
@dbtest
def test_system_command_not_found(executor):
results = run(executor, "system xyz")
- assert_result_equal(
- results, status="OSError: No such file or directory", assert_contains=True
- )
+ assert_result_equal(results, status="OSError: No such file or directory", assert_contains=True)
@dbtest
diff --git a/tests/utils.py b/tests/utils.py
index 41bac9b..4bacc94 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -12,7 +12,7 @@ import pytest
from litecli.main import special
-DATABASE = os.getenv("PYTEST_DATABASE", "test.sqlite3")
+DATABASE = "test.sqlite3"
def db_connection(dbname=":memory:"):
@@ -23,12 +23,10 @@ def db_connection(dbname=":memory:"):
try:
db_connection()
CAN_CONNECT_TO_DB = True
-except Exception as ex:
+except Exception:
CAN_CONNECT_TO_DB = False
-dbtest = pytest.mark.skipif(
- not CAN_CONNECT_TO_DB, reason="Error creating sqlite connection"
-)
+dbtest = pytest.mark.skipif(not CAN_CONNECT_TO_DB, reason="Error creating sqlite connection")
def create_db(dbname):
@@ -36,7 +34,7 @@ def create_db(dbname):
try:
cur.execute("""DROP DATABASE IF EXISTS _test_db""")
cur.execute("""CREATE DATABASE _test_db""")
- except:
+ except Exception:
pass
@@ -44,7 +42,7 @@ def drop_tables(dbname):
with closing(db_connection().cursor()) as cur:
try:
cur.execute("""DROP DATABASE IF EXISTS _test_db""")
- except:
+ except Exception:
pass
@@ -54,9 +52,7 @@ def run(executor, sql, rows_as_list=True):
for title, rows, headers, status in executor.run(sql):
rows = list(rows) if (rows_as_list and rows) else rows
- result.append(
- {"title": title, "rows": rows, "headers": headers, "status": status}
- )
+ result.append({"title": title, "rows": rows, "headers": headers, "status": status})
return result
@@ -89,8 +85,6 @@ def send_ctrl_c(wait_seconds):
Returns the `multiprocessing.Process` created.
"""
- ctrl_c_process = multiprocessing.Process(
- target=send_ctrl_c_to_pid, args=(os.getpid(), wait_seconds)
- )
+ ctrl_c_process = multiprocessing.Process(target=send_ctrl_c_to_pid, args=(os.getpid(), wait_seconds))
ctrl_c_process.start()
return ctrl_c_process