(cls, name, interpid, pipe, script_kwargs)
| 320 | |
| 321 | @classmethod |
| 322 | def _from_subinterp(cls, name, interpid, pipe, script_kwargs): |
| 323 | r, w = pipe |
| 324 | |
| 325 | # Build the script. |
| 326 | postscript = textwrap.dedent(f''' |
| 327 | # Send the result over the pipe. |
| 328 | import json |
| 329 | import os |
| 330 | os.write({w}, json.dumps(snapshot).encode()) |
| 331 | |
| 332 | ''') |
| 333 | _postscript = script_kwargs.get('postscript') |
| 334 | if _postscript: |
| 335 | _postscript = textwrap.dedent(_postscript).lstrip() |
| 336 | postscript += _postscript |
| 337 | script_kwargs['postscript'] = postscript.strip() |
| 338 | script = cls.build_script(name, **script_kwargs) |
| 339 | |
| 340 | # Run the script. |
| 341 | if interpid is None: |
| 342 | ret = run_in_subinterp(script) |
| 343 | if ret != 0: |
| 344 | raise AssertionError(f'{ret} != 0') |
| 345 | else: |
| 346 | _interpreters.run_string(interpid, script) |
| 347 | |
| 348 | # Parse the results. |
| 349 | text = os.read(r, 1000) |
| 350 | return cls.parse(text.decode()) |
| 351 | |
| 352 | |
| 353 | @force_not_colorized_test_class |
no test coverage detected