@@ -58,9 +58,21 @@ def tearDown(self):
5858 self .con .close ()
5959
6060 def CheckIsInstance (self ):
61- cur = self .con .cursor (factory = MyCursor )
61+ cur = self .con .cursor ()
62+ self .assertIsInstance (cur , sqlite .Cursor )
63+ cur = self .con .cursor (MyCursor )
64+ self .assertIsInstance (cur , MyCursor )
65+ cur = self .con .cursor (factory = lambda con : MyCursor (con ))
6266 self .assertIsInstance (cur , MyCursor )
6367
68+ def CheckInvalidFactory (self ):
69+ # not a callable at all
70+ self .assertRaises (TypeError , self .con .cursor , None )
71+ # invalid callable with not exact one argument
72+ self .assertRaises (TypeError , self .con .cursor , lambda : None )
73+ # invalid callable returning non-cursor
74+ self .assertRaises (TypeError , self .con .cursor , lambda con : None )
75+
6476class RowFactoryTestsBackwardsCompat (unittest .TestCase ):
6577 def setUp (self ):
6678 self .con = sqlite .connect (":memory:" )
@@ -183,10 +195,12 @@ def CheckSqliteRowAsSequence(self):
183195 def CheckFakeCursorClass (self ):
184196 # Issue #24257: Incorrect use of PyObject_IsInstance() caused
185197 # segmentation fault.
198+ # Issue #27861: Also applies for cursor factory.
186199 class FakeCursor (str ):
187200 __class__ = sqlite .Cursor
188- cur = self .con .cursor (factory = FakeCursor )
189- self .assertRaises (TypeError , sqlite .Row , cur , ())
201+ self .con .row_factory = sqlite .Row
202+ self .assertRaises (TypeError , self .con .cursor , FakeCursor )
203+ self .assertRaises (TypeError , sqlite .Row , FakeCursor (), ())
190204
191205 def tearDown (self ):
192206 self .con .close ()
0 commit comments