Skip to content

Commit fb35703

Browse files
committed
Redirect to the CapiTest method
1 parent 1dd9707 commit fb35703

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

Lib/test/datetimetester.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7301,26 +7301,30 @@ def test_update_type_cache(self):
73017301
res = script_helper.assert_python_ok('-c', script)
73027302
self.assertFalse(res.err)
73037303

7304+
def assert_python_in_subinterp(self, *args, **kwargs):
7305+
return CapiTest.assert_python_in_subinterp(self, *args, **kwargs)
7306+
73047307
def test_static_type_attr_on_subinterp(self):
73057308
script = textwrap.dedent(f"""
73067309
date = _testcapi.get_capi_types()['date']
73077310
date.today
73087311
""")
73097312
# Fail before loaded
73107313
with self.subTest('[PyDateTime_IMPORT] main: yes, sub: no'):
7311-
CapiTest.assert_python_in_subinterp(self, False, script)
7314+
self.assert_python_in_subinterp(False, script)
73127315

73137316
# OK after loaded
73147317
script2 = f'_testcapi.test_datetime_capi()\n{script}'
73157318
with self.subTest('[PyDateTime_IMPORT] main: no, sub: yes'):
7316-
CapiTest.assert_python_in_subinterp(self, True, script2, '')
7319+
self.assert_python_in_subinterp(True, script2, setup='')
73177320

73187321
with self.subTest('[PyDateTime_IMPORT] main: yes, sub: yes'):
7319-
CapiTest.assert_python_in_subinterp(self, True, script2)
7322+
# Check if each test_datetime_capi() calls PyDateTime_IMPORT
7323+
self.assert_python_in_subinterp(True, script2)
73207324

73217325
script3 = f'import _datetime\n{script}'
73227326
with self.subTest('Regular import'):
7323-
CapiTest.assert_python_in_subinterp(self, True, script3)
7327+
self.assert_python_in_subinterp(True, script3)
73247328

73257329
def test_static_type_at_shutdown1(self):
73267330
# gh-132413
@@ -7377,17 +7381,18 @@ def gen():
73777381
it = gen()
73787382
next(it)
73797383
""")
7380-
with self.subTest('PyDateTime_IMPORT by MainInterpreter'):
7381-
res = CapiTest.assert_python_in_subinterp(self, True, script)
7384+
with self.subTest('[PyDateTime_IMPORT] main: yes, sub: no'):
7385+
res = self.assert_python_in_subinterp(True, script)
73827386
self.assertIn(b'ImportError: sys.meta_path is None', res.err)
73837387

73847388
script2 = f'_testcapi.test_datetime_capi()\n{script}'
7385-
with self.subTest('PyDateTime_IMPORT by Subinterpreter'):
7386-
res = CapiTest.assert_python_in_subinterp(self, True, script2, '')
7389+
with self.subTest('[PyDateTime_IMPORT] main: no, sub: yes'):
7390+
res = self.assert_python_in_subinterp(True, script2, setup='')
73877391
self.assertFalse(res.err)
73887392

7389-
with self.subTest('PyDateTime_IMPORT by Main/Sub'):
7390-
res = CapiTest.assert_python_in_subinterp(self, True, script2, '')
7393+
with self.subTest('[PyDateTime_IMPORT] main: yes, sub: yes'):
7394+
# Check if each test_datetime_capi() calls PyDateTime_IMPORT
7395+
res = self.assert_python_in_subinterp(True, script2)
73917396
self.assertFalse(res.err)
73927397

73937398
def test_static_type_before_shutdown(self):
@@ -7398,7 +7403,7 @@ def test_static_type_before_shutdown(self):
73987403
timedelta(days=1)
73997404
assert '_datetime' in sys.modules
74007405
""")
7401-
CapiTest.assert_python_in_subinterp(self, True, script)
7406+
self.assert_python_in_subinterp(True, script)
74027407

74037408
def test_module_free(self):
74047409
script = textwrap.dedent("""

0 commit comments

Comments
 (0)