|
1 | 1 | #-*- coding: ISO-8859-1 -*- |
2 | 2 | # pysqlite2/test/dbapi.py: tests for DB-API compliance |
3 | 3 | # |
4 | | -# Copyright (C) 2004-2007 Gerhard Häring <gh@ghaering.de> |
| 4 | +# Copyright (C) 2004-2010 Gerhard Häring <gh@ghaering.de> |
5 | 5 | # |
6 | 6 | # This file is part of pysqlite. |
7 | 7 | # |
@@ -653,13 +653,13 @@ def CheckScriptStringSql(self): |
653 | 653 | res = cur.fetchone()[0] |
654 | 654 | self.assertEqual(res, 5) |
655 | 655 |
|
656 | | - def CheckScriptErrorIncomplete(self): |
| 656 | + def CheckScriptSyntaxError(self): |
657 | 657 | con = sqlite.connect(":memory:") |
658 | 658 | cur = con.cursor() |
659 | 659 | raised = False |
660 | 660 | try: |
661 | | - cur.executescript("create table test(sadfsadfdsa") |
662 | | - except sqlite.ProgrammingError: |
| 661 | + cur.executescript("create table test(x); asdf; create table test2(x)") |
| 662 | + except sqlite.OperationalError: |
663 | 663 | raised = True |
664 | 664 | self.assertEqual(raised, True, "should have raised an exception") |
665 | 665 |
|
@@ -692,7 +692,7 @@ def CheckConnectionExecutescript(self): |
692 | 692 | result = con.execute("select foo from test").fetchone()[0] |
693 | 693 | self.assertEqual(result, 5, "Basic test of Connection.executescript") |
694 | 694 |
|
695 | | -class ClosedTests(unittest.TestCase): |
| 695 | +class ClosedConTests(unittest.TestCase): |
696 | 696 | def setUp(self): |
697 | 697 | pass |
698 | 698 |
|
@@ -744,15 +744,112 @@ def CheckClosedCurExecute(self): |
744 | 744 | except: |
745 | 745 | self.fail("Should have raised a ProgrammingError") |
746 | 746 |
|
| 747 | + def CheckClosedCreateFunction(self): |
| 748 | + con = sqlite.connect(":memory:") |
| 749 | + con.close() |
| 750 | + def f(x): return 17 |
| 751 | + try: |
| 752 | + con.create_function("foo", 1, f) |
| 753 | + self.fail("Should have raised a ProgrammingError") |
| 754 | + except sqlite.ProgrammingError: |
| 755 | + pass |
| 756 | + except: |
| 757 | + self.fail("Should have raised a ProgrammingError") |
| 758 | + |
| 759 | + def CheckClosedCreateAggregate(self): |
| 760 | + con = sqlite.connect(":memory:") |
| 761 | + con.close() |
| 762 | + class Agg: |
| 763 | + def __init__(self): |
| 764 | + pass |
| 765 | + def step(self, x): |
| 766 | + pass |
| 767 | + def finalize(self): |
| 768 | + return 17 |
| 769 | + try: |
| 770 | + con.create_aggregate("foo", 1, Agg) |
| 771 | + self.fail("Should have raised a ProgrammingError") |
| 772 | + except sqlite.ProgrammingError: |
| 773 | + pass |
| 774 | + except: |
| 775 | + self.fail("Should have raised a ProgrammingError") |
| 776 | + |
| 777 | + def CheckClosedSetAuthorizer(self): |
| 778 | + con = sqlite.connect(":memory:") |
| 779 | + con.close() |
| 780 | + def authorizer(*args): |
| 781 | + return sqlite.DENY |
| 782 | + try: |
| 783 | + con.set_authorizer(authorizer) |
| 784 | + self.fail("Should have raised a ProgrammingError") |
| 785 | + except sqlite.ProgrammingError: |
| 786 | + pass |
| 787 | + except: |
| 788 | + self.fail("Should have raised a ProgrammingError") |
| 789 | + |
| 790 | + def CheckClosedSetProgressCallback(self): |
| 791 | + con = sqlite.connect(":memory:") |
| 792 | + con.close() |
| 793 | + def progress(): pass |
| 794 | + try: |
| 795 | + con.set_progress_handler(progress, 100) |
| 796 | + self.fail("Should have raised a ProgrammingError") |
| 797 | + except sqlite.ProgrammingError: |
| 798 | + pass |
| 799 | + except: |
| 800 | + self.fail("Should have raised a ProgrammingError") |
| 801 | + |
| 802 | + def CheckClosedCall(self): |
| 803 | + con = sqlite.connect(":memory:") |
| 804 | + con.close() |
| 805 | + try: |
| 806 | + con() |
| 807 | + self.fail("Should have raised a ProgrammingError") |
| 808 | + except sqlite.ProgrammingError: |
| 809 | + pass |
| 810 | + except: |
| 811 | + self.fail("Should have raised a ProgrammingError") |
| 812 | + |
| 813 | +class ClosedCurTests(unittest.TestCase): |
| 814 | + def setUp(self): |
| 815 | + pass |
| 816 | + |
| 817 | + def tearDown(self): |
| 818 | + pass |
| 819 | + |
| 820 | + def CheckClosed(self): |
| 821 | + con = sqlite.connect(":memory:") |
| 822 | + cur = con.cursor() |
| 823 | + cur.close() |
| 824 | + |
| 825 | + for method_name in ("execute", "executemany", "executescript", "fetchall", "fetchmany", "fetchone"): |
| 826 | + if method_name in ("execute", "executescript"): |
| 827 | + params = ("select 4 union select 5",) |
| 828 | + elif method_name == "executemany": |
| 829 | + params = ("insert into foo(bar) values (?)", [(3,), (4,)]) |
| 830 | + else: |
| 831 | + params = [] |
| 832 | + |
| 833 | + try: |
| 834 | + method = getattr(cur, method_name) |
| 835 | + |
| 836 | + method(*params) |
| 837 | + self.fail("Should have raised a ProgrammingError: method " + method_name) |
| 838 | + except sqlite.ProgrammingError: |
| 839 | + pass |
| 840 | + except: |
| 841 | + self.fail("Should have raised a ProgrammingError: " + method_name) |
| 842 | + |
747 | 843 | def suite(): |
748 | 844 | module_suite = unittest.makeSuite(ModuleTests, "Check") |
749 | 845 | connection_suite = unittest.makeSuite(ConnectionTests, "Check") |
750 | 846 | cursor_suite = unittest.makeSuite(CursorTests, "Check") |
751 | 847 | thread_suite = unittest.makeSuite(ThreadTests, "Check") |
752 | 848 | constructor_suite = unittest.makeSuite(ConstructorTests, "Check") |
753 | 849 | ext_suite = unittest.makeSuite(ExtensionTests, "Check") |
754 | | - closed_suite = unittest.makeSuite(ClosedTests, "Check") |
755 | | - return unittest.TestSuite((module_suite, connection_suite, cursor_suite, thread_suite, constructor_suite, ext_suite, closed_suite)) |
| 850 | + closed_con_suite = unittest.makeSuite(ClosedConTests, "Check") |
| 851 | + closed_cur_suite = unittest.makeSuite(ClosedCurTests, "Check") |
| 852 | + return unittest.TestSuite((module_suite, connection_suite, cursor_suite, thread_suite, constructor_suite, ext_suite, closed_con_suite, closed_cur_suite)) |
756 | 853 |
|
757 | 854 | def test(): |
758 | 855 | runner = unittest.TextTestRunner() |
|
0 commit comments