Skip to content

Commit f62763d

Browse files
author
Erlend Egeberg Aasland
authored
bpo-43398: Add test for defect connection factories (GH-27966)
1 parent 08d9e59 commit f62763d

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

Lib/sqlite3/test/factory.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
import sqlite3 as sqlite
2525
from collections.abc import Sequence
2626

27-
class MyConnection(sqlite.Connection):
28-
def __init__(self, *args, **kwargs):
29-
sqlite.Connection.__init__(self, *args, **kwargs)
3027

3128
def dict_factory(cursor, row):
3229
d = {}
@@ -40,14 +37,19 @@ def __init__(self, *args, **kwargs):
4037
self.row_factory = dict_factory
4138

4239
class ConnectionFactoryTests(unittest.TestCase):
43-
def setUp(self):
44-
self.con = sqlite.connect(":memory:", factory=MyConnection)
45-
46-
def tearDown(self):
47-
self.con.close()
40+
def test_connection_factories(self):
41+
class DefectFactory(sqlite.Connection):
42+
def __init__(self, *args, **kwargs):
43+
return None
44+
class OkFactory(sqlite.Connection):
45+
def __init__(self, *args, **kwargs):
46+
sqlite.Connection.__init__(self, *args, **kwargs)
47+
48+
for factory in DefectFactory, OkFactory:
49+
with self.subTest(factory=factory):
50+
con = sqlite.connect(":memory:", factory=factory)
51+
self.assertIsInstance(con, factory)
4852

49-
def test_is_instance(self):
50-
self.assertIsInstance(self.con, MyConnection)
5153

5254
class CursorFactoryTests(unittest.TestCase):
5355
def setUp(self):

0 commit comments

Comments
 (0)