def test_table_comma_suggests_tables_and_schemas(): suggestions = suggest_type('SELECT a, b FROM tbl1, ', 'SELECT a, b FROM tbl1, ') assert set(suggestions) == set([ FromClauseItem(schema=None), Schema(), ])
def test_2_statements_1st_current(): suggestions = suggest_type("select * from ; select * from b", "select * from ") assert set(suggestions) == set([FromClauseItem(schema=None), Schema()]) suggestions = suggest_type("select from a; select * from b", "select ") assert set(suggestions) == cols_etc("a", last_keyword="SELECT")
def test_left_join_with_comma(): text = "select * from foo f left join bar b," suggestions = suggest_type(text, text) # tbls should also include (None, 'bar', 'b', False) # but there's a bug with commas tbls = tuple([(None, "foo", "f", False)]) assert set(suggestions) == {FromClauseItem(schema=None, table_refs=tbls), Schema()}
def test_sub_select_table_name_completion_with_outer_table(expression): suggestion = suggest_type(expression, expression) tbls = tuple([(None, 'foo', None, False)]) assert set(suggestion) == set([ FromClauseItem(schema=None, table_refs=tbls), Schema(), ])
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_suggest_qualified_tables_views_functions_and_joins(expression): suggestions = suggest_type(expression, expression) tbls = tuple([(None, "foo", None, False)]) assert set(suggestions) == { FromClauseItem(schema="sch", table_refs=tbls), Join(tbls, "sch"), }
def test_2_statements_2nd_current(): suggestions = suggest_type("select * from a; select * from ", "select * from a; select * from ") assert set(suggestions) == set([FromClauseItem(schema=None), Schema()]) suggestions = suggest_type("select * from a; select from b", "select * from a; select ") assert set(suggestions) == set([ Column(table_refs=((None, "b", None, False), ), qualifiable=True), Function(schema=None), Keyword("SELECT"), ]) # Should work even if first statement is invalid suggestions = suggest_type("select * from; select * from ", "select * from; select * from ") assert set(suggestions) == set([FromClauseItem(schema=None), Schema()])
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_suggest_after_join_with_two_tables(expression): suggestions = suggest_type(expression, expression) tables = tuple([(None, 'foo', None, False), (None, 'bar', None, False)]) assert set(suggestions) == set([ FromClauseItem(schema=None, table_refs=tables), Join(tables, None), Schema(), ])
def test_join_suggests_tables_and_schemas(tbl_alias, join_type): text = 'SELECT * FROM abc {0} {1} JOIN '.format(tbl_alias, join_type) suggestion = suggest_type(text, text) tbls = tuple([(None, 'abc', tbl_alias or None, False)]) assert set(suggestion) == set([ FromClauseItem(schema=None, table_refs=tbls), Schema(), Join(tbls, None), ])
def test_join_suggests_tables_and_schemas(tbl_alias, join_type): text = f"SELECT * FROM abc {tbl_alias} {join_type} JOIN " suggestion = suggest_type(text, text) tbls = tuple([(None, "abc", tbl_alias or None, False)]) assert set(suggestion) == { FromClauseItem(schema=None, table_refs=tbls), Schema(), Join(tbls, None), }
def test_2_statements_1st_current(): suggestions = suggest_type('select * from ; select * from b', 'select * from ') assert set(suggestions) == set([ FromClauseItem(schema=None), Schema(), ]) suggestions = suggest_type('select from a; select * from b', 'select ') assert set(suggestions) == cols_etc('a')
def test_3_statements_2nd_current(): suggestions = suggest_type( "select * from a; select * from ; select * from c", "select * from a; select * from ", ) assert set(suggestions) == {FromClauseItem(schema=None), Schema()} suggestions = suggest_type( "select * from a; select from b; select * from c", "select * from a; select " ) assert set(suggestions) == cols_etc("b", last_keyword="SELECT")
def test_3_statements_2nd_current(): suggestions = suggest_type('select * from a; select * from ; select * from c', 'select * from a; select * from ') assert set(suggestions) == set([ FromClauseItem(schema=None), Schema(), ]) suggestions = suggest_type('select * from a; select from b; select * from c', 'select * from a; select ') assert set(suggestions) == cols_etc('b', last_keyword='SELECT')
def test_2_statements_2nd_current(): suggestions = suggest_type('select * from a; select * from ', 'select * from a; select * from ') assert set(suggestions) == set([ FromClauseItem(schema=None), Schema(), ]) suggestions = suggest_type('select * from a; select from b', 'select * from a; select ') assert set(suggestions) == set([ Column(table_refs=((None, 'b', None, False), )), Function(schema=None), Keyword() ]) # Should work even if first statement is invalid suggestions = suggest_type('select * from; select * from ', 'select * from; select * from ') assert set(suggestions) == set([ FromClauseItem(schema=None), Schema(), ])
def test_ignore_leading_double_quotes(sql): suggestions = suggest_type(sql, sql) assert FromClauseItem(schema=None) in set(suggestions)
def test_sub_select_table_name_completion(expression): suggestion = suggest_type(expression, expression) assert set(suggestion) == set([ FromClauseItem(schema=None), Schema(), ])
def test_suggest_qualified_tables_views_and_functions(expression): suggestions = suggest_type(expression, expression) assert set(suggestions) == set([FromClauseItem(schema='sch')])
def test_table_comma_suggests_tables_and_schemas(): suggestions = suggest_type("SELECT a, b FROM tbl1, ", "SELECT a, b FROM tbl1, ") assert set(suggestions) == {FromClauseItem(schema=None), Schema()}
def test_suggest_tables_views_schemas_and_functions(expression): suggestions = suggest_type(expression, expression) assert set(suggestions) == set([FromClauseItem(schema=None), Schema()])