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