diff options
author | Erlend Egeberg Aasland <erlend.aasland@innova.no> | 2021-08-30 17:49:34 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-30 17:49:34 (GMT) |
commit | f62763d26755260c31c717fb396550e00eb6b2a0 (patch) | |
tree | afdf04935ef5d4dafd4c3e4125fe963ac163941a /Lib/sqlite3/test/factory.py | |
parent | 08d9e597c8ef5a2b26375ac954fdf224f5d82c3c (diff) | |
download | cpython-f62763d26755260c31c717fb396550e00eb6b2a0.zip cpython-f62763d26755260c31c717fb396550e00eb6b2a0.tar.gz cpython-f62763d26755260c31c717fb396550e00eb6b2a0.tar.bz2 |
bpo-43398: Add test for defect connection factories (GH-27966)
Diffstat (limited to 'Lib/sqlite3/test/factory.py')
-rw-r--r-- | Lib/sqlite3/test/factory.py | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/Lib/sqlite3/test/factory.py b/Lib/sqlite3/test/factory.py index 7faa9ac..9e7a7e2 100644 --- a/Lib/sqlite3/test/factory.py +++ b/Lib/sqlite3/test/factory.py @@ -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): |