diff options
author | R. David Murray <rdmurray@bitdance.com> | 2010-06-01 01:32:12 (GMT) |
---|---|---|
committer | R. David Murray <rdmurray@bitdance.com> | 2010-06-01 01:32:12 (GMT) |
commit | d35251dc19b6f2d1cacbb622a578c81f33d8553a (patch) | |
tree | fd24991f9bc92a4f1360c25647ddb159745a8874 /Lib | |
parent | bcb8d3a0a5d2d7e0d962bd9164ea81128472e21c (diff) | |
download | cpython-d35251dc19b6f2d1cacbb622a578c81f33d8553a.zip cpython-d35251dc19b6f2d1cacbb622a578c81f33d8553a.tar.gz cpython-d35251dc19b6f2d1cacbb622a578c81f33d8553a.tar.bz2 |
#8845: expose sqlite3 inTransaction as RO in_transaction Connection attribute.
Patch by R. David Murray, unit tests by Shashwat Anand.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/sqlite3/test/dbapi.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/sqlite3/test/dbapi.py b/Lib/sqlite3/test/dbapi.py index ced6679..51253d0 100644 --- a/Lib/sqlite3/test/dbapi.py +++ b/Lib/sqlite3/test/dbapi.py @@ -84,6 +84,7 @@ class ModuleTests(unittest.TestCase): "NotSupportedError is not a subclass of DatabaseError") class ConnectionTests(unittest.TestCase): + def setUp(self): self.cx = sqlite.connect(":memory:") cu = self.cx.cursor() @@ -140,6 +141,28 @@ class ConnectionTests(unittest.TestCase): self.assertEqual(self.cx.ProgrammingError, sqlite.ProgrammingError) self.assertEqual(self.cx.NotSupportedError, sqlite.NotSupportedError) + def CheckInTransaction(self): + # Can't use db from setUp because we want to test initial state. + cx = sqlite.connect(":memory:") + cu = cx.cursor() + self.assertEqual(cx.in_transaction, False) + cu.execute("create table transactiontest(id integer primary key, name text)") + self.assertEqual(cx.in_transaction, False) + cu.execute("insert into transactiontest(name) values (?)", ("foo",)) + self.assertEqual(cx.in_transaction, True) + cu.execute("select name from transactiontest where name=?", ["foo"]) + row = cu.fetchone() + self.assertEqual(cx.in_transaction, True) + cx.commit() + self.assertEqual(cx.in_transaction, False) + cu.execute("select name from transactiontest where name=?", ["foo"]) + row = cu.fetchone() + self.assertEqual(cx.in_transaction, False) + + def CheckInTransactionRO(self): + with self.assertRaises(AttributeError): + self.cx.in_transaction = True + class CursorTests(unittest.TestCase): def setUp(self): self.cx = sqlite.connect(":memory:") |