Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_suggest_after_join_with_one_table(expression):
suggestions = suggest_type(expression, expression)
tables = ((None, "foo", None, False),)
assert set(suggestions) == set(
[
FromClauseItem(schema=None, table_refs=tables),
Join(((None, "foo", None, False),), None),
Schema(),
]
def test_dot_suggests_cols_of_an_alias(sql):
suggestions = suggest_type(sql, "SELECT t1.")
assert set(suggestions) == set(
[
Table(schema="t1"),
View(schema="t1"),
Column(table_refs=((None, "tabl1", "t1", False),)),
Function(schema="t1"),
]
def test_suggest_qualified_tables_views_functions_and_joins(expression):
suggestions = suggest_type(expression, expression)
tbls = tuple([(None, "foo", None, False)])
assert set(suggestions) == set(
[FromClauseItem(schema="sch", table_refs=tbls), Join(tbls, "sch")]
)
def test_sub_select_table_name_completion(expression):
suggestion = suggest_type(expression, expression)
assert set(suggestion) == set([FromClauseItem(schema=None), Schema()])
def test_statements_with_cursor_after_function_body(text):
suggestions = suggest_type(text, text[: text.find("; ") + 1])
assert set(suggestions) == set([Keyword(), Special()])
def test_suggest_qualified_tables_and_views(expression):
suggestions = suggest_type(expression, expression)
assert set(suggestions) == set([Table(schema="sch"), View(schema="sch")])
def test_insert_into_lparen_partial_text_suggests_cols():
suggestions = suggest_type("INSERT INTO abc (i", "INSERT INTO abc (i")
assert suggestions == (
Column(table_refs=((None, "abc", None, False),), context="insert"),
)
def test_distinct_and_order_by_suggestions_with_aliases(
text, text_before, last_keyword
):
suggestions = suggest_type(text, text_before)
assert set(suggestions) == set(
[
Column(
table_refs=(
TableReference(None, "tbl", "x", False),
TableReference(None, "tbl1", "y", False),
),
local_tables=(),
qualifiable=True,
),
Function(schema=None),
Keyword(last_keyword),
]
def test_select_suggests_cols_with_visible_table_scope():
suggestions = suggest_type("SELECT FROM tabl", "SELECT ")
assert set(suggestions) == cols_etc("tabl", last_keyword="SELECT")
def test_truncate_suggests_tables_and_schemas():
suggestions = suggest_type("TRUNCATE ", "TRUNCATE ")
assert set(suggestions) == set([Table(schema=None), Schema()])