You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.0 KiB

  1. # Author: Paul Kippes <kippesp@gmail.com>
  2. import unittest
  3. import sqlite3 as sqlite
  4. class DumpTests(unittest.TestCase):
  5. def setUp(self):
  6. self.cx = sqlite.connect(":memory:")
  7. self.cu = self.cx.cursor()
  8. def tearDown(self):
  9. self.cx.close()
  10. def CheckTableDump(self):
  11. expected_sqls = [
  12. """CREATE TABLE "index"("index" blob);"""
  13. ,
  14. """INSERT INTO "index" VALUES(X'01');"""
  15. ,
  16. """CREATE TABLE "quoted""table"("quoted""field" text);"""
  17. ,
  18. """INSERT INTO "quoted""table" VALUES('quoted''value');"""
  19. ,
  20. "CREATE TABLE t1(id integer primary key, s1 text, " \
  21. "t1_i1 integer not null, i2 integer, unique (s1), " \
  22. "constraint t1_idx1 unique (i2));"
  23. ,
  24. "INSERT INTO \"t1\" VALUES(1,'foo',10,20);"
  25. ,
  26. "INSERT INTO \"t1\" VALUES(2,'foo2',30,30);"
  27. ,
  28. "CREATE TABLE t2(id integer, t2_i1 integer, " \
  29. "t2_i2 integer, primary key (id)," \
  30. "foreign key(t2_i1) references t1(t1_i1));"
  31. ,
  32. "CREATE TRIGGER trigger_1 update of t1_i1 on t1 " \
  33. "begin " \
  34. "update t2 set t2_i1 = new.t1_i1 where t2_i1 = old.t1_i1; " \
  35. "end;"
  36. ,
  37. "CREATE VIEW v1 as select * from t1 left join t2 " \
  38. "using (id);"
  39. ]
  40. [self.cu.execute(s) for s in expected_sqls]
  41. i = self.cx.iterdump()
  42. actual_sqls = [s for s in i]
  43. expected_sqls = ['BEGIN TRANSACTION;'] + expected_sqls + \
  44. ['COMMIT;']
  45. [self.assertEqual(expected_sqls[i], actual_sqls[i])
  46. for i in range(len(expected_sqls))]
  47. def suite():
  48. return unittest.TestSuite(unittest.makeSuite(DumpTests, "Check"))
  49. def test():
  50. runner = unittest.TextTestRunner()
  51. runner.run(suite())
  52. if __name__ == "__main__":
  53. test()