aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/sqlite3/test/dbapi.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/sqlite3/test/dbapi.py')
-rw-r--r--Lib/sqlite3/test/dbapi.py58
1 files changed, 31 insertions, 27 deletions
diff --git a/Lib/sqlite3/test/dbapi.py b/Lib/sqlite3/test/dbapi.py
index c356d4706c4..202bd388760 100644
--- a/Lib/sqlite3/test/dbapi.py
+++ b/Lib/sqlite3/test/dbapi.py
@@ -22,7 +22,6 @@
# 3. This notice may not be removed or altered from any source distribution.
import unittest
-import sys
import sqlite3 as sqlite
try:
import threading
@@ -44,12 +43,12 @@ class ModuleTests(unittest.TestCase):
sqlite.paramstyle)
def CheckWarning(self):
- self.assertTrue(issubclass(sqlite.Warning, StandardError),
- "Warning is not a subclass of StandardError")
+ self.assertTrue(issubclass(sqlite.Warning, Exception),
+ "Warning is not a subclass of Exception")
def CheckError(self):
- self.assertTrue(issubclass(sqlite.Error, StandardError),
- "Error is not a subclass of StandardError")
+ self.assertTrue(issubclass(sqlite.Error, Exception),
+ "Error is not a subclass of Exception")
def CheckInterfaceError(self):
self.assertTrue(issubclass(sqlite.InterfaceError, sqlite.Error),
@@ -85,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()
@@ -141,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:")
@@ -260,10 +282,6 @@ class CursorTests(unittest.TestCase):
self.assertEqual(row[0], "foo")
def CheckExecuteDictMapping_Mapping(self):
- # Test only works with Python 2.5 or later
- if sys.version_info < (2, 5, 0):
- return
-
class D(dict):
def __missing__(self, key):
return "foo"
@@ -339,7 +357,7 @@ class CursorTests(unittest.TestCase):
def __init__(self):
self.value = 5
- def next(self):
+ def __next__(self):
if self.value == 10:
raise StopIteration
else:
@@ -379,8 +397,8 @@ class CursorTests(unittest.TestCase):
self.fail("should have raised a TypeError")
except TypeError:
return
- except Exception, e:
- print "raised", e.__class__
+ except Exception as e:
+ print("raised", e.__class__)
self.fail("raised wrong exception.")
def CheckFetchIter(self):
@@ -653,7 +671,7 @@ class ConstructorTests(unittest.TestCase):
ts = sqlite.TimestampFromTicks(42)
def CheckBinary(self):
- b = sqlite.Binary(chr(0) + "'")
+ b = sqlite.Binary(b"\0'")
class ExtensionTests(unittest.TestCase):
def CheckScriptStringSql(self):
@@ -669,20 +687,6 @@ class ExtensionTests(unittest.TestCase):
res = cur.fetchone()[0]
self.assertEqual(res, 5)
- def CheckScriptStringUnicode(self):
- con = sqlite.connect(":memory:")
- cur = con.cursor()
- cur.executescript(u"""
- create table a(i);
- insert into a(i) values (5);
- select i from a;
- delete from a;
- insert into a(i) values (6);
- """)
- cur.execute("select i from a")
- res = cur.fetchone()[0]
- self.assertEqual(res, 6)
-
def CheckScriptSyntaxError(self):
con = sqlite.connect(":memory:")
cur = con.cursor()