Skip to content

Commit a10fec4

Browse files
committed
improve test docs
1 parent 049e663 commit a10fec4

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

Lib/test/test_sqlite3/test_dbapi.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,8 +1070,8 @@ def test_execute_many_not_iterable(self):
10701070
with self.assertRaises(TypeError):
10711071
self.cu.executemany("insert into test(income) values (?)", 42)
10721072

1073-
@subTests("params_class", (ParamsCxCloseInIterMany, ParamsCxCloseInNext))
1074-
def test_executemany_use_after_close(self, params_class):
1073+
@subTests("params_factory", (ParamsCxCloseInIterMany, ParamsCxCloseInNext))
1074+
def test_executemany_use_after_close(self, params_factory):
10751075
# Prevent SIGSEGV with iterable of parameters closing the connection.
10761076
# Regression test for https://github.com/python/cpython/issues/143198.
10771077
cx = sqlite.connect(":memory:")
@@ -1080,11 +1080,17 @@ def test_executemany_use_after_close(self, params_class):
10801080
cu = cx.cursor()
10811081
msg = r"Cannot operate on a closed database\."
10821082
with self.assertRaisesRegex(sqlite.ProgrammingError, msg):
1083-
cu.executemany("insert into tmp(a) values (?)", params_class(cx))
1083+
cu.executemany("insert into tmp(a) values (?)", params_factory(cx))
10841084

1085+
# The test constructs an iterable of parameters of length 'n'
1086+
# and the connection is closed when we access the j-th one.
1087+
# The iterable is of type 'map' but the test wraps that map
1088+
# with 'iterable_wrapper' to exercise internals.
10851089
@subTests(("j", "n"), ([0, 1], [0, 3], [1, 3], [2, 3]))
1086-
@subTests("wtype", (list, lambda x: x))
1087-
def test_executemany_use_after_close_with_bind_parameters(self, j, n, wtype):
1090+
@subTests("iterable_wrapper", (list, lambda x: x, lambda x: iter(x)))
1091+
def test_executemany_use_after_close_with_bind_parameters(
1092+
self, j, n, iterable_wrapper
1093+
):
10881094
# Prevent SIGSEGV when closing the connection while binding parameters.
10891095
#
10901096
# Internally, the connection's state is checked after bind_parameters().
@@ -1110,7 +1116,7 @@ def __len__(self):
11101116

11111117
cu = cx.cursor()
11121118
msg = r"Cannot operate on a closed database\."
1113-
items = iter(wtype(map(PT, range(n))))
1119+
items = iterable_wrapper(map(PT, range(n)))
11141120
with self.assertRaisesRegex(sqlite.ProgrammingError, msg):
11151121
cu.executemany("insert into tmp(a) values (?)", items)
11161122

@@ -1821,21 +1827,21 @@ def test_connection_executemany(self):
18211827
self.assertEqual(result[0][0], 3, "Basic test of Connection.executemany")
18221828
self.assertEqual(result[1][0], 4, "Basic test of Connection.executemany")
18231829

1824-
@subTests("params_class", (ParamsCxCloseInIterMany, ParamsCxCloseInNext))
1825-
def test_connection_executemany_use_after_close(self, params_class):
1830+
@subTests("params_factory", (ParamsCxCloseInIterMany, ParamsCxCloseInNext))
1831+
def test_connection_executemany_use_after_close(self, params_factory):
18261832
# Prevent SIGSEGV with iterable of parameters closing the connection.
18271833
# Regression test for https://github.com/python/cpython/issues/143198.
18281834
cx = sqlite.connect(":memory:")
18291835
cx.execute("create table tmp(a number)")
18301836
self.addCleanup(cx.close)
18311837
msg = r"Cannot operate on a closed database\."
18321838
with self.assertRaisesRegex(sqlite.ProgrammingError, msg):
1833-
cx.executemany("insert into tmp(a) values (?)", params_class(cx))
1839+
cx.executemany("insert into tmp(a) values (?)", params_factory(cx))
18341840

18351841
@subTests(("j", "n"), ([0, 1], [0, 3], [1, 3], [2, 3]))
1836-
@subTests("wtype", (list, lambda x: x))
1842+
@subTests("iterable_wrapper", (list, lambda x: x))
18371843
def test_connection_executemany_use_after_close_with_bind_parameters(
1838-
self, j, n, wtype,
1844+
self, j, n, iterable_wrapper,
18391845
):
18401846
# See CursorTests.test_executemany_use_after_close_with_bind_parameters().
18411847

@@ -1853,7 +1859,7 @@ def __getitem__(self, i):
18531859
def __len__(self):
18541860
return 1
18551861

1856-
items = iter(wtype(map(PT, range(n))))
1862+
items = iterable_wrapper(map(PT, range(n)))
18571863
msg = r"Cannot operate on a closed database\."
18581864
with self.assertRaisesRegex(sqlite.ProgrammingError, msg):
18591865
cx.executemany("insert into tmp(a) values (?)", items)

0 commit comments

Comments
 (0)