diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-09-01 22:21:05 +0300 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-09-01 22:21:05 +0300 |
commit | af0628e045c024fec27432afd1f20c0d08095197 (patch) | |
tree | 67ca762679d23287ed5eb05db2af9e90f2f7749a /Lib/sqlite3 | |
parent | Issue #27919: Deprecate extra_path option in distutils. (diff) | |
parent | Issue #27881: Fixed possible bugs when setting sqlite3.Connection.isolation_l... (diff) | |
download | cpython-af0628e045c024fec27432afd1f20c0d08095197.tar.gz cpython-af0628e045c024fec27432afd1f20c0d08095197.tar.bz2 cpython-af0628e045c024fec27432afd1f20c0d08095197.zip |
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.py | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/Lib/sqlite3/test/regression.py b/Lib/sqlite3/test/regression.py index cb465bad7b3..7dd0050528f 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): """ |