@@ -7275,79 +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 )
7333-
7334- with self .subTest ('With closure' ):
7335- # Finalization does not happen when a generator is nested
7336- script = textwrap .dedent ("""
7337- def no_issue():
7338- def gen():
7339- try:
7340- yield
7341- finally:
7342- assert sys.modules
7343- import sys
7344- it = gen()
7345- next(it)
7346-
7347- exec(no_issue.__code__)
7348- """ )
7349- res = script_helper .assert_python_ok ('-c' , script )
7350- self .assertFalse (res .err )
7295+ script_helper .assert_python_ok ('-c' , script )
73517296
73527297
73537298def load_tests (loader , standard_tests , pattern ):
0 commit comments