Skip to content

Commit ca98adb

Browse files
authored
Cleanup
1 parent 0ee6e3d commit ca98adb

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

Lib/test/datetimetester.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7155,8 +7155,8 @@ def test_datetime_from_timestamp(self):
71557155

71567156
self.assertEqual(dt_orig, dt_rt)
71577157

7158-
def assert_python_in_subinterp(self, check_if_ok, script, init='',
7159-
fini='', repeat=1, config='isolated'):
7158+
def assert_python_ok_in_subinterp(self, script, init='', fini='',
7159+
repeat=1, config='isolated'):
71607160
# iOS requires the use of the custom framework loader,
71617161
# not the ExtensionFileLoader.
71627162
if sys.platform == "ios":
@@ -7177,7 +7177,7 @@ def assert_python_in_subinterp(self, check_if_ok, script, init='',
71777177
spec = importlib.util.spec_from_loader(fullname, loader)
71787178
_testcapi = importlib.util.module_from_spec(spec)
71797179
spec.loader.exec_module(_testcapi)
7180-
INDEX = $INDEX$
7180+
run_counter = $RUN_COUNTER$
71817181
setup = _testcapi.test_datetime_capi_newinterp # call it if needed
71827182
$SCRIPT$
71837183
"""
@@ -7187,8 +7187,8 @@ def assert_python_in_subinterp(self, check_if_ok, script, init='',
71877187
setup = _testcapi.test_datetime_capi_newinterp
71887188
$INIT$
71897189
7190-
for idx in range({repeat}):
7191-
subcode = subinterp_code.replace('$INDEX$', str(idx))
7190+
for i in range(1, {1+repeat}):
7191+
subcode = subinterp_code.replace('$RUN_COUNTER$', str(i))
71927192
if {_interpreters is None}:
71937193
ret = support.run_in_subinterp(subcode)
71947194
else:
@@ -7201,10 +7201,7 @@ def assert_python_in_subinterp(self, check_if_ok, script, init='',
72017201
code = code.replace('$INIT$', init).replace('$FINI$', fini)
72027202
code = code.replace('$SCRIPT$', script)
72037203

7204-
if check_if_ok:
7205-
res = script_helper.assert_python_ok('-c', code)
7206-
else:
7207-
res = script_helper.assert_python_failure('-c', code)
7204+
res = script_helper.assert_python_ok('-c', code)
72087205
return res
72097206

72107207
def test_type_check_in_subinterp(self):
@@ -7221,10 +7218,10 @@ def run(type_checker, obj):
72217218
run(_testcapi.datetime_check_delta, _datetime.timedelta(1))
72227219
run(_testcapi.datetime_check_tzinfo, _datetime.tzinfo())
72237220
""")
7224-
self.assert_python_in_subinterp(True, script)
7221+
self.assert_python_ok_in_subinterp(script)
72257222
if _interpreters is not None:
72267223
with self.subTest(name := 'legacy'):
7227-
self.assert_python_in_subinterp(True, script, config=name)
7224+
self.assert_python_ok_in_subinterp(script, config=name)
72287225

72297226

72307227
class ExtensionModuleTests(unittest.TestCase):
@@ -7233,8 +7230,8 @@ def setUp(self):
72337230
if self.__class__.__name__.endswith('Pure'):
72347231
self.skipTest('Not relevant in pure Python')
72357232

7236-
def assert_python_in_subinterp(self, *args, **kwargs):
7237-
return CapiTest.assert_python_in_subinterp(self, *args, **kwargs)
7233+
def assert_python_ok_in_subinterp(self, *args, **kwargs):
7234+
return CapiTest.assert_python_ok_in_subinterp(self, *args, **kwargs)
72387235

72397236
@support.cpython_only
72407237
def test_gh_120161(self):
@@ -7337,25 +7334,25 @@ def test_static_type_on_subinterp(self):
73377334
""")
73387335
with_setup = 'setup()' + script
73397336
with self.subTest('[PyDateTime_IMPORT] main: no, sub: yes'):
7340-
self.assert_python_in_subinterp(True, with_setup)
7337+
self.assert_python_ok_in_subinterp(with_setup)
73417338

73427339
with self.subTest('[PyDateTime_IMPORT] main: yes, sub: yes'):
73437340
# Fails if the setup() means test_datetime_capi() rather than
73447341
# test_datetime_capi_newinterp()
7345-
self.assert_python_in_subinterp(True, with_setup, 'setup()')
7346-
self.assert_python_in_subinterp(True, 'setup()', fini=with_setup)
7347-
self.assert_python_in_subinterp(True, with_setup, repeat=2)
7342+
self.assert_python_ok_in_subinterp(with_setup, 'setup()')
7343+
self.assert_python_ok_in_subinterp('setup()', fini=with_setup)
7344+
self.assert_python_ok_in_subinterp(with_setup, repeat=2)
73487345

73497346
with_import = 'import _datetime' + script
73507347
with self.subTest('Explicit import'):
7351-
self.assert_python_in_subinterp(True, with_import, 'setup()')
7348+
self.assert_python_ok_in_subinterp(with_import, 'setup()')
73527349

73537350
with_import = textwrap.dedent("""
73547351
timedelta = _testcapi.get_capi_types()['timedelta']
73557352
timedelta(days=1)
73567353
""") + script
73577354
with self.subTest('Implicit import'):
7358-
self.assert_python_in_subinterp(True, with_import, 'setup()')
7355+
self.assert_python_ok_in_subinterp(with_import, 'setup()')
73597356

73607357

73617358
def load_tests(loader, standard_tests, pattern):

0 commit comments

Comments
 (0)