mirror of
https://github.com/python/cpython.git
synced 2025-07-25 20:24:11 +00:00

svn+ssh://pythondev@svn.python.org/python/trunk ........ r62127 | trent.nelson | 2008-04-03 08:39:17 -0700 (Thu, 03 Apr 2008) | 1 line Remove the building of Berkeley DB step; _bsddb44.vcproj takes care of this for us now. ........ r62136 | amaury.forgeotdarc | 2008-04-03 16:07:55 -0700 (Thu, 03 Apr 2008) | 9 lines #1733757: the interpreter would hang on shutdown, if the function set by sys.settrace calls threading.currentThread. The correction somewhat improves the code, but it was close. Many thanks to the "with" construct, which turns python code into C calls. I wonder if it is not better to sys.settrace(None) just after running the __main__ module and before finalization. ........ r62141 | jeffrey.yasskin | 2008-04-03 21:51:19 -0700 (Thu, 03 Apr 2008) | 5 lines Doh! os.read() raises an OSError, not an IOError when it's interrupted. And fix some flakiness in test_itimer_prof, which could detect that the timer had reached 0 before the signal arrived announcing that fact. ........ r62142 | fred.drake | 2008-04-03 22:41:30 -0700 (Thu, 03 Apr 2008) | 4 lines - Issue #2385: distutils.core.run_script() makes __file__ available, so the controlled environment will more closely mirror the typical script environment. This supports setup.py scripts that refer to data files. ........ r62147 | fred.drake | 2008-04-04 04:31:14 -0700 (Fri, 04 Apr 2008) | 6 lines my previous change did what I said it should not: it changed the current directory to the directory in which the setup.py script lived (which made __file__ wrong) fixed, with test that the script is run in the current directory of the caller ........ r62148 | fred.drake | 2008-04-04 04:38:51 -0700 (Fri, 04 Apr 2008) | 2 lines stupid, stupid, stupid! ........ r62150 | jeffrey.yasskin | 2008-04-04 09:48:19 -0700 (Fri, 04 Apr 2008) | 2 lines Oops again. EINTR is in errno, not signal. ........ r62158 | andrew.kuchling | 2008-04-04 19:42:20 -0700 (Fri, 04 Apr 2008) | 1 line Minor edits ........ r62159 | andrew.kuchling | 2008-04-04 19:47:07 -0700 (Fri, 04 Apr 2008) | 1 line Markup fix; explain what interval timers do; typo fix ........ r62160 | andrew.kuchling | 2008-04-04 20:38:39 -0700 (Fri, 04 Apr 2008) | 1 line Various edits ........ r62161 | neal.norwitz | 2008-04-04 21:26:31 -0700 (Fri, 04 Apr 2008) | 9 lines Prevent test_sqlite from hanging on older versions of sqlite. The problem is that when trying to do the second insert, sqlite seems to sleep for a very long time. Here is the output from strace: read(6, "SQLite format 3\0\4\0\1\1\0@ \0\0\0\1\0\0\0\0"..., 1024) = 1024 nanosleep({4294, 966296000}, <unfinished ...> I don't know which version this was fixed in, but 3.2.1 definitely fails. ........
184 lines
6.5 KiB
Python
184 lines
6.5 KiB
Python
#-*- coding: ISO-8859-1 -*-
|
|
# pysqlite2/test/transactions.py: tests transactions
|
|
#
|
|
# Copyright (C) 2005-2007 Gerhard Häring <gh@ghaering.de>
|
|
#
|
|
# This file is part of pysqlite.
|
|
#
|
|
# This software is provided 'as-is', without any express or implied
|
|
# warranty. In no event will the authors be held liable for any damages
|
|
# arising from the use of this software.
|
|
#
|
|
# Permission is granted to anyone to use this software for any purpose,
|
|
# including commercial applications, and to alter it and redistribute it
|
|
# freely, subject to the following restrictions:
|
|
#
|
|
# 1. The origin of this software must not be misrepresented; you must not
|
|
# claim that you wrote the original software. If you use this software
|
|
# in a product, an acknowledgment in the product documentation would be
|
|
# appreciated but is not required.
|
|
# 2. Altered source versions must be plainly marked as such, and must not be
|
|
# misrepresented as being the original software.
|
|
# 3. This notice may not be removed or altered from any source distribution.
|
|
|
|
import os, unittest
|
|
import sqlite3 as sqlite
|
|
|
|
def get_db_path():
|
|
return "sqlite_testdb"
|
|
|
|
class TransactionTests(unittest.TestCase):
|
|
def setUp(self):
|
|
try:
|
|
os.remove(get_db_path())
|
|
except OSError:
|
|
pass
|
|
|
|
self.con1 = sqlite.connect(get_db_path(), timeout=0.1)
|
|
self.cur1 = self.con1.cursor()
|
|
|
|
self.con2 = sqlite.connect(get_db_path(), timeout=0.1)
|
|
self.cur2 = self.con2.cursor()
|
|
|
|
def tearDown(self):
|
|
self.cur1.close()
|
|
self.con1.close()
|
|
|
|
self.cur2.close()
|
|
self.con2.close()
|
|
|
|
try:
|
|
os.unlink(get_db_path())
|
|
except OSError:
|
|
pass
|
|
|
|
def CheckDMLdoesAutoCommitBefore(self):
|
|
self.cur1.execute("create table test(i)")
|
|
self.cur1.execute("insert into test(i) values (5)")
|
|
self.cur1.execute("create table test2(j)")
|
|
self.cur2.execute("select i from test")
|
|
res = self.cur2.fetchall()
|
|
self.failUnlessEqual(len(res), 1)
|
|
|
|
def CheckInsertStartsTransaction(self):
|
|
self.cur1.execute("create table test(i)")
|
|
self.cur1.execute("insert into test(i) values (5)")
|
|
self.cur2.execute("select i from test")
|
|
res = self.cur2.fetchall()
|
|
self.failUnlessEqual(len(res), 0)
|
|
|
|
def CheckUpdateStartsTransaction(self):
|
|
self.cur1.execute("create table test(i)")
|
|
self.cur1.execute("insert into test(i) values (5)")
|
|
self.con1.commit()
|
|
self.cur1.execute("update test set i=6")
|
|
self.cur2.execute("select i from test")
|
|
res = self.cur2.fetchone()[0]
|
|
self.failUnlessEqual(res, 5)
|
|
|
|
def CheckDeleteStartsTransaction(self):
|
|
self.cur1.execute("create table test(i)")
|
|
self.cur1.execute("insert into test(i) values (5)")
|
|
self.con1.commit()
|
|
self.cur1.execute("delete from test")
|
|
self.cur2.execute("select i from test")
|
|
res = self.cur2.fetchall()
|
|
self.failUnlessEqual(len(res), 1)
|
|
|
|
def CheckReplaceStartsTransaction(self):
|
|
self.cur1.execute("create table test(i)")
|
|
self.cur1.execute("insert into test(i) values (5)")
|
|
self.con1.commit()
|
|
self.cur1.execute("replace into test(i) values (6)")
|
|
self.cur2.execute("select i from test")
|
|
res = self.cur2.fetchall()
|
|
self.failUnlessEqual(len(res), 1)
|
|
self.failUnlessEqual(res[0][0], 5)
|
|
|
|
def CheckToggleAutoCommit(self):
|
|
self.cur1.execute("create table test(i)")
|
|
self.cur1.execute("insert into test(i) values (5)")
|
|
self.con1.isolation_level = None
|
|
self.failUnlessEqual(self.con1.isolation_level, None)
|
|
self.cur2.execute("select i from test")
|
|
res = self.cur2.fetchall()
|
|
self.failUnlessEqual(len(res), 1)
|
|
|
|
self.con1.isolation_level = "DEFERRED"
|
|
self.failUnlessEqual(self.con1.isolation_level , "DEFERRED")
|
|
self.cur1.execute("insert into test(i) values (5)")
|
|
self.cur2.execute("select i from test")
|
|
res = self.cur2.fetchall()
|
|
self.failUnlessEqual(len(res), 1)
|
|
|
|
def CheckRaiseTimeout(self):
|
|
if sqlite.sqlite_version_info < (3, 2, 2):
|
|
# This will fail (hang) on earlier versions of sqlite.
|
|
# Determine exact version it was fixed. 3.2.1 hangs.
|
|
return
|
|
self.cur1.execute("create table test(i)")
|
|
self.cur1.execute("insert into test(i) values (5)")
|
|
try:
|
|
self.cur2.execute("insert into test(i) values (5)")
|
|
self.fail("should have raised an OperationalError")
|
|
except sqlite.OperationalError:
|
|
pass
|
|
except:
|
|
self.fail("should have raised an OperationalError")
|
|
|
|
def CheckLocking(self):
|
|
"""
|
|
This tests the improved concurrency with pysqlite 2.3.4. You needed
|
|
to roll back con2 before you could commit con1.
|
|
"""
|
|
if sqlite.sqlite_version_info < (3, 2, 2):
|
|
# This will fail (hang) on earlier versions of sqlite.
|
|
# Determine exact version it was fixed. 3.2.1 hangs.
|
|
return
|
|
self.cur1.execute("create table test(i)")
|
|
self.cur1.execute("insert into test(i) values (5)")
|
|
try:
|
|
self.cur2.execute("insert into test(i) values (5)")
|
|
self.fail("should have raised an OperationalError")
|
|
except sqlite.OperationalError:
|
|
pass
|
|
except:
|
|
self.fail("should have raised an OperationalError")
|
|
# NO self.con2.rollback() HERE!!!
|
|
self.con1.commit()
|
|
|
|
class SpecialCommandTests(unittest.TestCase):
|
|
def setUp(self):
|
|
self.con = sqlite.connect(":memory:")
|
|
self.cur = self.con.cursor()
|
|
|
|
def CheckVacuum(self):
|
|
self.cur.execute("create table test(i)")
|
|
self.cur.execute("insert into test(i) values (5)")
|
|
self.cur.execute("vacuum")
|
|
|
|
def CheckDropTable(self):
|
|
self.cur.execute("create table test(i)")
|
|
self.cur.execute("insert into test(i) values (5)")
|
|
self.cur.execute("drop table test")
|
|
|
|
def CheckPragma(self):
|
|
self.cur.execute("create table test(i)")
|
|
self.cur.execute("insert into test(i) values (5)")
|
|
self.cur.execute("pragma count_changes=1")
|
|
|
|
def tearDown(self):
|
|
self.cur.close()
|
|
self.con.close()
|
|
|
|
def suite():
|
|
default_suite = unittest.makeSuite(TransactionTests, "Check")
|
|
special_command_suite = unittest.makeSuite(SpecialCommandTests, "Check")
|
|
return unittest.TestSuite((default_suite, special_command_suite))
|
|
|
|
def test():
|
|
runner = unittest.TextTestRunner()
|
|
runner.run(suite())
|
|
|
|
if __name__ == "__main__":
|
|
test()
|