| 521 | @requires_test_modules |
| 522 | @contextlib.contextmanager |
| 523 | def interpreter_from_capi(self, config=None, whence=None): |
| 524 | if config is False: |
| 525 | if whence is None: |
| 526 | whence = _interpreters.WHENCE_LEGACY_CAPI |
| 527 | else: |
| 528 | assert whence in (_interpreters.WHENCE_LEGACY_CAPI, |
| 529 | _interpreters.WHENCE_UNKNOWN), repr(whence) |
| 530 | config = None |
| 531 | elif config is True: |
| 532 | config = _interpreters.new_config('default') |
| 533 | elif config is None: |
| 534 | if whence not in ( |
| 535 | _interpreters.WHENCE_LEGACY_CAPI, |
| 536 | _interpreters.WHENCE_UNKNOWN, |
| 537 | ): |
| 538 | config = _interpreters.new_config('legacy') |
| 539 | elif isinstance(config, str): |
| 540 | config = _interpreters.new_config(config) |
| 541 | |
| 542 | if whence is None: |
| 543 | whence = _interpreters.WHENCE_XI |
| 544 | |
| 545 | interpid = _testinternalcapi.create_interpreter(config, whence=whence) |
| 546 | try: |
| 547 | yield interpid |
| 548 | finally: |
| 549 | try: |
| 550 | _testinternalcapi.destroy_interpreter(interpid) |
| 551 | except _interpreters.InterpreterNotFoundError: |
| 552 | pass |
| 553 | |
| 554 | @contextlib.contextmanager |
| 555 | def interpreter_obj_from_capi(self, config='legacy'): |