|
31 | 31 | import _testmultiphase
|
32 | 32 | except ImportError:
|
33 | 33 | _testmultiphase = None
|
| 34 | +try: |
| 35 | + import _testsinglephase |
| 36 | +except ImportError: |
| 37 | + _testsinglephase = None |
34 | 38 |
|
35 | 39 | # Skip this test if the _testcapi module isn't available.
|
36 | 40 | _testcapi = import_helper.import_module('_testcapi')
|
@@ -1325,12 +1329,92 @@ def test_configured_settings(self):
|
1325 | 1329 | json.dump(settings, stdin)
|
1326 | 1330 | ''')
|
1327 | 1331 | with os.fdopen(r) as stdout:
|
1328 |
| - support.run_in_subinterp_with_config(script, **kwargs) |
| 1332 | + ret = support.run_in_subinterp_with_config(script, **kwargs) |
| 1333 | + self.assertEqual(ret, 0) |
1329 | 1334 | out = stdout.read()
|
1330 | 1335 | settings = json.loads(out)
|
1331 | 1336 |
|
1332 | 1337 | self.assertEqual(settings, expected)
|
1333 | 1338 |
|
| 1339 | + @unittest.skipIf(_testsinglephase is None, "test requires _testsinglphase module") |
| 1340 | + @unittest.skipUnless(hasattr(os, "pipe"), "requires os.pipe()") |
| 1341 | + def test_overridden_setting_extensions_subinterp_check(self): |
| 1342 | + """ |
| 1343 | + PyInterpreterConfig.check_multi_interp_extensions can be overridden |
| 1344 | + with PyInterpreterState.override_multi_interp_extensions_check. |
| 1345 | + This verifies that the override works but does not modify |
| 1346 | + the underlying setting. |
| 1347 | + """ |
| 1348 | + import json |
| 1349 | + |
| 1350 | + EXTENSIONS = 1<<8 |
| 1351 | + THREADS = 1<<10 |
| 1352 | + DAEMON_THREADS = 1<<11 |
| 1353 | + FORK = 1<<15 |
| 1354 | + EXEC = 1<<16 |
| 1355 | + BASE_FLAGS = FORK | EXEC | THREADS | DAEMON_THREADS |
| 1356 | + base_kwargs = { |
| 1357 | + 'allow_fork': True, |
| 1358 | + 'allow_exec': True, |
| 1359 | + 'allow_threads': True, |
| 1360 | + 'allow_daemon_threads': True, |
| 1361 | + } |
| 1362 | + |
| 1363 | + def check(enabled, override): |
| 1364 | + kwargs = dict( |
| 1365 | + base_kwargs, |
| 1366 | + check_multi_interp_extensions=enabled, |
| 1367 | + ) |
| 1368 | + flags = BASE_FLAGS | EXTENSIONS if enabled else BASE_FLAGS |
| 1369 | + settings = { |
| 1370 | + 'feature_flags': flags, |
| 1371 | + } |
| 1372 | + if override == 0: |
| 1373 | + enabled_after = enabled |
| 1374 | + else: |
| 1375 | + enabled_after = (override > 0) |
| 1376 | + expected = { |
| 1377 | + 'settings_before': settings, |
| 1378 | + 'enabled_initial': enabled, |
| 1379 | + 'override_initial': 0, |
| 1380 | + 'settings_after': settings, |
| 1381 | + 'enabled_after': enabled_after, |
| 1382 | + 'override_actual': override, |
| 1383 | + 'settings_final': settings, |
| 1384 | + 'override_noop': 0, |
| 1385 | + 'settings_noop': settings, |
| 1386 | + 'enabled_restored': enabled, |
| 1387 | + } |
| 1388 | + |
| 1389 | + r, w = os.pipe() |
| 1390 | + script = textwrap.dedent(f''' |
| 1391 | + from test.test_capi.check_config import run_check |
| 1392 | + run_check({override}, {w}) |
| 1393 | + ''') |
| 1394 | + with os.fdopen(r) as stdout: |
| 1395 | + ret = support.run_in_subinterp_with_config(script, **kwargs) |
| 1396 | + self.assertEqual(ret, 0) |
| 1397 | + out = stdout.read() |
| 1398 | + results = json.loads(out) |
| 1399 | + |
| 1400 | + self.assertEqual(results, expected) |
| 1401 | + |
| 1402 | + # setting: check disabled |
| 1403 | + with self.subTest('config disabled, override disabled'): |
| 1404 | + check(False, -1) |
| 1405 | + with self.subTest('config disabled, override cleared'): |
| 1406 | + check(False, 0) |
| 1407 | + with self.subTest('config disabled, override enabled'): |
| 1408 | + check(False, 1) |
| 1409 | + |
| 1410 | + # setting: check enabled |
| 1411 | + with self.subTest('config enabled, override disabled'): |
| 1412 | + check(True, -1) |
| 1413 | + with self.subTest('config enabled, override cleared'): |
| 1414 | + check(True, 0) |
| 1415 | + with self.subTest('config enabled, override enabled'): |
| 1416 | + check(True, 1) |
| 1417 | + |
1334 | 1418 | def test_mutate_exception(self):
|
1335 | 1419 | """
|
1336 | 1420 | Exceptions saved in global module state get shared between
|
|
0 commit comments