Skip to content

Commit f22edc1

Browse files
committed
minimize test
1 parent d9121b1 commit f22edc1

File tree

2 files changed

+4
-84
lines changed

2 files changed

+4
-84
lines changed

Lib/test/datetimetester.py

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7275,61 +7275,24 @@ def test_update_type_cache(self):
72757275
""")
72767276
script_helper.assert_python_ok('-c', script)
72777277

7278-
def test_module_free(self):
7279-
script = textwrap.dedent("""
7280-
import sys
7281-
import gc
7282-
import weakref
7283-
ws = weakref.WeakSet()
7284-
for _ in range(3):
7285-
import _datetime
7286-
timedelta = _datetime.timedelta # static type
7287-
ws.add(_datetime)
7288-
del sys.modules['_datetime']
7289-
del _datetime
7290-
gc.collect()
7291-
assert len(ws) == 0
7292-
""")
7293-
script_helper.assert_python_ok('-c', script)
7294-
7295-
@unittest.skipIf(not support.Py_DEBUG, "Debug builds only")
7296-
def test_no_leak(self):
7297-
script = textwrap.dedent("""
7298-
import datetime
7299-
datetime.datetime.strptime('20000101', '%Y%m%d').strftime('%Y%m%d')
7300-
""")
7301-
res = script_helper.assert_python_ok('-X', 'showrefcount', '-c', script)
7302-
self.assertIn(b'[0 refs, 0 blocks]', res.err)
7303-
73047278
def test_static_type_at_shutdown(self):
73057279
# gh-132413
73067280
script = textwrap.dedent("""
7307-
import sys
73087281
import _datetime
73097282
timedelta = _datetime.timedelta
73107283
73117284
def gen():
73127285
try:
73137286
yield
73147287
finally:
7315-
# Exceptions are ignored here
7316-
assert not sys.modules
7317-
td = _datetime.timedelta(days=1)
7318-
assert td.days == 1
7319-
td = timedelta(days=1)
7320-
assert td.days == 1
7321-
assert not sys.modules
7288+
# sys.modules is empty
7289+
_datetime.timedelta(days=1)
7290+
timedelta(days=1)
73227291
73237292
it = gen()
73247293
next(it)
73257294
""")
7326-
res = script_helper.assert_python_ok('-c', script)
7327-
self.assertFalse(res.err)
7328-
7329-
if support.Py_DEBUG:
7330-
with self.subTest('Refleak'):
7331-
res = script_helper.assert_python_ok('-X', 'showrefcount', '-c', script)
7332-
self.assertIn(b'[0 refs, 0 blocks]', res.err)
7295+
script_helper.assert_python_ok('-c', script)
73337296

73347297

73357298
def load_tests(loader, standard_tests, pattern):

Lib/test/test_embed.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -440,49 +440,6 @@ def test_datetime_reset_strptime(self):
440440
out, err = self.run_embedded_interpreter("test_repeated_init_exec", code)
441441
self.assertEqual(out, '20000101\n' * INIT_LOOPS)
442442

443-
def test_datetime_capi_type_address(self):
444-
# Check if the C-API types keep their addresses until runtime shutdown
445-
code = textwrap.dedent("""
446-
import _datetime as d
447-
print(
448-
f'{id(d.date)}'
449-
f'{id(d.time)}'
450-
f'{id(d.datetime)}'
451-
f'{id(d.timedelta)}'
452-
f'{id(d.tzinfo)}'
453-
)
454-
""")
455-
out, err = self.run_embedded_interpreter("test_repeated_init_exec", code)
456-
self.assertEqual(len(set(out.splitlines())), 1)
457-
458-
def test_datetime_capi_at_shutdown(self):
459-
# gh-132413: Users need to call PyDateTime_IMPORT every time
460-
# after starting an interpreter.
461-
code = textwrap.dedent("""
462-
import sys
463-
import _testcapi
464-
_testcapi.test_datetime_capi() # PyDateTime_IMPORT only once
465-
timedelta = type(_testcapi.get_delta_fromdsu(False, 1, 0, 0))
466-
467-
def gen():
468-
try:
469-
yield
470-
finally:
471-
assert not sys.modules
472-
res = 0
473-
try:
474-
timedelta(days=1)
475-
res = 1
476-
except ImportError:
477-
res = 2
478-
print(res)
479-
480-
it = gen()
481-
next(it)
482-
""")
483-
out, err = self.run_embedded_interpreter("test_repeated_init_exec", code)
484-
self.assertEqual(out, '1\n' + '2\n' * (INIT_LOOPS - 1))
485-
486443
def test_static_types_inherited_slots(self):
487444
script = textwrap.dedent("""
488445
import test.support

0 commit comments

Comments
 (0)