def test_write_table_method(self): df = DataFrame([[1, 2], [3, 4]], columns=["col1", "col2"]) sqldf = SQLDF(locals()) sqldf._write_table("tbl", df) # table created cursor = sqldf.conn.cursor() sq_type, name, tbl_name, rootpage, sql = list( cursor.execute("select * from sqlite_master where type='table';"))[0] self.assertEqual(name, "tbl")
def test_write_table_method(self): df = DataFrame([[1, 2], [3, 4]], columns=["col1", "col2"]) sqldf = SQLDF(locals()) sqldf._write_table("tbl", df) # table created cursor = sqldf.conn.cursor() sq_type, name, tbl_name, rootpage, sql = list( cursor.execute( "select * from sqlite_master where type='table';"))[0] self.assertEqual(name, "tbl")
def test_write_table_method_garbage_table(self): df = [[1, 2], [3, [4]]] sqldf = SQLDF(locals()) self.assertRaises(Exception, lambda: sqldf._write_table("tbl", df)) # table destroyed cursor = sqldf.conn.cursor() tablemaster = list(cursor.execute("select * from sqlite_master where type='table';")) self.assertEqual(tablemaster, [])
def test_write_table_method_garbage_table(self): df = [[1, 2], [3, [4]]] sqldf = SQLDF(locals()) self.assertRaises(Exception, lambda: sqldf._write_table("tbl", df)) # table destroyed cursor = sqldf.conn.cursor() tablemaster = list( cursor.execute("select * from sqlite_master where type='table';")) self.assertEqual(tablemaster, [])
def test_write_table_method_col_with_right_bracket(self): df = DataFrame([[1]], columns=["co)l"]) sqldf = SQLDF(locals()) self.assertRaises(Exception, lambda: sqldf._write_table("tbl", df))