Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-44958: Fix ref. leak introduced in GH-27844 #28490

Merged
merged 2 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
61 changes: 33 additions & 28 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,38 +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()
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