Skip to content

Commit 063f37d

Browse files
committed
Add test cases
1 parent 56267bd commit 063f37d

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Lib/test/datetimetester.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7367,6 +7367,40 @@ def gen():
73677367
res = self.assert_python_in_subinterp(True, script, setup='')
73687368
self.assertFalse(res.err)
73697369

7370+
script = textwrap.dedent("""
7371+
import gc
7372+
import sys
7373+
import _testcapi
7374+
7375+
def emulate_interp_restart():
7376+
del sys.modules['_datetime']
7377+
try:
7378+
del sys.modules['datetime']
7379+
except KeyError:
7380+
pass
7381+
gc.collect() # unload
7382+
7383+
_testcapi.test_datetime_capi() # only once
7384+
timedelta = _testcapi.get_capi_types()['timedelta']
7385+
emulate_interp_restart()
7386+
timedelta(days=1)
7387+
emulate_interp_restart()
7388+
7389+
def gen():
7390+
try:
7391+
yield
7392+
finally:
7393+
# Exceptions are ignored here
7394+
assert not sys.modules
7395+
timedelta(days=1)
7396+
7397+
it = gen()
7398+
next(it)
7399+
""")
7400+
with self.subTest('MainInterpreter Restart'):
7401+
res = script_helper.assert_python_ok('-c', script)
7402+
self.assertIn(b'ImportError: sys.meta_path is None', res.err)
7403+
73707404
script = textwrap.dedent("""
73717405
import sys
73727406
timedelta = _testcapi.get_capi_types()['timedelta']

0 commit comments

Comments
 (0)