mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
#8845: expose sqlite3 inTransaction as RO in_transaction Connection attribute.
Patch by R. David Murray, unit tests by Shashwat Anand.
This commit is contained in:
parent
bcb8d3a0a5
commit
d35251dc19
6 changed files with 50 additions and 1 deletions
|
@ -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:")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue