def test_2_statements_2nd_current(self): suggestions = suggest_type('select * from a; select * from ', 'select * from a; select * from ') self.assertSetEqual(set(suggestions), set([ FromClauseItem(schema=None), Schema(), ])) suggestions = suggest_type('select * from a; select from b', 'select * from a; select ') self.assertSetEqual( 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 ') self.assertSetEqual(set(suggestions), set([ FromClauseItem(schema=None), Schema(), ]))
def test_alter_column_type_suggests_types(self): q = 'ALTER TABLE foo ALTER COLUMN bar TYPE ' self.assertSetEqual( set(suggest_type(q, q)), set([Datatype(schema=None), Table(schema=None), Schema()]))
def test_sub_select_table_name_completion(self, expression): suggestions = suggest_type(expression, expression) self.assertSetEqual(set(suggestions), set([ FromClauseItem(schema=None), Schema(), ]))
def test_table_comma_suggests_tables_and_schemas(self): suggestions = suggest_type('SELECT a, b FROM tbl1, ', 'SELECT a, b FROM tbl1, ') self.assertSetEqual(set(suggestions), set([ FromClauseItem(schema=None), Schema(), ]))
def test_into_suggests_tables_and_schemas(self): suggestions = suggest_type('INSERT INTO ', 'INSERT INTO ') self.assertSetEqual( set(suggestions), set([ Table(schema=None), View(schema=None), Schema(), ]))
def test_suggests_tables_views_and_schemas(self, expression): suggestions = suggest_type(expression, expression) self.assertSetEqual( set(suggestions), set([ Table(schema=None), View(schema=None), Schema(), ]))
def test_suggest_after_join_with_one_table(self, expression): suggestions = suggest_type(expression, expression) tables = ((None, 'foo', None, False), ) self.assertSetEqual( set(suggestions), set([ FromClauseItem(schema=None, table_refs=tables), Join(((None, 'foo', None, False), ), None), Schema(), ]))
def test_sub_select_table_name_completion_with_outer_table( self, expression): suggestions = suggest_type(expression, expression) tbls = tuple([(None, 'foo', None, False)]) self.assertSetEqual( set(suggestions), set([ FromClauseItem(schema=None, table_refs=tbls), Schema(), ]))
def test_suggest_after_join_with_two_tables(self, expression): suggestions = suggest_type(expression, expression) tables = tuple([(None, 'foo', None, False), (None, 'bar', None, False)]) self.assertSetEqual( set(suggestions), set([ FromClauseItem(schema=None, table_refs=tables), Join(tables, None), Schema(), ]))
def test_left_join_with_comma(self): 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)]) self.assertSetEqual( set(suggestions), set([ FromClauseItem(schema=None, table_refs=tbls), Schema(), ]))
def test_2_statements_1st_current(self): suggestions = suggest_type('select * from ; select * from b', 'select * from ') self.assertSetEqual(set(suggestions), set([ FromClauseItem(schema=None), Schema(), ])) suggestions = suggest_type('select from a; select * from b', 'select ') self.assertSetEqual(set(suggestions), cols_etc('a', last_keyword='SELECT'))
def test_join_suggests_tables_and_schemas(self): tbl_aliases = ( '', 'foo', ) join_types = ( '', 'INNER', 'LEFT', 'RIGHT OUTER', ) for table in tbl_aliases: for join in join_types: text = 'SELECT * FROM abc {0} {1} JOIN '.format(table, join) suggestions = suggest_type(text, text) tbls = tuple([(None, 'abc', table or None, False)]) self.assertSetEqual( set(suggestions), set([ FromClauseItem(schema=None, table_refs=tbls), Schema(), Join(tbls, None), ]))
def test_identifier_suggests_types_in_parentheses(self, text): self.assertSetEqual( set(suggest_type(text, text)), set([Datatype(schema=None), Table(schema=None), Schema()]))
def test_cast_operator_suggests_types(self, text): self.assertSetEqual( set(suggest_type(text, text)), set([Datatype(schema=None), Table(schema=None), Schema()]))
def test_drop_schema_suggests_schemas(self): sql = 'DROP SCHEMA ' self.assertEqual(suggest_type(sql, sql), (Schema(), ))
def test_truncate_suggests_tables_and_schemas(self): suggestions = suggest_type('TRUNCATE ', 'TRUNCATE ') self.assertSetEqual(set(suggestions), set([Table(schema=None), Schema()]))
def test_suggest_tables_views_schemas_and_functions(self, expression): suggestions = suggest_type(expression, expression) self.assertSetEqual(set(suggestions), set([FromClauseItem(schema=None), Schema()]))