MCPcopy Index your code
hub / github.com/python/cpython / read_json

Method read_json

Lib/test/libregrtest/run_workers.py:322–354  ·  view source on GitHub ↗
(self, json_file: JsonFile, json_tmpfile: TextIO | None,
                  stdout: str)

Source from the content-addressed store, hash-verified

320 state=State.WORKER_BUG)
321
322 def read_json(self, json_file: JsonFile, json_tmpfile: TextIO | None,
323 stdout: str) -> tuple[TestResult, str]:
324 try:
325 if json_tmpfile is not None:
326 json_tmpfile.seek(0)
327 worker_json = json_tmpfile.read()
328 elif json_file.file_type == JsonFileType.STDOUT:
329 stdout, _, worker_json = stdout.rpartition("\n")
330 stdout = stdout.rstrip()
331 else:
332 with json_file.open(encoding='utf8') as json_fp:
333 worker_json = json_fp.read()
334 except Exception as exc:
335 # gh-101634: Catch UnicodeDecodeError if stdout cannot be
336 # decoded from encoding
337 err_msg = f"Failed to read worker process JSON: {exc}"
338 raise WorkerError(self.test_name, err_msg, stdout,
339 state=State.WORKER_BUG)
340
341 if not worker_json:
342 raise WorkerError(self.test_name, "empty JSON", stdout,
343 state=State.WORKER_BUG)
344
345 try:
346 result = TestResult.from_json(worker_json)
347 except Exception as exc:
348 # gh-101634: Catch UnicodeDecodeError if stdout cannot be
349 # decoded from encoding
350 err_msg = f"Failed to parse worker process JSON: {exc}"
351 raise WorkerError(self.test_name, err_msg, stdout,
352 state=State.WORKER_BUG)
353
354 return (result, stdout)
355
356 def _runtest(self, test_name: TestName) -> MultiprocessResult:
357 with contextlib.ExitStack() as stack:

Callers 1

_runtestMethod · 0.95

Calls 7

WorkerErrorClass · 0.85
seekMethod · 0.45
readMethod · 0.45
rpartitionMethod · 0.45
rstripMethod · 0.45
openMethod · 0.45
from_jsonMethod · 0.45

Tested by

no test coverage detected