Skip to content

Commit 992fd0c

Browse files
committed
Move up a few tests
1 parent 8a81b18 commit 992fd0c

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

Lib/test/datetimetester.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7233,6 +7233,9 @@ def setUp(self):
72337233
if self.__class__.__name__.endswith('Pure'):
72347234
self.skipTest('Not relevant in pure Python')
72357235

7236+
def assert_python_in_subinterp(self, *args, **kwargs):
7237+
return CapiTest.assert_python_in_subinterp(self, *args, **kwargs)
7238+
72367239
@support.cpython_only
72377240
def test_gh_120161(self):
72387241
with self.subTest('simple'):
@@ -7301,8 +7304,31 @@ def test_update_type_cache(self):
73017304
res = script_helper.assert_python_ok('-c', script)
73027305
self.assertFalse(res.err)
73037306

7304-
def assert_python_in_subinterp(self, *args, **kwargs):
7305-
return CapiTest.assert_python_in_subinterp(self, *args, **kwargs)
7307+
def test_module_free(self):
7308+
script = textwrap.dedent("""
7309+
import sys
7310+
import gc
7311+
import weakref
7312+
ws = weakref.WeakSet()
7313+
for _ in range(3):
7314+
import _datetime
7315+
timedelta = _datetime.timedelta # static type
7316+
ws.add(_datetime)
7317+
del sys.modules['_datetime']
7318+
del _datetime
7319+
gc.collect()
7320+
assert len(ws) == 0
7321+
""")
7322+
script_helper.assert_python_ok('-c', script)
7323+
7324+
@unittest.skipIf(not support.Py_DEBUG, "Debug builds only")
7325+
def test_no_leak(self):
7326+
script = textwrap.dedent("""
7327+
import datetime
7328+
datetime.datetime.strptime('20000101', '%Y%m%d').strftime('%Y%m%d')
7329+
""")
7330+
res = script_helper.assert_python_ok('-X', 'showrefcount', '-c', script)
7331+
self.assertIn(b'[0 refs, 0 blocks]', res.err)
73067332

73077333
def test_static_type_on_subinterp(self):
73087334
script = textwrap.dedent(f"""
@@ -7432,32 +7458,6 @@ def gen():
74327458
res = self.assert_python_in_subinterp(True, script2)
74337459
self.assertFalse(res.err)
74347460

7435-
def test_module_free(self):
7436-
script = textwrap.dedent("""
7437-
import sys
7438-
import gc
7439-
import weakref
7440-
ws = weakref.WeakSet()
7441-
for _ in range(3):
7442-
import _datetime
7443-
timedelta = _datetime.timedelta
7444-
ws.add(_datetime)
7445-
del sys.modules['_datetime']
7446-
del _datetime
7447-
gc.collect()
7448-
assert len(ws) == 0
7449-
""")
7450-
script_helper.assert_python_ok('-c', script)
7451-
7452-
@unittest.skipIf(not support.Py_DEBUG, "Debug builds only")
7453-
def test_no_leak(self):
7454-
script = textwrap.dedent("""
7455-
import datetime
7456-
datetime.datetime.strptime('20000101', '%Y%m%d').strftime('%Y%m%d')
7457-
""")
7458-
res = script_helper.assert_python_ok('-X', 'showrefcount', '-c', script)
7459-
self.assertIn(b'[0 refs, 0 blocks]', res.err)
7460-
74617461

74627462
def load_tests(loader, standard_tests, pattern):
74637463
standard_tests.addTest(ZoneInfoCompleteTest())

0 commit comments

Comments
 (0)