[Python-checkins] bpo-43398: Add test for defect connection factories (GH-27966)

pablogsal webhook-mailer at python.org
Mon Aug 30 13:49:42 EDT 2021


https://github.com/python/cpython/commit/f62763d26755260c31c717fb396550e00eb6b2a0
commit: f62763d26755260c31c717fb396550e00eb6b2a0
branch: main
author: Erlend Egeberg Aasland <erlend.aasland at innova.no>
committer: pablogsal <Pablogsal at gmail.com>
date: 2021-08-30T18:49:34+01:00
summary:

bpo-43398: Add test for defect connection factories (GH-27966)

files:
M Lib/sqlite3/test/factory.py

diff --git a/Lib/sqlite3/test/factory.py b/Lib/sqlite3/test/factory.py
index 7faa9ac8c1fc2e..9e7a7e28c6ed3a 100644
--- a/Lib/sqlite3/test/factory.py
+++ b/Lib/sqlite3/test/factory.py
@@ -24,9 +24,6 @@
 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 @@ def __init__(self, *args, **kwargs):
         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):



More information about the Python-checkins mailing list