24
24
import sqlite3 as sqlite
25
25
from collections .abc import Sequence
26
26
27
- class MyConnection (sqlite .Connection ):
28
- def __init__ (self , * args , ** kwargs ):
29
- sqlite .Connection .__init__ (self , * args , ** kwargs )
30
27
31
28
def dict_factory (cursor , row ):
32
29
d = {}
@@ -40,14 +37,19 @@ def __init__(self, *args, **kwargs):
40
37
self .row_factory = dict_factory
41
38
42
39
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 )
48
52
49
- def test_is_instance (self ):
50
- self .assertIsInstance (self .con , MyConnection )
51
53
52
54
class CursorFactoryTests (unittest .TestCase ):
53
55
def setUp (self ):
0 commit comments