@@ -489,36 +489,27 @@ def test_executescript_step_through_select(self):
489
489
490
490
class ConverterProgrammingErrorTestCase (unittest .TestCase ):
491
491
def setUp (self ):
492
- self .con = sqlite .connect (' :memory:' , detect_types = sqlite .PARSE_COLNAMES )
492
+ self .con = sqlite .connect (" :memory:" , detect_types = sqlite .PARSE_COLNAMES )
493
493
self .cur = self .con .cursor ()
494
- self .cur .execute ('create table test(x foo)' )
494
+ self .cur .execute ("create table test(x foo)" )
495
+ self .cur .executemany ("insert into test(x) values (?)" , [("foo" ,), ("bar" ,)])
495
496
496
- sqlite .converters [' CURSOR_INIT' ] = lambda x : self .cur .__init__ (self .con )
497
- sqlite .converters [' CURSOR_CLOSE' ] = lambda x : self .cur .close ()
498
- sqlite .converters [' CURSOR_ITER' ] = lambda x , l = []: self .cur .fetchone () if l else l .append (None )
497
+ sqlite .converters [" CURSOR_INIT" ] = lambda x : self .cur .__init__ (self .con )
498
+ sqlite .converters [" CURSOR_CLOSE" ] = lambda x : self .cur .close ()
499
+ sqlite .converters [" CURSOR_ITER" ] = lambda x , l = []: self .cur .fetchone () if l else l .append (None )
499
500
500
501
def tearDown (self ):
501
- del sqlite .converters [' CURSOR_INIT' ]
502
- del sqlite .converters [' CURSOR_CLOSE' ]
503
- del sqlite .converters [' CURSOR_ITER' ]
502
+ del sqlite .converters [" CURSOR_INIT" ]
503
+ del sqlite .converters [" CURSOR_CLOSE" ]
504
+ del sqlite .converters [" CURSOR_ITER" ]
504
505
self .cur .close ()
505
506
self .con .close ()
506
507
507
- def test_cursor_init (self ):
508
- self .cur .execute ('insert into test(x) values (?)' , ('foo' ,))
509
- with self .assertRaises (sqlite .ProgrammingError ):
510
- self .cur .execute ('select x as "x [CURSOR_INIT]", x from test' )
511
-
512
- def test_cursor_close (self ):
513
- self .cur .execute ('insert into test(x) values (?)' , ('foo' ,))
514
- with self .assertRaises (sqlite .ProgrammingError ):
515
- self .cur .execute ('select x as "x [CURSOR_CLOSE]", x from test' )
516
-
517
- def test_cursor_iter (self ):
518
- self .cur .executemany ('insert into test(x) values (?)' , (('foo' ,),) * 2 )
519
- self .cur .execute ('select x as "x [CURSOR_ITER]", x from test' )
520
- with self .assertRaises (sqlite .ProgrammingError ):
521
- self .cur .fetchone ()
508
+ def test_recursive_cursor_usage (self ):
509
+ for converter in "CURSOR_INIT" , "CURSOR_CLOSE" , "CURSOR_ITER" :
510
+ with self .subTest (converter = converter ):
511
+ self .cur .execute (f'select x as "x [{ converter } ]", x from test' )
512
+ self .assertRaises (sqlite .ProgrammingError , self .cur .fetchall )
522
513
523
514
524
515
if __name__ == "__main__" :
0 commit comments