Beispiel #1
0
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")
Beispiel #2
0
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()])
Beispiel #3
0
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(),
    ])
Beispiel #4
0
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()
    ])
Beispiel #5
0
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) == set(
        [FromClauseItem(schema=None, table_refs=tbls),
         Schema()])
Beispiel #6
0
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)
    ])
Beispiel #7
0
def test_cast_operator_suggests_types(text):
    assert set(suggest_type(text, text)) == set(
        [Datatype(schema=None),
         Table(schema=None),
         Schema()])
Beispiel #8
0
def test_drop_schema_suggests_schemas():
    sql = "DROP SCHEMA "
    assert suggest_type(sql, sql) == (Schema(), )
Beispiel #9
0
def test_suggest_tables_views_schemas_and_functions(expression):
    suggestions = suggest_type(expression, expression)
    assert set(suggestions) == set([FromClauseItem(schema=None), Schema()])
Beispiel #10
0
def test_sub_select_table_name_completion(expression):
    suggestion = suggest_type(expression, expression)
    assert set(suggestion) == set([FromClauseItem(schema=None), Schema()])
Beispiel #11
0
def test_into_suggests_tables_and_schemas():
    suggestion = suggest_type("INSERT INTO ", "INSERT INTO ")
    assert set(suggestion) == set(
        [Table(schema=None), View(schema=None),
         Schema()])
Beispiel #12
0
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()])
Beispiel #13
0
def test_truncate_suggests_tables_and_schemas():
    suggestions = suggest_type("TRUNCATE ", "TRUNCATE ")
    assert set(suggestions) == set([Table(schema=None), Schema()])
Beispiel #14
0
def test_alter_column_type_suggests_types():
    q = "ALTER TABLE foo ALTER COLUMN bar TYPE "
    assert set(suggest_type(q, q)) == set(
        [Datatype(schema=None),
         Table(schema=None),
         Schema()])
Beispiel #15
0
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()])
Beispiel #16
0
def test_identifier_suggests_types_in_parentheses(text):
    assert set(suggest_type(text, text)) == set(
        [Datatype(schema=None),
         Table(schema=None),
         Schema()])
Beispiel #17
0
def test_suggests_tables_views_and_schemas(expression):
    suggestions = suggest_type(expression, expression)
    assert set(suggestions) == set(
        [Table(schema=None), View(schema=None),
         Schema()])