@@ -84,6 +84,7 @@ def CheckNotSupportedError(self):
8484 "NotSupportedError is not a subclass of DatabaseError" )
8585
8686class ConnectionTests (unittest .TestCase ):
87+
8788 def setUp (self ):
8889 self .cx = sqlite .connect (":memory:" )
8990 cu = self .cx .cursor ()
@@ -140,6 +141,28 @@ def CheckExceptions(self):
140141 self .assertEqual (self .cx .ProgrammingError , sqlite .ProgrammingError )
141142 self .assertEqual (self .cx .NotSupportedError , sqlite .NotSupportedError )
142143
144+ def CheckInTransaction (self ):
145+ # Can't use db from setUp because we want to test initial state.
146+ cx = sqlite .connect (":memory:" )
147+ cu = cx .cursor ()
148+ self .assertEqual (cx .in_transaction , False )
149+ cu .execute ("create table transactiontest(id integer primary key, name text)" )
150+ self .assertEqual (cx .in_transaction , False )
151+ cu .execute ("insert into transactiontest(name) values (?)" , ("foo" ,))
152+ self .assertEqual (cx .in_transaction , True )
153+ cu .execute ("select name from transactiontest where name=?" , ["foo" ])
154+ row = cu .fetchone ()
155+ self .assertEqual (cx .in_transaction , True )
156+ cx .commit ()
157+ self .assertEqual (cx .in_transaction , False )
158+ cu .execute ("select name from transactiontest where name=?" , ["foo" ])
159+ row = cu .fetchone ()
160+ self .assertEqual (cx .in_transaction , False )
161+
162+ def CheckInTransactionRO (self ):
163+ with self .assertRaises (AttributeError ):
164+ self .cx .in_transaction = True
165+
143166class CursorTests (unittest .TestCase ):
144167 def setUp (self ):
145168 self .cx = sqlite .connect (":memory:" )
0 commit comments