Skip to content

Commit 3b2dd6d

Browse files
Add a test just for how the setting is used.
1 parent e0c55ad commit 3b2dd6d

2 files changed

Lines changed: 46 additions & 5 deletions

File tree

Lib/test/test_capi/check_config.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def import_singlephase():
1818
return False
1919

2020

21-
def check_singlephase(override):
21+
def check_singlephase_override(override):
2222
# Check using the default setting.
2323
settings_initial = _testinternalcapi.get_interp_settings()
2424
allowed_initial = import_singlephase()
@@ -64,9 +64,17 @@ def check_singlephase(override):
6464
}, **noop)
6565

6666

67-
def run_singlephase_check(override, outfd):
67+
def run_singlephase_check(outfd):
6868
with os.fdopen(outfd, 'w') as outfile:
6969
sys.stdout = outfile
7070
sys.stderr = outfile
71-
results = check_singlephase(override)
71+
allowed = import_singlephase()
72+
json.dump({'allowed': allowed}, outfile)
73+
74+
75+
def run_singlephase_override_check(override, outfd):
76+
with os.fdopen(outfd, 'w') as outfile:
77+
sys.stdout = outfile
78+
sys.stderr = outfile
79+
results = check_singlephase_override(override)
7280
json.dump(results, outfile)

Lib/test/test_capi/test_misc.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,39 @@ def test_configured_settings(self):
13361336

13371337
self.assertEqual(settings, expected)
13381338

1339+
@unittest.skipIf(_testsinglephase is None, "test requires _testsinglephase module")
1340+
@unittest.skipUnless(hasattr(os, "pipe"), "requires os.pipe()")
1341+
def test_setting_extensions_subinterp_check(self):
1342+
"""
1343+
This verifies that the interpreter's configured setting
1344+
is used during import.
1345+
"""
1346+
import json
1347+
1348+
for enabled in (True, False):
1349+
label = 'enabled' if enabled else 'disabled'
1350+
with self.subTest(f'config: check {label}'):
1351+
kwargs = {
1352+
'allow_fork': True,
1353+
'allow_exec': True,
1354+
'allow_threads': True,
1355+
'allow_daemon_threads': True,
1356+
'check_multi_interp_extensions': enabled,
1357+
}
1358+
1359+
r, w = os.pipe()
1360+
script = textwrap.dedent(f'''
1361+
from test.test_capi import check_config
1362+
check_config.run_singlephase_check({w})
1363+
''')
1364+
with os.fdopen(r) as stdout:
1365+
ret = support.run_in_subinterp_with_config(script, **kwargs)
1366+
self.assertEqual(ret, 0)
1367+
out = stdout.read()
1368+
results = json.loads(out)
1369+
1370+
self.assertEqual(results, {'allowed': not enabled})
1371+
13391372
@unittest.skipIf(_testsinglephase is None, "test requires _testsinglephase module")
13401373
@unittest.skipUnless(hasattr(os, "pipe"), "requires os.pipe()")
13411374
def test_overridden_setting_extensions_subinterp_check(self):
@@ -1387,8 +1420,8 @@ def check(enabled, override):
13871420

13881421
r, w = os.pipe()
13891422
script = textwrap.dedent(f'''
1390-
from test.test_capi.check_config import run_singlephase_check
1391-
run_singlephase_check({override}, {w})
1423+
from test.test_capi import check_config
1424+
check_config.run_singlephase_override_check({override}, {w})
13921425
''')
13931426
with os.fdopen(r) as stdout:
13941427
ret = support.run_in_subinterp_with_config(script, **kwargs)

0 commit comments

Comments
 (0)