]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-43398: Add test for defect connection factories (GH-27966)
authorErlend Egeberg Aasland <erlend.aasland@innova.no>
Mon, 30 Aug 2021 17:49:34 +0000 (19:49 +0200)
committerGitHub <noreply@github.com>
Mon, 30 Aug 2021 17:49:34 +0000 (18:49 +0100)
Lib/sqlite3/test/factory.py

index 7faa9ac8c1fc2e03956a766c20de8614c2936615..9e7a7e28c6ed3aee66ce0c0ca9b528fd55f335d0 100644 (file)
@@ -24,9 +24,6 @@ import unittest
 import sqlite3 as sqlite
 from collections.abc import Sequence
 
-class MyConnection(sqlite.Connection):
-    def __init__(self, *args, **kwargs):
-        sqlite.Connection.__init__(self, *args, **kwargs)
 
 def dict_factory(cursor, row):
     d = {}
@@ -40,14 +37,19 @@ class MyCursor(sqlite.Cursor):
         self.row_factory = dict_factory
 
 class ConnectionFactoryTests(unittest.TestCase):
-    def setUp(self):
-        self.con = sqlite.connect(":memory:", factory=MyConnection)
-
-    def tearDown(self):
-        self.con.close()
+    def test_connection_factories(self):
+        class DefectFactory(sqlite.Connection):
+            def __init__(self, *args, **kwargs):
+                return None
+        class OkFactory(sqlite.Connection):
+            def __init__(self, *args, **kwargs):
+                sqlite.Connection.__init__(self, *args, **kwargs)
+
+        for factory in DefectFactory, OkFactory:
+            with self.subTest(factory=factory):
+                con = sqlite.connect(":memory:", factory=factory)
+                self.assertIsInstance(con, factory)
 
-    def test_is_instance(self):
-        self.assertIsInstance(self.con, MyConnection)
 
 class CursorFactoryTests(unittest.TestCase):
     def setUp(self):