bpo-44958: Fix ref. leak introduced in GH-27844 (GH-28490) · python/cpython@3e3ff09 (original) (raw)
`@@ -28,6 +28,8 @@
`
28
28
`import functools
`
29
29
`from test import support
`
30
30
``
``
31
`+
from .test_dbapi import managed_connect
`
``
32
+
31
33
`class RegressionTests(unittest.TestCase):
`
32
34
`def setUp(self):
`
33
35
`self.con = sqlite.connect(":memory:")
`
`@@ -437,38 +439,41 @@ def test_return_empty_bytestring(self):
`
437
439
`self.assertEqual(val, b'')
`
438
440
``
439
441
`def test_table_lock_cursor_replace_stmt(self):
`
440
``
`-
con = sqlite.connect(":memory:")
`
441
``
`-
cur = con.cursor()
`
442
``
`-
cur.execute("create table t(t)")
`
443
``
`-
cur.executemany("insert into t values(?)", ((v,) for v in range(5)))
`
444
``
`-
con.commit()
`
445
``
`-
cur.execute("select t from t")
`
446
``
`-
cur.execute("drop table t")
`
447
``
`-
con.commit()
`
``
442
`+
with managed_connect(":memory:", in_mem=True) as con:
`
``
443
`+
cur = con.cursor()
`
``
444
`+
cur.execute("create table t(t)")
`
``
445
`+
cur.executemany("insert into t values(?)",
`
``
446
`+
((v,) for v in range(5)))
`
``
447
`+
con.commit()
`
``
448
`+
cur.execute("select t from t")
`
``
449
`+
cur.execute("drop table t")
`
``
450
`+
con.commit()
`
448
451
``
449
452
`def test_table_lock_cursor_dealloc(self):
`
450
``
`-
con = sqlite.connect(":memory:")
`
451
``
`-
con.execute("create table t(t)")
`
452
``
`-
con.executemany("insert into t values(?)", ((v,) for v in range(5)))
`
453
``
`-
con.commit()
`
454
``
`-
cur = con.execute("select t from t")
`
455
``
`-
del cur
`
456
``
`-
con.execute("drop table t")
`
457
``
`-
con.commit()
`
``
453
`+
with managed_connect(":memory:", in_mem=True) as con:
`
``
454
`+
con.execute("create table t(t)")
`
``
455
`+
con.executemany("insert into t values(?)",
`
``
456
`+
((v,) for v in range(5)))
`
``
457
`+
con.commit()
`
``
458
`+
cur = con.execute("select t from t")
`
``
459
`+
del cur
`
``
460
`+
con.execute("drop table t")
`
``
461
`+
con.commit()
`
458
462
``
459
463
`def test_table_lock_cursor_non_readonly_select(self):
`
460
``
`-
con = sqlite.connect(":memory:")
`
461
``
`-
con.execute("create table t(t)")
`
462
``
`-
con.executemany("insert into t values(?)", ((v,) for v in range(5)))
`
463
``
`-
con.commit()
`
464
``
`-
def dup(v):
`
465
``
`-
con.execute("insert into t values(?)", (v,))
`
466
``
`-
return
`
467
``
`-
con.create_function("dup", 1, dup)
`
468
``
`-
cur = con.execute("select dup(t) from t")
`
469
``
`-
del cur
`
470
``
`-
con.execute("drop table t")
`
471
``
`-
con.commit()
`
``
464
`+
with managed_connect(":memory:", in_mem=True) as con:
`
``
465
`+
con.execute("create table t(t)")
`
``
466
`+
con.executemany("insert into t values(?)",
`
``
467
`+
((v,) for v in range(5)))
`
``
468
`+
con.commit()
`
``
469
`+
def dup(v):
`
``
470
`+
con.execute("insert into t values(?)", (v,))
`
``
471
`+
return
`
``
472
`+
con.create_function("dup", 1, dup)
`
``
473
`+
cur = con.execute("select dup(t) from t")
`
``
474
`+
del cur
`
``
475
`+
con.execute("drop table t")
`
``
476
`+
con.commit()
`
472
477
``
473
478
``
474
479
`if name == "main":
`