blob: b27486d5b87ee551645b0b487ef44002da81bce9 [file] [log] [blame]
Anthony Baxterc51ee692006-04-01 00:57:31 +00001#-*- coding: ISO-8859-1 -*-
2# pysqlite2/test/dbapi.py: tests for DB-API compliance
3#
Gerhard Häring1cc60ed2008-02-29 22:08:41 +00004# Copyright (C) 2004-2007 Gerhard Häring <gh@ghaering.de>
Anthony Baxterc51ee692006-04-01 00:57:31 +00005#
6# This file is part of pysqlite.
7#
8# This software is provided 'as-is', without any express or implied
9# warranty. In no event will the authors be held liable for any damages
10# arising from the use of this software.
11#
12# Permission is granted to anyone to use this software for any purpose,
13# including commercial applications, and to alter it and redistribute it
14# freely, subject to the following restrictions:
15#
16# 1. The origin of this software must not be misrepresented; you must not
17# claim that you wrote the original software. If you use this software
18# in a product, an acknowledgment in the product documentation would be
19# appreciated but is not required.
20# 2. Altered source versions must be plainly marked as such, and must not be
21# misrepresented as being the original software.
22# 3. This notice may not be removed or altered from any source distribution.
23
24import unittest
Gerhard Häring1cc60ed2008-02-29 22:08:41 +000025import sys
Anthony Baxterc51ee692006-04-01 00:57:31 +000026import threading
27import sqlite3 as sqlite
28
29class ModuleTests(unittest.TestCase):
30 def CheckAPILevel(self):
31 self.assertEqual(sqlite.apilevel, "2.0",
32 "apilevel is %s, should be 2.0" % sqlite.apilevel)
33
34 def CheckThreadSafety(self):
35 self.assertEqual(sqlite.threadsafety, 1,
36 "threadsafety is %d, should be 1" % sqlite.threadsafety)
37
38 def CheckParamStyle(self):
39 self.assertEqual(sqlite.paramstyle, "qmark",
40 "paramstyle is '%s', should be 'qmark'" %
41 sqlite.paramstyle)
42
43 def CheckWarning(self):
44 self.assert_(issubclass(sqlite.Warning, StandardError),
45 "Warning is not a subclass of StandardError")
46
47 def CheckError(self):
48 self.failUnless(issubclass(sqlite.Error, StandardError),
49 "Error is not a subclass of StandardError")
50
51 def CheckInterfaceError(self):
52 self.failUnless(issubclass(sqlite.InterfaceError, sqlite.Error),
53 "InterfaceError is not a subclass of Error")
54
55 def CheckDatabaseError(self):
56 self.failUnless(issubclass(sqlite.DatabaseError, sqlite.Error),
57 "DatabaseError is not a subclass of Error")
58
59 def CheckDataError(self):
60 self.failUnless(issubclass(sqlite.DataError, sqlite.DatabaseError),
61 "DataError is not a subclass of DatabaseError")
62
63 def CheckOperationalError(self):
64 self.failUnless(issubclass(sqlite.OperationalError, sqlite.DatabaseError),
65 "OperationalError is not a subclass of DatabaseError")
66
67 def CheckIntegrityError(self):
68 self.failUnless(issubclass(sqlite.IntegrityError, sqlite.DatabaseError),
69 "IntegrityError is not a subclass of DatabaseError")
70
71 def CheckInternalError(self):
72 self.failUnless(issubclass(sqlite.InternalError, sqlite.DatabaseError),
73 "InternalError is not a subclass of DatabaseError")
74
75 def CheckProgrammingError(self):
76 self.failUnless(issubclass(sqlite.ProgrammingError, sqlite.DatabaseError),
77 "ProgrammingError is not a subclass of DatabaseError")
78
79 def CheckNotSupportedError(self):
80 self.failUnless(issubclass(sqlite.NotSupportedError,
81 sqlite.DatabaseError),
82 "NotSupportedError is not a subclass of DatabaseError")
83
84class ConnectionTests(unittest.TestCase):
85 def setUp(self):
86 self.cx = sqlite.connect(":memory:")
87 cu = self.cx.cursor()
88 cu.execute("create table test(id integer primary key, name text)")
89 cu.execute("insert into test(name) values (?)", ("foo",))
90
91 def tearDown(self):
92 self.cx.close()
93
94 def CheckCommit(self):
95 self.cx.commit()
96
97 def CheckCommitAfterNoChanges(self):
98 """
99 A commit should also work when no changes were made to the database.
100 """
101 self.cx.commit()
102 self.cx.commit()
103
104 def CheckRollback(self):
105 self.cx.rollback()
106
107 def CheckRollbackAfterNoChanges(self):
108 """
109 A rollback should also work when no changes were made to the database.
110 """
111 self.cx.rollback()
112 self.cx.rollback()
113
114 def CheckCursor(self):
115 cu = self.cx.cursor()
116
117 def CheckFailedOpen(self):
118 YOU_CANNOT_OPEN_THIS = "/foo/bar/bla/23534/mydb.db"
119 try:
120 con = sqlite.connect(YOU_CANNOT_OPEN_THIS)
121 except sqlite.OperationalError:
122 return
123 self.fail("should have raised an OperationalError")
124
125 def CheckClose(self):
126 self.cx.close()
127
128 def CheckExceptions(self):
129 # Optional DB-API extension.
130 self.failUnlessEqual(self.cx.Warning, sqlite.Warning)
131 self.failUnlessEqual(self.cx.Error, sqlite.Error)
132 self.failUnlessEqual(self.cx.InterfaceError, sqlite.InterfaceError)
133 self.failUnlessEqual(self.cx.DatabaseError, sqlite.DatabaseError)
134 self.failUnlessEqual(self.cx.DataError, sqlite.DataError)
135 self.failUnlessEqual(self.cx.OperationalError, sqlite.OperationalError)
136 self.failUnlessEqual(self.cx.IntegrityError, sqlite.IntegrityError)
137 self.failUnlessEqual(self.cx.InternalError, sqlite.InternalError)
138 self.failUnlessEqual(self.cx.ProgrammingError, sqlite.ProgrammingError)
139 self.failUnlessEqual(self.cx.NotSupportedError, sqlite.NotSupportedError)
140
141class CursorTests(unittest.TestCase):
142 def setUp(self):
143 self.cx = sqlite.connect(":memory:")
144 self.cu = self.cx.cursor()
145 self.cu.execute("create table test(id integer primary key, name text, income number)")
146 self.cu.execute("insert into test(name) values (?)", ("foo",))
147
148 def tearDown(self):
149 self.cu.close()
150 self.cx.close()
151
152 def CheckExecuteNoArgs(self):
153 self.cu.execute("delete from test")
154
155 def CheckExecuteIllegalSql(self):
156 try:
157 self.cu.execute("select asdf")
158 self.fail("should have raised an OperationalError")
159 except sqlite.OperationalError:
160 return
161 except:
162 self.fail("raised wrong exception")
163
164 def CheckExecuteTooMuchSql(self):
165 try:
166 self.cu.execute("select 5+4; select 4+5")
167 self.fail("should have raised a Warning")
168 except sqlite.Warning:
169 return
170 except:
171 self.fail("raised wrong exception")
172
173 def CheckExecuteTooMuchSql2(self):
174 self.cu.execute("select 5+4; -- foo bar")
175
176 def CheckExecuteTooMuchSql3(self):
177 self.cu.execute("""
178 select 5+4;
179
180 /*
181 foo
182 */
183 """)
184
185 def CheckExecuteWrongSqlArg(self):
186 try:
187 self.cu.execute(42)
188 self.fail("should have raised a ValueError")
189 except ValueError:
190 return
191 except:
192 self.fail("raised wrong exception.")
193
194 def CheckExecuteArgInt(self):
195 self.cu.execute("insert into test(id) values (?)", (42,))
196
197 def CheckExecuteArgFloat(self):
198 self.cu.execute("insert into test(income) values (?)", (2500.32,))
199
200 def CheckExecuteArgString(self):
201 self.cu.execute("insert into test(name) values (?)", ("Hugo",))
202
203 def CheckExecuteWrongNoOfArgs1(self):
204 # too many parameters
205 try:
206 self.cu.execute("insert into test(id) values (?)", (17, "Egon"))
207 self.fail("should have raised ProgrammingError")
208 except sqlite.ProgrammingError:
209 pass
210
211 def CheckExecuteWrongNoOfArgs2(self):
212 # too little parameters
213 try:
214 self.cu.execute("insert into test(id) values (?)")
215 self.fail("should have raised ProgrammingError")
216 except sqlite.ProgrammingError:
217 pass
218
219 def CheckExecuteWrongNoOfArgs3(self):
220 # no parameters, parameters are needed
221 try:
222 self.cu.execute("insert into test(id) values (?)")
223 self.fail("should have raised ProgrammingError")
224 except sqlite.ProgrammingError:
225 pass
226
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000227 def CheckExecuteParamList(self):
228 self.cu.execute("insert into test(name) values ('foo')")
229 self.cu.execute("select name from test where name=?", ["foo"])
230 row = self.cu.fetchone()
231 self.failUnlessEqual(row[0], "foo")
232
233 def CheckExecuteParamSequence(self):
234 class L(object):
235 def __len__(self):
236 return 1
237 def __getitem__(self, x):
238 assert x == 0
239 return "foo"
240
241 self.cu.execute("insert into test(name) values ('foo')")
242 self.cu.execute("select name from test where name=?", L())
243 row = self.cu.fetchone()
244 self.failUnlessEqual(row[0], "foo")
245
Anthony Baxterc51ee692006-04-01 00:57:31 +0000246 def CheckExecuteDictMapping(self):
247 self.cu.execute("insert into test(name) values ('foo')")
248 self.cu.execute("select name from test where name=:name", {"name": "foo"})
249 row = self.cu.fetchone()
250 self.failUnlessEqual(row[0], "foo")
251
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000252 def CheckExecuteDictMapping_Mapping(self):
253 # Test only works with Python 2.5 or later
254 if sys.version_info < (2, 5, 0):
255 return
256
257 class D(dict):
258 def __missing__(self, key):
259 return "foo"
260
261 self.cu.execute("insert into test(name) values ('foo')")
262 self.cu.execute("select name from test where name=:name", D())
263 row = self.cu.fetchone()
264 self.failUnlessEqual(row[0], "foo")
265
Anthony Baxterc51ee692006-04-01 00:57:31 +0000266 def CheckExecuteDictMappingTooLittleArgs(self):
267 self.cu.execute("insert into test(name) values ('foo')")
268 try:
269 self.cu.execute("select name from test where name=:name and id=:id", {"name": "foo"})
270 self.fail("should have raised ProgrammingError")
271 except sqlite.ProgrammingError:
272 pass
273
274 def CheckExecuteDictMappingNoArgs(self):
275 self.cu.execute("insert into test(name) values ('foo')")
276 try:
277 self.cu.execute("select name from test where name=:name")
278 self.fail("should have raised ProgrammingError")
279 except sqlite.ProgrammingError:
280 pass
281
282 def CheckExecuteDictMappingUnnamed(self):
283 self.cu.execute("insert into test(name) values ('foo')")
284 try:
285 self.cu.execute("select name from test where name=?", {"name": "foo"})
286 self.fail("should have raised ProgrammingError")
287 except sqlite.ProgrammingError:
288 pass
289
290 def CheckClose(self):
291 self.cu.close()
292
293 def CheckRowcountExecute(self):
294 self.cu.execute("delete from test")
295 self.cu.execute("insert into test(name) values ('foo')")
296 self.cu.execute("insert into test(name) values ('foo')")
297 self.cu.execute("update test set name='bar'")
298 self.failUnlessEqual(self.cu.rowcount, 2)
299
300 def CheckRowcountExecutemany(self):
301 self.cu.execute("delete from test")
302 self.cu.executemany("insert into test(name) values (?)", [(1,), (2,), (3,)])
303 self.failUnlessEqual(self.cu.rowcount, 3)
304
Anthony Baxter72289a62006-04-04 06:29:05 +0000305 def CheckTotalChanges(self):
306 self.cu.execute("insert into test(name) values ('foo')")
307 self.cu.execute("insert into test(name) values ('foo')")
308 if self.cx.total_changes < 2:
309 self.fail("total changes reported wrong value")
310
Anthony Baxterc51ee692006-04-01 00:57:31 +0000311 # Checks for executemany:
312 # Sequences are required by the DB-API, iterators
313 # enhancements in pysqlite.
314
315 def CheckExecuteManySequence(self):
316 self.cu.executemany("insert into test(income) values (?)", [(x,) for x in range(100, 110)])
317
318 def CheckExecuteManyIterator(self):
319 class MyIter:
320 def __init__(self):
321 self.value = 5
322
323 def next(self):
324 if self.value == 10:
325 raise StopIteration
326 else:
327 self.value += 1
328 return (self.value,)
329
330 self.cu.executemany("insert into test(income) values (?)", MyIter())
331
332 def CheckExecuteManyGenerator(self):
333 def mygen():
334 for i in range(5):
335 yield (i,)
336
337 self.cu.executemany("insert into test(income) values (?)", mygen())
338
339 def CheckExecuteManyWrongSqlArg(self):
340 try:
341 self.cu.executemany(42, [(3,)])
342 self.fail("should have raised a ValueError")
343 except ValueError:
344 return
345 except:
346 self.fail("raised wrong exception.")
347
348 def CheckExecuteManySelect(self):
349 try:
350 self.cu.executemany("select ?", [(3,)])
351 self.fail("should have raised a ProgrammingError")
352 except sqlite.ProgrammingError:
353 return
354 except:
355 self.fail("raised wrong exception.")
356
357 def CheckExecuteManyNotIterable(self):
358 try:
359 self.cu.executemany("insert into test(income) values (?)", 42)
360 self.fail("should have raised a TypeError")
361 except TypeError:
362 return
363 except Exception, e:
364 print "raised", e.__class__
365 self.fail("raised wrong exception.")
366
367 def CheckFetchIter(self):
368 # Optional DB-API extension.
369 self.cu.execute("delete from test")
370 self.cu.execute("insert into test(id) values (?)", (5,))
371 self.cu.execute("insert into test(id) values (?)", (6,))
372 self.cu.execute("select id from test order by id")
373 lst = []
374 for row in self.cu:
375 lst.append(row[0])
376 self.failUnlessEqual(lst[0], 5)
377 self.failUnlessEqual(lst[1], 6)
378
379 def CheckFetchone(self):
380 self.cu.execute("select name from test")
381 row = self.cu.fetchone()
382 self.failUnlessEqual(row[0], "foo")
383 row = self.cu.fetchone()
384 self.failUnlessEqual(row, None)
385
386 def CheckFetchoneNoStatement(self):
387 cur = self.cx.cursor()
388 row = cur.fetchone()
389 self.failUnlessEqual(row, None)
390
391 def CheckArraySize(self):
392 # must default ot 1
393 self.failUnlessEqual(self.cu.arraysize, 1)
394
395 # now set to 2
396 self.cu.arraysize = 2
397
398 # now make the query return 3 rows
399 self.cu.execute("delete from test")
400 self.cu.execute("insert into test(name) values ('A')")
401 self.cu.execute("insert into test(name) values ('B')")
402 self.cu.execute("insert into test(name) values ('C')")
403 self.cu.execute("select name from test")
404 res = self.cu.fetchmany()
405
406 self.failUnlessEqual(len(res), 2)
407
408 def CheckFetchmany(self):
409 self.cu.execute("select name from test")
410 res = self.cu.fetchmany(100)
411 self.failUnlessEqual(len(res), 1)
412 res = self.cu.fetchmany(100)
413 self.failUnlessEqual(res, [])
414
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000415 def CheckFetchmanyKwArg(self):
416 """Checks if fetchmany works with keyword arguments"""
417 self.cu.execute("select name from test")
418 res = self.cu.fetchmany(size=100)
419 self.failUnlessEqual(len(res), 1)
420
Anthony Baxterc51ee692006-04-01 00:57:31 +0000421 def CheckFetchall(self):
422 self.cu.execute("select name from test")
423 res = self.cu.fetchall()
424 self.failUnlessEqual(len(res), 1)
425 res = self.cu.fetchall()
426 self.failUnlessEqual(res, [])
427
428 def CheckSetinputsizes(self):
429 self.cu.setinputsizes([3, 4, 5])
430
431 def CheckSetoutputsize(self):
432 self.cu.setoutputsize(5, 0)
433
434 def CheckSetoutputsizeNoColumn(self):
435 self.cu.setoutputsize(42)
436
437 def CheckCursorConnection(self):
438 # Optional DB-API extension.
439 self.failUnlessEqual(self.cu.connection, self.cx)
440
441 def CheckWrongCursorCallable(self):
442 try:
443 def f(): pass
444 cur = self.cx.cursor(f)
445 self.fail("should have raised a TypeError")
446 except TypeError:
447 return
448 self.fail("should have raised a ValueError")
449
450 def CheckCursorWrongClass(self):
451 class Foo: pass
452 foo = Foo()
453 try:
454 cur = sqlite.Cursor(foo)
455 self.fail("should have raised a ValueError")
456 except TypeError:
457 pass
458
459class ThreadTests(unittest.TestCase):
460 def setUp(self):
461 self.con = sqlite.connect(":memory:")
462 self.cur = self.con.cursor()
463 self.cur.execute("create table test(id integer primary key, name text, bin binary, ratio number, ts timestamp)")
464
465 def tearDown(self):
466 self.cur.close()
467 self.con.close()
468
469 def CheckConCursor(self):
470 def run(con, errors):
471 try:
472 cur = con.cursor()
473 errors.append("did not raise ProgrammingError")
474 return
475 except sqlite.ProgrammingError:
476 return
477 except:
478 errors.append("raised wrong exception")
479
480 errors = []
481 t = threading.Thread(target=run, kwargs={"con": self.con, "errors": errors})
482 t.start()
483 t.join()
484 if len(errors) > 0:
485 self.fail("\n".join(errors))
486
487 def CheckConCommit(self):
488 def run(con, errors):
489 try:
490 con.commit()
491 errors.append("did not raise ProgrammingError")
492 return
493 except sqlite.ProgrammingError:
494 return
495 except:
496 errors.append("raised wrong exception")
497
498 errors = []
499 t = threading.Thread(target=run, kwargs={"con": self.con, "errors": errors})
500 t.start()
501 t.join()
502 if len(errors) > 0:
503 self.fail("\n".join(errors))
504
505 def CheckConRollback(self):
506 def run(con, errors):
507 try:
508 con.rollback()
509 errors.append("did not raise ProgrammingError")
510 return
511 except sqlite.ProgrammingError:
512 return
513 except:
514 errors.append("raised wrong exception")
515
516 errors = []
517 t = threading.Thread(target=run, kwargs={"con": self.con, "errors": errors})
518 t.start()
519 t.join()
520 if len(errors) > 0:
521 self.fail("\n".join(errors))
522
523 def CheckConClose(self):
524 def run(con, errors):
525 try:
526 con.close()
527 errors.append("did not raise ProgrammingError")
528 return
529 except sqlite.ProgrammingError:
530 return
531 except:
532 errors.append("raised wrong exception")
533
534 errors = []
535 t = threading.Thread(target=run, kwargs={"con": self.con, "errors": errors})
536 t.start()
537 t.join()
538 if len(errors) > 0:
539 self.fail("\n".join(errors))
540
541 def CheckCurImplicitBegin(self):
542 def run(cur, errors):
543 try:
544 cur.execute("insert into test(name) values ('a')")
545 errors.append("did not raise ProgrammingError")
546 return
547 except sqlite.ProgrammingError:
548 return
549 except:
550 errors.append("raised wrong exception")
551
552 errors = []
553 t = threading.Thread(target=run, kwargs={"cur": self.cur, "errors": errors})
554 t.start()
555 t.join()
556 if len(errors) > 0:
557 self.fail("\n".join(errors))
558
559 def CheckCurClose(self):
560 def run(cur, errors):
561 try:
562 cur.close()
563 errors.append("did not raise ProgrammingError")
564 return
565 except sqlite.ProgrammingError:
566 return
567 except:
568 errors.append("raised wrong exception")
569
570 errors = []
571 t = threading.Thread(target=run, kwargs={"cur": self.cur, "errors": errors})
572 t.start()
573 t.join()
574 if len(errors) > 0:
575 self.fail("\n".join(errors))
576
577 def CheckCurExecute(self):
578 def run(cur, errors):
579 try:
580 cur.execute("select name from test")
581 errors.append("did not raise ProgrammingError")
582 return
583 except sqlite.ProgrammingError:
584 return
585 except:
586 errors.append("raised wrong exception")
587
588 errors = []
589 self.cur.execute("insert into test(name) values ('a')")
590 t = threading.Thread(target=run, kwargs={"cur": self.cur, "errors": errors})
591 t.start()
592 t.join()
593 if len(errors) > 0:
594 self.fail("\n".join(errors))
595
596 def CheckCurIterNext(self):
597 def run(cur, errors):
598 try:
599 row = cur.fetchone()
600 errors.append("did not raise ProgrammingError")
601 return
602 except sqlite.ProgrammingError:
603 return
604 except:
605 errors.append("raised wrong exception")
606
607 errors = []
608 self.cur.execute("insert into test(name) values ('a')")
609 self.cur.execute("select name from test")
610 t = threading.Thread(target=run, kwargs={"cur": self.cur, "errors": errors})
611 t.start()
612 t.join()
613 if len(errors) > 0:
614 self.fail("\n".join(errors))
615
616class ConstructorTests(unittest.TestCase):
617 def CheckDate(self):
618 d = sqlite.Date(2004, 10, 28)
619
620 def CheckTime(self):
621 t = sqlite.Time(12, 39, 35)
622
623 def CheckTimestamp(self):
624 ts = sqlite.Timestamp(2004, 10, 28, 12, 39, 35)
625
626 def CheckDateFromTicks(self):
627 d = sqlite.DateFromTicks(42)
628
629 def CheckTimeFromTicks(self):
630 t = sqlite.TimeFromTicks(42)
631
632 def CheckTimestampFromTicks(self):
633 ts = sqlite.TimestampFromTicks(42)
634
635 def CheckBinary(self):
636 b = sqlite.Binary(chr(0) + "'")
637
638class ExtensionTests(unittest.TestCase):
639 def CheckScriptStringSql(self):
640 con = sqlite.connect(":memory:")
641 cur = con.cursor()
642 cur.executescript("""
643 -- bla bla
644 /* a stupid comment */
645 create table a(i);
646 insert into a(i) values (5);
647 """)
648 cur.execute("select i from a")
649 res = cur.fetchone()[0]
650 self.failUnlessEqual(res, 5)
651
652 def CheckScriptStringUnicode(self):
653 con = sqlite.connect(":memory:")
654 cur = con.cursor()
655 cur.executescript(u"""
656 create table a(i);
657 insert into a(i) values (5);
658 select i from a;
659 delete from a;
660 insert into a(i) values (6);
661 """)
662 cur.execute("select i from a")
663 res = cur.fetchone()[0]
664 self.failUnlessEqual(res, 6)
665
666 def CheckScriptErrorIncomplete(self):
667 con = sqlite.connect(":memory:")
668 cur = con.cursor()
669 raised = False
670 try:
671 cur.executescript("create table test(sadfsadfdsa")
672 except sqlite.ProgrammingError:
673 raised = True
674 self.failUnlessEqual(raised, True, "should have raised an exception")
675
676 def CheckScriptErrorNormal(self):
677 con = sqlite.connect(":memory:")
678 cur = con.cursor()
679 raised = False
680 try:
681 cur.executescript("create table test(sadfsadfdsa); select foo from hurz;")
682 except sqlite.OperationalError:
683 raised = True
684 self.failUnlessEqual(raised, True, "should have raised an exception")
685
686 def CheckConnectionExecute(self):
687 con = sqlite.connect(":memory:")
688 result = con.execute("select 5").fetchone()[0]
689 self.failUnlessEqual(result, 5, "Basic test of Connection.execute")
690
691 def CheckConnectionExecutemany(self):
692 con = sqlite.connect(":memory:")
693 con.execute("create table test(foo)")
694 con.executemany("insert into test(foo) values (?)", [(3,), (4,)])
695 result = con.execute("select foo from test order by foo").fetchall()
696 self.failUnlessEqual(result[0][0], 3, "Basic test of Connection.executemany")
697 self.failUnlessEqual(result[1][0], 4, "Basic test of Connection.executemany")
698
699 def CheckConnectionExecutescript(self):
700 con = sqlite.connect(":memory:")
701 con.executescript("create table test(foo); insert into test(foo) values (5);")
702 result = con.execute("select foo from test").fetchone()[0]
703 self.failUnlessEqual(result, 5, "Basic test of Connection.executescript")
704
705class ClosedTests(unittest.TestCase):
706 def setUp(self):
707 pass
708
709 def tearDown(self):
710 pass
711
712 def CheckClosedConCursor(self):
713 con = sqlite.connect(":memory:")
714 con.close()
715 try:
716 cur = con.cursor()
717 self.fail("Should have raised a ProgrammingError")
718 except sqlite.ProgrammingError:
719 pass
720 except:
721 self.fail("Should have raised a ProgrammingError")
722
723 def CheckClosedConCommit(self):
724 con = sqlite.connect(":memory:")
725 con.close()
726 try:
727 con.commit()
728 self.fail("Should have raised a ProgrammingError")
729 except sqlite.ProgrammingError:
730 pass
731 except:
732 self.fail("Should have raised a ProgrammingError")
733
734 def CheckClosedConRollback(self):
735 con = sqlite.connect(":memory:")
736 con.close()
737 try:
738 con.rollback()
739 self.fail("Should have raised a ProgrammingError")
740 except sqlite.ProgrammingError:
741 pass
742 except:
743 self.fail("Should have raised a ProgrammingError")
744
745 def CheckClosedCurExecute(self):
746 con = sqlite.connect(":memory:")
747 cur = con.cursor()
748 con.close()
749 try:
750 cur.execute("select 4")
751 self.fail("Should have raised a ProgrammingError")
752 except sqlite.ProgrammingError:
753 pass
754 except:
755 self.fail("Should have raised a ProgrammingError")
756
757def suite():
758 module_suite = unittest.makeSuite(ModuleTests, "Check")
759 connection_suite = unittest.makeSuite(ConnectionTests, "Check")
760 cursor_suite = unittest.makeSuite(CursorTests, "Check")
761 thread_suite = unittest.makeSuite(ThreadTests, "Check")
762 constructor_suite = unittest.makeSuite(ConstructorTests, "Check")
763 ext_suite = unittest.makeSuite(ExtensionTests, "Check")
764 closed_suite = unittest.makeSuite(ClosedTests, "Check")
765 return unittest.TestSuite((module_suite, connection_suite, cursor_suite, thread_suite, constructor_suite, ext_suite, closed_suite))
766
767def test():
768 runner = unittest.TextTestRunner()
769 runner.run(suite())
770
771if __name__ == "__main__":
772 test()