2424import sqlite3 as sqlite
2525from collections .abc import Sequence
2626
27- class MyConnection (sqlite .Connection ):
28- def __init__ (self , * args , ** kwargs ):
29- sqlite .Connection .__init__ (self , * args , ** kwargs )
3027
3128def dict_factory (cursor , row ):
3229 d = {}
@@ -40,14 +37,19 @@ def __init__(self, *args, **kwargs):
4037 self .row_factory = dict_factory
4138
4239class 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
5254class CursorFactoryTests (unittest .TestCase ):
5355 def setUp (self ):
0 commit comments