@@ -581,158 +581,54 @@ class ThreadTests(unittest.TestCase):
581
581
def setUp (self ):
582
582
self .con = sqlite .connect (":memory:" )
583
583
self .cur = self .con .cursor ()
584
- self .cur .execute ("create table test(id integer primary key, name text, bin binary, ratio number, ts timestamp )" )
584
+ self .cur .execute ("create table test(name text)" )
585
585
586
586
def tearDown (self ):
587
587
self .cur .close ()
588
588
self .con .close ()
589
589
590
- def test_con_cursor (self ):
591
- def run (con , errors ):
592
- try :
593
- cur = con .cursor ()
594
- errors .append ("did not raise ProgrammingError" )
595
- return
596
- except sqlite .ProgrammingError :
597
- return
598
- except :
599
- errors .append ("raised wrong exception" )
600
-
601
- errors = []
602
- t = threading .Thread (target = run , kwargs = {"con" : self .con , "errors" : errors })
603
- t .start ()
604
- t .join ()
605
- if len (errors ) > 0 :
606
- self .fail ("\n " .join (errors ))
607
-
608
- def test_con_commit (self ):
609
- def run (con , errors ):
610
- try :
611
- con .commit ()
612
- errors .append ("did not raise ProgrammingError" )
613
- return
614
- except sqlite .ProgrammingError :
615
- return
616
- except :
617
- errors .append ("raised wrong exception" )
618
-
619
- errors = []
620
- t = threading .Thread (target = run , kwargs = {"con" : self .con , "errors" : errors })
621
- t .start ()
622
- t .join ()
623
- if len (errors ) > 0 :
624
- self .fail ("\n " .join (errors ))
625
-
626
- def test_con_rollback (self ):
627
- def run (con , errors ):
628
- try :
629
- con .rollback ()
630
- errors .append ("did not raise ProgrammingError" )
631
- return
632
- except sqlite .ProgrammingError :
633
- return
634
- except :
635
- errors .append ("raised wrong exception" )
636
-
637
- errors = []
638
- t = threading .Thread (target = run , kwargs = {"con" : self .con , "errors" : errors })
639
- t .start ()
640
- t .join ()
641
- if len (errors ) > 0 :
642
- self .fail ("\n " .join (errors ))
643
-
644
- def test_con_close (self ):
645
- def run (con , errors ):
646
- try :
647
- con .close ()
648
- errors .append ("did not raise ProgrammingError" )
649
- return
650
- except sqlite .ProgrammingError :
651
- return
652
- except :
653
- errors .append ("raised wrong exception" )
654
-
655
- errors = []
656
- t = threading .Thread (target = run , kwargs = {"con" : self .con , "errors" : errors })
657
- t .start ()
658
- t .join ()
659
- if len (errors ) > 0 :
660
- self .fail ("\n " .join (errors ))
661
-
662
- def test_cur_implicit_begin (self ):
663
- def run (cur , errors ):
664
- try :
665
- cur .execute ("insert into test(name) values ('a')" )
666
- errors .append ("did not raise ProgrammingError" )
667
- return
668
- except sqlite .ProgrammingError :
669
- return
670
- except :
671
- errors .append ("raised wrong exception" )
672
-
673
- errors = []
674
- t = threading .Thread (target = run , kwargs = {"cur" : self .cur , "errors" : errors })
675
- t .start ()
676
- t .join ()
677
- if len (errors ) > 0 :
678
- self .fail ("\n " .join (errors ))
679
-
680
- def test_cur_close (self ):
681
- def run (cur , errors ):
682
- try :
683
- cur .close ()
684
- errors .append ("did not raise ProgrammingError" )
685
- return
686
- except sqlite .ProgrammingError :
687
- return
688
- except :
689
- errors .append ("raised wrong exception" )
690
-
691
- errors = []
692
- t = threading .Thread (target = run , kwargs = {"cur" : self .cur , "errors" : errors })
693
- t .start ()
694
- t .join ()
695
- if len (errors ) > 0 :
696
- self .fail ("\n " .join (errors ))
697
-
698
- def test_cur_execute (self ):
699
- def run (cur , errors ):
590
+ @threading_helper .reap_threads
591
+ def _run_test (self , fn , * args , ** kwds ):
592
+ def run (err ):
700
593
try :
701
- cur .execute ("select name from test" )
702
- errors .append ("did not raise ProgrammingError" )
703
- return
594
+ fn (* args , ** kwds )
595
+ err .append ("did not raise ProgrammingError" )
704
596
except sqlite .ProgrammingError :
705
- return
597
+ pass
706
598
except :
707
- errors .append ("raised wrong exception" )
599
+ err .append ("raised wrong exception" )
708
600
709
- errors = []
710
- self .cur .execute ("insert into test(name) values ('a')" )
711
- t = threading .Thread (target = run , kwargs = {"cur" : self .cur , "errors" : errors })
601
+ err = []
602
+ t = threading .Thread (target = run , kwargs = {"err" : err })
712
603
t .start ()
713
604
t .join ()
714
- if len (errors ) > 0 :
715
- self .fail ("\n " .join (errors ))
716
-
717
- def test_cur_iter_next (self ):
718
- def run (cur , errors ):
719
- try :
720
- row = cur .fetchone ()
721
- errors .append ("did not raise ProgrammingError" )
722
- return
723
- except sqlite .ProgrammingError :
724
- return
725
- except :
726
- errors .append ("raised wrong exception" )
605
+ if err :
606
+ self .fail ("\n " .join (err ))
607
+
608
+ def test_check_connection_thread (self ):
609
+ fns = [
610
+ lambda : self .con .cursor (),
611
+ lambda : self .con .commit (),
612
+ lambda : self .con .rollback (),
613
+ lambda : self .con .close (),
614
+ lambda : self .con .set_trace_callback (None ),
615
+ lambda : self .con .create_collation ("foo" , None ),
616
+ ]
617
+ for fn in fns :
618
+ with self .subTest (fn = fn ):
619
+ self ._run_test (fn )
620
+
621
+ def test_check_cursor_thread (self ):
622
+ fns = [
623
+ lambda : self .cur .execute ("insert into test(name) values('a')" ),
624
+ lambda : self .cur .close (),
625
+ lambda : self .cur .execute ("select name from test" ),
626
+ lambda : self .cur .fetchone (),
627
+ ]
628
+ for fn in fns :
629
+ with self .subTest (fn = fn ):
630
+ self ._run_test (fn )
727
631
728
- errors = []
729
- self .cur .execute ("insert into test(name) values ('a')" )
730
- self .cur .execute ("select name from test" )
731
- t = threading .Thread (target = run , kwargs = {"cur" : self .cur , "errors" : errors })
732
- t .start ()
733
- t .join ()
734
- if len (errors ) > 0 :
735
- self .fail ("\n " .join (errors ))
736
632
737
633
@threading_helper .reap_threads
738
634
def test_dont_check_same_thread (self ):
0 commit comments