Mercurial > cpython-lru_cache-weakref
annotate Lib/sqlite3/test/hooks.py @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | ce023c95db9f |
| children | 649937bb8f1c |
| rev | line source |
|---|---|
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1 #-*- coding: ISO-8859-1 -*- |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
2 # pysqlite2/test/hooks.py: tests for various SQLite-specific hooks |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
3 # |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
4 # Copyright (C) 2006-2007 Gerhard Häring <gh@ghaering.de> |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
5 # |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
6 # This file is part of pysqlite. |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
7 # |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
8 # This software is provided 'as-is', without any express or implied |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
9 # warranty. In no event will the authors be held liable for any damages |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
10 # arising from the use of this software. |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
11 # |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
12 # Permission is granted to anyone to use this software for any purpose, |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
13 # including commercial applications, and to alter it and redistribute it |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
14 # freely, subject to the following restrictions: |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
15 # |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
16 # 1. The origin of this software must not be misrepresented; you must not |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
17 # claim that you wrote the original software. If you use this software |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
18 # in a product, an acknowledgment in the product documentation would be |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
19 # appreciated but is not required. |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
20 # 2. Altered source versions must be plainly marked as such, and must not be |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
21 # misrepresented as being the original software. |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
22 # 3. This notice may not be removed or altered from any source distribution. |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
23 |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
24 import os, unittest |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
25 import sqlite3 as sqlite |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
26 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
27 class CollationTests(unittest.TestCase): |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
28 def setUp(self): |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
29 pass |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
30 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
31 def tearDown(self): |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
32 pass |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
33 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
34 def CheckCreateCollationNotCallable(self): |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
35 con = sqlite.connect(":memory:") |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
36 try: |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
37 con.create_collation("X", 42) |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
38 self.fail("should have raised a TypeError") |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
39 except TypeError, e: |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
45580
diff
changeset
|
40 self.assertEqual(e.args[0], "parameter must be callable") |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
41 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
42 def CheckCreateCollationNotAscii(self): |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
43 con = sqlite.connect(":memory:") |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
44 try: |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
45 con.create_collation("collä", cmp) |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
46 self.fail("should have raised a ProgrammingError") |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
47 except sqlite.ProgrammingError, e: |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
48 pass |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
49 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
50 def CheckCollationIsUsed(self): |
|
38839
d4b1f9a31c29
Re-revert this change. Install the version check and don't run the test
Neal Norwitz <nnorwitz@gmail.com>
parents:
38835
diff
changeset
|
51 if sqlite.version_info < (3, 2, 1): # old SQLite versions crash on this test |
|
d4b1f9a31c29
Re-revert this change. Install the version check and don't run the test
Neal Norwitz <nnorwitz@gmail.com>
parents:
38835
diff
changeset
|
52 return |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
53 def mycoll(x, y): |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
54 # reverse order |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
55 return -cmp(x, y) |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
56 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
57 con = sqlite.connect(":memory:") |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
58 con.create_collation("mycoll", mycoll) |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
59 sql = """ |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
60 select x from ( |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
61 select 'a' as x |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
62 union |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
63 select 'b' as x |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
64 union |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
65 select 'c' as x |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
66 ) order by x collate mycoll |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
67 """ |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
68 result = con.execute(sql).fetchall() |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
69 if result[0][0] != "c" or result[1][0] != "b" or result[2][0] != "a": |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
70 self.fail("the expected order was not returned") |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
71 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
72 con.create_collation("mycoll", None) |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
73 try: |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
74 result = con.execute(sql).fetchall() |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
75 self.fail("should have raised an OperationalError") |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
76 except sqlite.OperationalError, e: |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
45580
diff
changeset
|
77 self.assertEqual(e.args[0].lower(), "no such collation sequence: mycoll") |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
78 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
79 def CheckCollationRegisterTwice(self): |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
80 """ |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
81 Register two different collation functions under the same name. |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
82 Verify that the last one is actually used. |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
83 """ |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
84 con = sqlite.connect(":memory:") |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
85 con.create_collation("mycoll", cmp) |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
86 con.create_collation("mycoll", lambda x, y: -cmp(x, y)) |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
87 result = con.execute(""" |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
88 select x from (select 'a' as x union select 'b' as x) order by x collate mycoll |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
89 """).fetchall() |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
90 if result[0][0] != 'b' or result[1][0] != 'a': |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
91 self.fail("wrong collation function is used") |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
92 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
93 def CheckDeregisterCollation(self): |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
94 """ |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
95 Register a collation, then deregister it. Make sure an error is raised if we try |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
96 to use it. |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
97 """ |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
98 con = sqlite.connect(":memory:") |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
99 con.create_collation("mycoll", cmp) |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
100 con.create_collation("mycoll", None) |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
101 try: |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
102 con.execute("select 'a' as x union select 'b' as x order by x collate mycoll") |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
103 self.fail("should have raised an OperationalError") |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
104 except sqlite.OperationalError, e: |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
105 if not e.args[0].startswith("no such collation sequence"): |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
106 self.fail("wrong OperationalError raised") |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
107 |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
108 class ProgressTests(unittest.TestCase): |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
109 def CheckProgressHandlerUsed(self): |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
110 """ |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
111 Test that the progress handler is invoked once it is set. |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
112 """ |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
113 con = sqlite.connect(":memory:") |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
114 progress_calls = [] |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
115 def progress(): |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
116 progress_calls.append(None) |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
117 return 0 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
118 con.set_progress_handler(progress, 1) |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
119 con.execute(""" |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
120 create table foo(a, b) |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
121 """) |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
45580
diff
changeset
|
122 self.assertTrue(progress_calls) |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
123 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
124 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
125 def CheckOpcodeCount(self): |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
126 """ |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
127 Test that the opcode argument is respected. |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
128 """ |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
129 con = sqlite.connect(":memory:") |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
130 progress_calls = [] |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
131 def progress(): |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
132 progress_calls.append(None) |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
133 return 0 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
134 con.set_progress_handler(progress, 1) |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
135 curs = con.cursor() |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
136 curs.execute(""" |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
137 create table foo (a, b) |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
138 """) |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
139 first_count = len(progress_calls) |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
140 progress_calls = [] |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
141 con.set_progress_handler(progress, 2) |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
142 curs.execute(""" |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
143 create table bar (a, b) |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
144 """) |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
145 second_count = len(progress_calls) |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
45580
diff
changeset
|
146 self.assertTrue(first_count > second_count) |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
147 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
148 def CheckCancelOperation(self): |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
149 """ |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
150 Test that returning a non-zero value stops the operation in progress. |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
151 """ |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
152 con = sqlite.connect(":memory:") |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
153 progress_calls = [] |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
154 def progress(): |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
155 progress_calls.append(None) |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
156 return 1 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
157 con.set_progress_handler(progress, 1) |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
158 curs = con.cursor() |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
159 self.assertRaises( |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
160 sqlite.OperationalError, |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
161 curs.execute, |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
162 "create table bar (a, b)") |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
163 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
164 def CheckClearHandler(self): |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
165 """ |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
166 Test that setting the progress handler to None clears the previously set handler. |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
167 """ |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
168 con = sqlite.connect(":memory:") |
|
75007
ce023c95db9f
Fix a variable scoping error in an sqlite3 test
Petri Lehtinen <petri@digip.org>
parents:
55106
diff
changeset
|
169 action = [] |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
170 def progress(): |
|
75007
ce023c95db9f
Fix a variable scoping error in an sqlite3 test
Petri Lehtinen <petri@digip.org>
parents:
55106
diff
changeset
|
171 action.append(1) |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
172 return 0 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
173 con.set_progress_handler(progress, 1) |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
174 con.set_progress_handler(None, 1) |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
175 con.execute("select 1 union select 2 union select 3").fetchall() |
|
75007
ce023c95db9f
Fix a variable scoping error in an sqlite3 test
Petri Lehtinen <petri@digip.org>
parents:
55106
diff
changeset
|
176 self.assertEqual(len(action), 0, "progress handler was not cleared") |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
177 |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
178 def suite(): |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
179 collation_suite = unittest.makeSuite(CollationTests, "Check") |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
180 progress_suite = unittest.makeSuite(ProgressTests, "Check") |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
45468
diff
changeset
|
181 return unittest.TestSuite((collation_suite, progress_suite)) |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
182 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
183 def test(): |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
184 runner = unittest.TextTestRunner() |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
185 runner.run(suite()) |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
186 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
187 if __name__ == "__main__": |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
188 test() |
