def test_fts4(self): """ Tests for FTS4Table """ table = """ CREATE VIRTUAL TABLE textsearch USING fts4 ( name TEXT NOT NULL, value INT, description);""" parser = Parser(table) self.assertTrue(parser.obj) obj = parser.obj self.assertIsInstance(obj,virtual.FTS4Table) self.assertEqual(obj.name,"textsearch") self.assertEqual(obj.definition,table) self.assertTrue(hasattr(obj,"columns")) for (column,dtype,constraint) in [ ("name","TEXT","NOT NULL"), ("value","INT",None), ("description","",None)]: col = [col for col in obj.columns.values() if col.name == column] self.assertTrue(col) self.assertEqual(len(col),1) col = col[0] self.assertEqual(col._datatype,dtype) if constraint: con = [con for con in col.allconstraints if con.constraint == constraint] self.assertTrue(con) con = con[0]
def test_selectmode(self): """ Tests that the parser finds the correct Select.mode """ definition = """ SELECT DISTINCT rowid,* FROM testtable;""" parser = Parser(definition) self.assertEqual(parser.obj.mode,"DISTINCT")
def test_selectobj(self): """ Tests that the parser correctly identifies the statement as a Select statement """ definition = """ SELECT rowid,* FROM testtable;""" parser = Parser(definition) self.assertTrue(parser.obj) self.assertIsInstance(parser.obj,View.SimpleSelectStatement)
def test_virtualtable(self): """ Tests that the parser can correctly parse a VIRTUAL Table """ table = """ CREATE VIRTUAL TABLE IF NOT EXISTS temp.testtable USING mymodule(this,that);""" parser = Parser(table) self.assertTrue(parser.obj) obj = parser.obj self.assertIsInstance(obj,virtual.VirtualTable) self.assertTrue(obj.istemporary) self.assertTrue(obj.existsok) self.assertEqual(obj.name,"testtable") self.assertEqual(obj.module, "mymodule") self.assertEqual(obj.args, "(this,that)")
def test_multiple_multiline_comments(self): """ The parse previously consumed multiline comments greedily which would result in all text between two (or more) multiline comments getting captured. Switched to non-greedy to fix. """ table = """CREATE TABLE a( column1, /* A multiline comment */ column2 /* The previous column would be captured when these two comments were merged */ );""" parsedtable = Parser(table).obj self.assertIn("column1",parsedtable.columns) ## This would always pass self.assertIn("column2",parsedtable.columns) ## This would fail with the bug
def test_fts4_advancedtable(self): """ Tests for FTS4AdvancedTable """ """ Tests for FTS4Table """ table = """ CREATE VIRTUAL TABLE advtextsearch USING fts4 ( name TEXT NOT NULL, value INT, description);""" parser = Parser(table) self.assertTrue(parser.obj) obj = parser.obj self.connection.addtables(obj) obj2 = self.connection.gettable("advtextsearch") self.assertTrue(obj2) self.assertEqual(obj,obj2) advobj = obj.to_advancedtable(self.connection) self.assertTrue(advobj) self.assertEqual(obj,advobj) self.assertEqual(obj2,advobj)
def setUp(self): self.definition = TESTTABLE self.parser = Parser(self.definition) self.table = self.parser.obj
def test_basic_parsecolumn(self): """ A basic test for Parser.parse_column """ table = sql.TableConstructor("testtable", columns = [objects.Column("blah"),]).to_table() for (definition,column) in [("name TEXT",objects.Column("name",datatype="TEXT")),]: with self.subTest(definition = definition, column = column): self.assertEqual(Parser.parse_column(definition,table),column)