def test_2_statements_2nd_current(): suggestions = suggest_type('select * from a; select * from ', 'select * from a; select * from ') assert set(suggestions) == set([ Table(schema=None), View(schema=None), Function(schema=None, filter='is_set_returning'), Schema(), ]) suggestions = suggest_type('select * from a; select from b', 'select * from a; select ') assert set(suggestions) == set([ Column(tables=((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([ Table(schema=None), View(schema=None), Function(schema=None, filter='is_set_returning'), Schema(), ])
def test_df_suggests_schema_or_function(): suggestions = suggest_type('\\df xxx', '\\df xxx') assert set(suggestions) == set([ Function(schema=None), Schema(), ]) suggestions = suggest_type('\\df myschema.xxx', '\\df myschema.xxx') assert suggestions == (Function(schema='myschema'), )
def test_col_comma_suggests_cols(): suggestions = suggest_type("SELECT a, b, FROM tbl", "SELECT a, b,") assert set(suggestions) == set([ Column(table_refs=((None, "tbl", None, False), ), qualifiable=True), Function(schema=None), Keyword("SELECT"), ])
def test_select_suggests_cols_and_funcs(): suggestions = suggest_type("SELECT ", "SELECT ") assert set(suggestions) == set([ Column(table_refs=(), qualifiable=True), Function(schema=None), Keyword("SELECT"), ])
def test_lparen_suggests_cols_and_funcs(): suggestion = suggest_type("SELECT MAX( FROM tbl", "SELECT MAX(") assert set(suggestion) == set([ Column(table_refs=((None, "tbl", None, False), ), qualifiable=True), Function(schema=None), Keyword("("), ])
def test_statements_in_function_body(text): suggestions = suggest_type(text, text[: text.find(" ") + 1]) assert set(suggestions) == { Column(table_refs=((None, "foo", None, False),), qualifiable=True), Function(schema=None), Keyword("SELECT"), }
def test_statements_in_function_body(text): suggestions = suggest_type(text, text[:text.find(' ') + 1]) assert set(suggestions) == set([ Column(table_refs=((None, 'foo', None, False),), qualifiable=True), Function(schema=None), Keyword('SELECT'), ])
def test_select_suggests_cols_and_funcs(): suggestions = suggest_type('SELECT ', 'SELECT ') assert set(suggestions) == set([ Column(table_refs=()), Function(schema=None), Keyword(), ])
def test_select_suggests_fields_from_function(): suggestions = suggest_type('SELECT FROM func()', 'SELECT ') assert set(suggestions) == set([ Column(tables=((None, 'func', None, True), )), Function(schema=None), Keyword() ])
def test_distinct_suggests_cols(text): suggestions = suggest_type(text, text) assert set(suggestions) == set([ Column(table_refs=(), local_tables=(), qualifiable=True), Function(schema=None), Keyword('DISTINCT') ])
def test_select_suggests_cols_with_visible_table_scope(): suggestions = suggest_type('SELECT FROM tabl', 'SELECT ') assert set(suggestions) == set([ Column(tables=((None, 'tabl', None, False), )), Function(schema=None), Keyword() ])
def test_where_in_suggests_columns(expression): suggestions = suggest_type(expression, expression) assert set(suggestions) == set([ Column(tables=((None, 'tabl', None, False), )), Function(schema=None), Keyword(), ])
def test_col_comma_suggests_cols(): suggestions = suggest_type('SELECT a, b, FROM tbl', 'SELECT a, b,') assert set(suggestions) == set([ Column(table_refs=((None, 'tbl', None, False), )), Function(schema=None), Keyword(), ])
def test_2_statements_1st_current(): suggestions = suggest_type('select * from ; select * from b', 'select * from ') assert set(suggestions) == set([ Table(schema=None), View(schema=None), Function(schema=None, filter='for_from_clause'), Schema(), ]) suggestions = suggest_type('select from a; select * from b', 'select ') assert set(suggestions) == set([ Column(tables=((None, 'a', None, False), )), Function(schema=None), Keyword() ])
def test_suggest_qualified_tables_views_and_set_returning_functions( expression): suggestions = suggest_type(expression, expression) assert set(suggestions) == set([ Table(schema='sch'), View(schema='sch'), Function(schema='sch', filter='is_set_returning'), ])
def test_suggest_where_keyword(text): # https://github.com/dbcli/mycli/issues/135 suggestions = suggest_type(text, text) assert set(suggestions) == set([ Column(tables=((None, 'foo', None, False), )), Function(schema=None), Keyword(), ])
def test_where_equals_any_suggests_columns_or_keywords(): text = 'SELECT * FROM tabl WHERE foo = ANY(' suggestions = suggest_type(text, text) assert set(suggestions) == set([ Column(tables=((None, 'tabl', None, False), )), Function(schema=None), Keyword(), ])
def cols_etc(table, schema=None, alias=None, is_function=False, parent=None): return set([ Column(table_refs=(TableReference(schema, table, alias, is_function), ), qualifiable=True), Function(schema=parent), Keyword() ])
def test_join_alias_dot_suggests_cols2(sql): suggestion = suggest_type(sql, sql) assert set(suggestion) == { Column(table_refs=((None, "def", "d", False),)), Table(schema="d"), View(schema="d"), Function(schema="d"), }
def test_join_alias_dot_suggests_cols2(sql): suggestion = suggest_type(sql, sql) assert set(suggestion) == set([ Column(table_refs=((None, 'def', 'd', False), )), Table(schema='d'), View(schema='d'), Function(schema='d'), ])
def test_dot_suggests_cols_of_an_alias_where(sql): suggestions = suggest_type(sql, sql) assert set(suggestions) == set([ Table(schema='t1'), View(schema='t1'), Column(table_refs=((None, 'tabl1', 't1', False), )), Function(schema='t1'), ])
def test_suggest_tables_views_schemas_and_set_returning_functions(expression): suggestions = suggest_type(expression, expression) assert set(suggestions) == set([ Table(schema=None), View(schema=None), Function(schema=None, filter='is_set_returning'), 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_sub_select_col_name_completion(): suggestions = suggest_type("SELECT * FROM (SELECT FROM abc", "SELECT * FROM (SELECT ") assert set(suggestions) == set([ Column(table_refs=((None, "abc", None, False), ), qualifiable=True), Function(schema=None), Keyword("SELECT"), ])
def test_dot_suggests_cols_of_a_table_or_schema_qualified_table(): suggestions = suggest_type('SELECT tabl. FROM tabl', 'SELECT tabl.') assert set(suggestions) == set([ Column(table_refs=((None, 'tabl', None, False), )), Table(schema='tabl'), View(schema='tabl'), Function(schema='tabl'), ])
def test_partially_typed_col_name_suggests_col_names(): suggestions = suggest_type('SELECT * FROM tabl WHERE col_n', 'SELECT * FROM tabl WHERE col_n') assert set(suggestions) == set([ Column(tables=((None, 'tabl', None, False), )), Function(schema=None), Keyword() ])
def test_sub_select_col_name_completion(): suggestions = suggest_type('SELECT * FROM (SELECT FROM abc', 'SELECT * FROM (SELECT ') assert set(suggestions) == set([ Column(table_refs=((None, 'abc', None, False), )), Function(schema=None), Keyword(), ])
def test_sub_select_table_name_completion(expression): suggestion = suggest_type(expression, expression) assert set(suggestion) == set([ Table(schema=None), View(schema=None), Function(schema=None, filter='is_set_returning'), Schema(), ])
def test_join_alias_dot_suggests_cols1(sql): suggestions = suggest_type(sql, sql) assert set(suggestions) == set([ Column(tables=((None, 'abc', 'a', False), )), Table(schema='a'), View(schema='a'), Function(schema='a'), ])
def test_dot_suggests_cols_of_an_alias_where(sql): suggestions = suggest_type(sql, sql) assert set(suggestions) == { Table(schema="t1"), View(schema="t1"), Column(table_refs=((None, "tabl1", "t1", False),)), Function(schema="t1"), }