summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_sqlite3/test_dump.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_sqlite3/test_dump.py')
-rw-r--r--Lib/test/test_sqlite3/test_dump.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/Lib/test/test_sqlite3/test_dump.py b/Lib/test/test_sqlite3/test_dump.py
index 2e1f0b8..7261b7f 100644
--- a/Lib/test/test_sqlite3/test_dump.py
+++ b/Lib/test/test_sqlite3/test_dump.py
@@ -54,6 +54,76 @@ class DumpTests(MemoryDatabaseMixin, unittest.TestCase):
[self.assertEqual(expected_sqls[i], actual_sqls[i])
for i in range(len(expected_sqls))]
+ def test_table_dump_filter(self):
+ all_table_sqls = [
+ """CREATE TABLE "some_table_2" ("id_1" INTEGER);""",
+ """INSERT INTO "some_table_2" VALUES(3);""",
+ """INSERT INTO "some_table_2" VALUES(4);""",
+ """CREATE TABLE "test_table_1" ("id_2" INTEGER);""",
+ """INSERT INTO "test_table_1" VALUES(1);""",
+ """INSERT INTO "test_table_1" VALUES(2);""",
+ ]
+ all_views_sqls = [
+ """CREATE VIEW "view_1" AS SELECT * FROM "some_table_2";""",
+ """CREATE VIEW "view_2" AS SELECT * FROM "test_table_1";""",
+ ]
+ # Create database structure.
+ for sql in [*all_table_sqls, *all_views_sqls]:
+ self.cu.execute(sql)
+ # %_table_% matches all tables.
+ dump_sqls = list(self.cx.iterdump(filter="%_table_%"))
+ self.assertEqual(
+ dump_sqls,
+ ["BEGIN TRANSACTION;", *all_table_sqls, "COMMIT;"],
+ )
+ # view_% matches all views.
+ dump_sqls = list(self.cx.iterdump(filter="view_%"))
+ self.assertEqual(
+ dump_sqls,
+ ["BEGIN TRANSACTION;", *all_views_sqls, "COMMIT;"],
+ )
+ # %_1 matches tables and views with the _1 suffix.
+ dump_sqls = list(self.cx.iterdump(filter="%_1"))
+ self.assertEqual(
+ dump_sqls,
+ [
+ "BEGIN TRANSACTION;",
+ """CREATE TABLE "test_table_1" ("id_2" INTEGER);""",
+ """INSERT INTO "test_table_1" VALUES(1);""",
+ """INSERT INTO "test_table_1" VALUES(2);""",
+ """CREATE VIEW "view_1" AS SELECT * FROM "some_table_2";""",
+ "COMMIT;"
+ ],
+ )
+ # some_% matches some_table_2.
+ dump_sqls = list(self.cx.iterdump(filter="some_%"))
+ self.assertEqual(
+ dump_sqls,
+ [
+ "BEGIN TRANSACTION;",
+ """CREATE TABLE "some_table_2" ("id_1" INTEGER);""",
+ """INSERT INTO "some_table_2" VALUES(3);""",
+ """INSERT INTO "some_table_2" VALUES(4);""",
+ "COMMIT;"
+ ],
+ )
+ # Only single object.
+ dump_sqls = list(self.cx.iterdump(filter="view_2"))
+ self.assertEqual(
+ dump_sqls,
+ [
+ "BEGIN TRANSACTION;",
+ """CREATE VIEW "view_2" AS SELECT * FROM "test_table_1";""",
+ "COMMIT;"
+ ],
+ )
+ # % matches all objects.
+ dump_sqls = list(self.cx.iterdump(filter="%"))
+ self.assertEqual(
+ dump_sqls,
+ ["BEGIN TRANSACTION;", *all_table_sqls, *all_views_sqls, "COMMIT;"],
+ )
+
def test_dump_autoincrement(self):
expected = [
'CREATE TABLE "t1" (id integer primary key autoincrement);',