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

Method create_json_file

Lib/test/libregrtest/run_workers.py:247–267  ·  view source on GitHub ↗

Create JSON file.

(self, stack: contextlib.ExitStack)

Source from the content-addressed store, hash-verified

245 return stdout_file
246
247 def create_json_file(self, stack: contextlib.ExitStack) -> tuple[JsonFile, TextIO | None]:
248 """Create JSON file."""
249
250 json_file_use_stdout = self.runtests.json_file_use_stdout()
251 if json_file_use_stdout:
252 json_file = JsonFile(None, JsonFileType.STDOUT)
253 json_tmpfile = None
254 else:
255 json_tmpfile = tempfile.TemporaryFile('w+', encoding='utf8')
256 stack.enter_context(json_tmpfile)
257
258 json_fd = json_tmpfile.fileno()
259 if MS_WINDOWS:
260 # The msvcrt module is only available on Windows;
261 # we run mypy with `--platform=linux` in CI
262 json_handle: int = msvcrt.get_osfhandle(json_fd) # type: ignore[attr-defined]
263 json_file = JsonFile(json_handle,
264 JsonFileType.WINDOWS_HANDLE)
265 else:
266 json_file = JsonFile(json_fd, JsonFileType.UNIX_FD)
267 return (json_file, json_tmpfile)
268
269 def create_worker_runtests(self, test_name: TestName, json_file: JsonFile) -> WorkerRunTests:
270 tests = (test_name,)

Callers 1

_runtestMethod · 0.95

Calls 4

JsonFileClass · 0.85
json_file_use_stdoutMethod · 0.80
enter_contextMethod · 0.80
filenoMethod · 0.45

Tested by

no test coverage detected