ยปCore Development>Code coverage>Lib/sqlite3/test/dump.py

Python code coverage for Lib/sqlite3/test/dump.py

#countcontent
1n/a# Author: Paul Kippes <kippesp@gmail.com>
2n/a
3n/aimport unittest
4n/aimport sqlite3 as sqlite
5n/a
6n/aclass DumpTests(unittest.TestCase):
7n/a def setUp(self):
8n/a self.cx = sqlite.connect(":memory:")
9n/a self.cu = self.cx.cursor()
10n/a
11n/a def tearDown(self):
12n/a self.cx.close()
13n/a
14n/a def CheckTableDump(self):
15n/a expected_sqls = [
16n/a """CREATE TABLE "index"("index" blob);"""
17n/a ,
18n/a """INSERT INTO "index" VALUES(X'01');"""
19n/a ,
20n/a """CREATE TABLE "quoted""table"("quoted""field" text);"""
21n/a ,
22n/a """INSERT INTO "quoted""table" VALUES('quoted''value');"""
23n/a ,
24n/a "CREATE TABLE t1(id integer primary key, s1 text, " \
25n/a "t1_i1 integer not null, i2 integer, unique (s1), " \
26n/a "constraint t1_idx1 unique (i2));"
27n/a ,
28n/a "INSERT INTO \"t1\" VALUES(1,'foo',10,20);"
29n/a ,
30n/a "INSERT INTO \"t1\" VALUES(2,'foo2',30,30);"
31n/a ,
32n/a "CREATE TABLE t2(id integer, t2_i1 integer, " \
33n/a "t2_i2 integer, primary key (id)," \
34n/a "foreign key(t2_i1) references t1(t1_i1));"
35n/a ,
36n/a "CREATE TRIGGER trigger_1 update of t1_i1 on t1 " \
37n/a "begin " \
38n/a "update t2 set t2_i1 = new.t1_i1 where t2_i1 = old.t1_i1; " \
39n/a "end;"
40n/a ,
41n/a "CREATE VIEW v1 as select * from t1 left join t2 " \
42n/a "using (id);"
43n/a ]
44n/a [self.cu.execute(s) for s in expected_sqls]
45n/a i = self.cx.iterdump()
46n/a actual_sqls = [s for s in i]
47n/a expected_sqls = ['BEGIN TRANSACTION;'] + expected_sqls + \
48n/a ['COMMIT;']
49n/a [self.assertEqual(expected_sqls[i], actual_sqls[i])
50n/a for i in range(len(expected_sqls))]
51n/a
52n/a def CheckUnorderableRow(self):
53n/a # iterdump() should be able to cope with unorderable row types (issue #15545)
54n/a class UnorderableRow:
55n/a def __init__(self, cursor, row):
56n/a self.row = row
57n/a def __getitem__(self, index):
58n/a return self.row[index]
59n/a self.cx.row_factory = UnorderableRow
60n/a CREATE_ALPHA = """CREATE TABLE "alpha" ("one");"""
61n/a CREATE_BETA = """CREATE TABLE "beta" ("two");"""
62n/a expected = [
63n/a "BEGIN TRANSACTION;",
64n/a CREATE_ALPHA,
65n/a CREATE_BETA,
66n/a "COMMIT;"
67n/a ]
68n/a self.cu.execute(CREATE_BETA)
69n/a self.cu.execute(CREATE_ALPHA)
70n/a got = list(self.cx.iterdump())
71n/a self.assertEqual(expected, got)
72n/a
73n/adef suite():
74n/a return unittest.TestSuite(unittest.makeSuite(DumpTests, "Check"))
75n/a
76n/adef test():
77n/a runner = unittest.TextTestRunner()
78n/a runner.run(suite())
79n/a
80n/aif __name__ == "__main__":
81n/a test()