bpo-45512: Extend sqlite3 test suite regarding isolation levels (GH-29576)

This commit is contained in:
Erlend Egeberg Aasland 2021-11-17 11:01:54 +01:00 committed by GitHub
parent 15409c720b
commit 5f9247e36a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 124 additions and 3 deletions

View file

@ -514,14 +514,35 @@ class ConnectionTests(unittest.TestCase):
"isolation_level string must be '', 'DEFERRED', 'IMMEDIATE', or "
"'EXCLUSIVE'"
)
with self.assertRaisesRegex(ValueError, msg):
memory_database(isolation_level="BOGUS")
levels = (
"BOGUS",
" ",
"DEFERRE",
"IMMEDIAT",
"EXCLUSIV",
"DEFERREDS",
"IMMEDIATES",
"EXCLUSIVES",
)
for level in levels:
with self.subTest(level=level):
with self.assertRaisesRegex(ValueError, msg):
memory_database(isolation_level=level)
with memory_database() as cx:
with self.assertRaisesRegex(ValueError, msg):
cx.isolation_level = level
# Check that the default level is not changed
self.assertEqual(cx.isolation_level, "")
def test_connection_init_good_isolation_levels(self):
for level in ("", "DEFERRED", "IMMEDIATE", "EXCLUSIVE", None):
with self.subTest(level=level):
with memory_database(isolation_level=level) as cx:
cx.execute("select 'ok'")
self.assertEqual(cx.isolation_level, level)
with memory_database() as cx:
self.assertEqual(cx.isolation_level, "")
cx.isolation_level = level
self.assertEqual(cx.isolation_level, level)
def test_connection_reinit(self):
db = ":memory:"