summaryrefslogtreecommitdiffstats
path: root/Lib/sqlite3
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-09-01 19:21:05 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-09-01 19:21:05 (GMT)
commitaf0628e045c024fec27432afd1f20c0d08095197 (patch)
tree67ca762679d23287ed5eb05db2af9e90f2f7749a /Lib/sqlite3
parent5c071c1ff4c96ccd9d5a1ae381a3bb3ac4590223 (diff)
parent2891492d2357253fd832485023c78e593660319d (diff)
downloadcpython-af0628e045c024fec27432afd1f20c0d08095197.zip
cpython-af0628e045c024fec27432afd1f20c0d08095197.tar.gz
cpython-af0628e045c024fec27432afd1f20c0d08095197.tar.bz2
Issue #27881: Fixed possible bugs when setting sqlite3.Connection.isolation_level.
Based on patch by Xiang Zhang.
Diffstat (limited to 'Lib/sqlite3')
-rw-r--r--Lib/sqlite3/test/regression.py31
1 files changed, 27 insertions, 4 deletions
diff --git a/Lib/sqlite3/test/regression.py b/Lib/sqlite3/test/regression.py
index cb465ba..7dd0050 100644
--- a/Lib/sqlite3/test/regression.py
+++ b/Lib/sqlite3/test/regression.py
@@ -146,11 +146,34 @@ class RegressionTests(unittest.TestCase):
self.assertRaises(TypeError, sqlite.register_adapter, {}, None)
def CheckSetIsolationLevel(self):
- """
- See issue 3312.
- """
+ # See issue 27881.
+ class CustomStr(str):
+ def upper(self):
+ return None
+ def __del__(self):
+ con.isolation_level = ""
+
con = sqlite.connect(":memory:")
- setattr(con, "isolation_level", "\xe9")
+ con.isolation_level = None
+ for level in "", "DEFERRED", "IMMEDIATE", "EXCLUSIVE":
+ with self.subTest(level=level):
+ con.isolation_level = level
+ con.isolation_level = level.lower()
+ con.isolation_level = level.capitalize()
+ con.isolation_level = CustomStr(level)
+
+ # setting isolation_level failure should not alter previous state
+ con.isolation_level = None
+ con.isolation_level = "DEFERRED"
+ pairs = [
+ (1, TypeError), (b'', TypeError), ("abc", ValueError),
+ ("IMMEDIATE\0EXCLUSIVE", ValueError), ("\xe9", ValueError),
+ ]
+ for value, exc in pairs:
+ with self.subTest(level=value):
+ with self.assertRaises(exc):
+ con.isolation_level = value
+ self.assertEqual(con.isolation_level, "DEFERRED")
def CheckCursorConstructorCallCheck(self):
"""