summaryrefslogtreecommitdiffstats
path: root/Lib/sqlite3
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-09-01 19:18:03 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-09-01 19:18:03 (GMT)
commit2891492d2357253fd832485023c78e593660319d (patch)
tree1616614be0767954f930b724fa580ebbcd88afb4 /Lib/sqlite3
parent00b1e0f7ea1523813e3d407bfdefdf55592566af (diff)
downloadcpython-2891492d2357253fd832485023c78e593660319d.zip
cpython-2891492d2357253fd832485023c78e593660319d.tar.gz
cpython-2891492d2357253fd832485023c78e593660319d.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):
"""