mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-76785: Add PyInterpreterConfig Helpers (gh-117170)
These helpers make it easier to customize and inspect the config used to initialize interpreters. This is especially valuable in our tests. I found inspiration from the PyConfig API for the PyInterpreterConfig dict conversion stuff. As part of this PR I've also added a bunch of tests.
This commit is contained in:
parent
cae4cdd07d
commit
f341d6017d
13 changed files with 764 additions and 96 deletions
|
@ -1823,15 +1823,19 @@ class SubinterpImportTests(unittest.TestCase):
|
|||
**(self.ISOLATED if isolated else self.NOT_ISOLATED),
|
||||
check_multi_interp_extensions=strict,
|
||||
)
|
||||
gil = kwargs['gil']
|
||||
kwargs['gil'] = 'default' if gil == 0 else (
|
||||
'shared' if gil == 1 else 'own' if gil == 2 else gil)
|
||||
_, out, err = script_helper.assert_python_ok('-c', textwrap.dedent(f'''
|
||||
import _testinternalcapi, sys
|
||||
assert (
|
||||
{name!r} in sys.builtin_module_names or
|
||||
{name!r} not in sys.modules
|
||||
), repr({name!r})
|
||||
config = type(sys.implementation)(**{kwargs})
|
||||
ret = _testinternalcapi.run_in_subinterp_with_config(
|
||||
{self.import_script(name, "sys.stdout.fileno()")!r},
|
||||
**{kwargs},
|
||||
config,
|
||||
)
|
||||
assert ret == 0, ret
|
||||
'''))
|
||||
|
@ -1847,12 +1851,16 @@ class SubinterpImportTests(unittest.TestCase):
|
|||
**(self.ISOLATED if isolated else self.NOT_ISOLATED),
|
||||
check_multi_interp_extensions=True,
|
||||
)
|
||||
gil = kwargs['gil']
|
||||
kwargs['gil'] = 'default' if gil == 0 else (
|
||||
'shared' if gil == 1 else 'own' if gil == 2 else gil)
|
||||
_, out, err = script_helper.assert_python_ok('-c', textwrap.dedent(f'''
|
||||
import _testinternalcapi, sys
|
||||
assert {name!r} not in sys.modules, {name!r}
|
||||
config = type(sys.implementation)(**{kwargs})
|
||||
ret = _testinternalcapi.run_in_subinterp_with_config(
|
||||
{self.import_script(name, "sys.stdout.fileno()")!r},
|
||||
**{kwargs},
|
||||
config,
|
||||
)
|
||||
assert ret == 0, ret
|
||||
'''))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue