bpo-40956: Convert sqlite3.connect and sqlite3.Connection.__init__ to AC (GH-24421)

This commit is contained in:
Erlend Egeberg Aasland 2021-06-20 21:24:00 +02:00 committed by GitHub
parent 09eb817115
commit 185ecdc146
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 298 additions and 71 deletions

View file

@ -27,6 +27,7 @@ import threading
import unittest
from test.support.os_helper import TESTFN, unlink
from test.support import threading_helper
# Helper for tests using TESTFN
@ -224,6 +225,10 @@ class OpenTests(unittest.TestCase):
with managed_connect(f"file:{TESTFN}?mode=ro", uri=True) as cx:
cx.execute(self._sql)
def test_database_keyword(self):
with sqlite.connect(database=":memory:") as cx:
self.assertEqual(type(cx), sqlite.Connection)
class CursorTests(unittest.TestCase):
def setUp(self):
@ -724,6 +729,22 @@ class ThreadTests(unittest.TestCase):
if len(errors) > 0:
self.fail("\n".join(errors))
@threading_helper.reap_threads
def test_dont_check_same_thread(self):
def run(con, err):
try:
con.execute("select 1")
except sqlite.Error:
err.append("multi-threading not allowed")
con = sqlite.connect(":memory:", check_same_thread=False)
err = []
t = threading.Thread(target=run, kwargs={"con": con, "err": err})
t.start()
t.join()
self.assertEqual(len(err), 0, "\n".join(err))
class ConstructorTests(unittest.TestCase):
def test_date(self):
d = sqlite.Date(2004, 10, 28)