Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
bpo-44958: Fix ref. leak in test_table_lock_cursor_non_readonly_select()
Modify managed_connect() helper to support in-memory databases. Use it
for the regression tests added in GH-27844.
  • Loading branch information
Erlend E. Aasland committed Sep 21, 2021
commit 24e0e12fe1e4c130d8adcbd509ae176cd95052fd
5 changes: 3 additions & 2 deletions Lib/sqlite3/test/test_dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@

# Helper for tests using TESTFN
@contextlib.contextmanager
def managed_connect(*args, **kwargs):
def managed_connect(*args, in_mem=False, **kwargs):
cx = sqlite.connect(*args, **kwargs)
try:
yield cx
finally:
cx.close()
unlink(TESTFN)
if not in_mem:
unlink(TESTFN)


class ModuleTests(unittest.TestCase):
Expand Down
62 changes: 33 additions & 29 deletions Lib/sqlite3/test/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import functools
from test import support

from .test_dbapi import managed_connect

class RegressionTests(unittest.TestCase):
def setUp(self):
self.con = sqlite.connect(":memory:")
Expand Down Expand Up @@ -437,39 +439,41 @@ def test_return_empty_bytestring(self):
self.assertEqual(val, b'')

def test_table_lock_cursor_replace_stmt(self):
con = sqlite.connect(":memory:")
cur = con.cursor()
cur.execute("create table t(t)")
cur.executemany("insert into t values(?)", ((v,) for v in range(5)))
con.commit()
cur.execute("select t from t")
cur.execute("drop table t")
con.commit()
with managed_connect(":memory:", in_mem=True) as con:
cur = con.cursor()
cur.execute("create table t(t)")
cur.executemany("insert into t values(?)",
((v,) for v in range(5)))
con.commit()
cur.execute("select t from t")
cur.execute("drop table t")
con.commit()

def test_table_lock_cursor_dealloc(self):
con = sqlite.connect(":memory:")
con.execute("create table t(t)")
con.executemany("insert into t values(?)", ((v,) for v in range(5)))
con.commit()
cur = con.execute("select t from t")
del cur
con.execute("drop table t")
con.commit()
with managed_connect(":memory:", in_mem=True) as con:
con.execute("create table t(t)")
con.executemany("insert into t values(?)",
((v,) for v in range(5)))
con.commit()
cur = con.execute("select t from t")
del cur
con.execute("drop table t")
con.commit()

def test_table_lock_cursor_non_readonly_select(self):
con = sqlite.connect(":memory:")
con.execute("create table t(t)")
con.executemany("insert into t values(?)", ((v,) for v in range(5)))
con.commit()
def dup(v):
con.execute("insert into t values(?)", (v,))
return
con.create_function("dup", 1, dup)
cur = con.execute("select dup(t) from t")
del cur
con.execute("drop table t")
con.commit()
con.close()
with managed_connect(":memory:", in_mem=True) as con:
con.execute("create table t(t)")
con.executemany("insert into t values(?)",
((v,) for v in range(5)))
con.commit()
def dup(v):
con.execute("insert into t values(?)", (v,))
return
con.create_function("dup", 1, dup)
cur = con.execute("select dup(t) from t")
del cur
con.execute("drop table t")
con.commit()


if __name__ == "__main__":
Expand Down