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

Method get_output

Lib/test/test_faulthandler.py:67–106  ·  view source on GitHub ↗

Run the specified code in Python (in a new child process) and read the output from the standard error or from a file (if filename is set). Return the output lines as a list. Strip the reference count from the standard error for Python debug build, and replac

(self, code, filename=None, fd=None)

Source from the content-addressed store, hash-verified

65class FaultHandlerTests(unittest.TestCase):
66
67 def get_output(self, code, filename=None, fd=None):
68 """
69 Run the specified code in Python (in a new child process) and read the
70 output from the standard error or from a file (if filename is set).
71 Return the output lines as a list.
72
73 Strip the reference count from the standard error for Python debug
74 build, and replace "Current thread 0x00007f8d8fbd9700" by "Current
75 thread XXX".
76 """
77 code = dedent(code).strip()
78 pass_fds = []
79 if fd is not None:
80 pass_fds.append(fd)
81 env = dict(os.environ)
82
83 # Sanitizers must not handle SIGSEGV (ex: for test_enable_fd())
84 option = 'handle_segv=0'
85 support.set_sanitizer_env_var(env, option)
86
87 with support.SuppressCrashReport():
88 process = script_helper.spawn_python('-c', code,
89 pass_fds=pass_fds,
90 env=env)
91 with process:
92 output, stderr = process.communicate()
93 exitcode = process.wait()
94 output = output.decode('ascii', 'backslashreplace')
95 if filename:
96 self.assertEqual(output, '')
97 with open(filename, "rb") as fp:
98 output = fp.read()
99 output = output.decode('ascii', 'backslashreplace')
100 elif fd is not None:
101 self.assertEqual(output, '')
102 os.lseek(fd, os.SEEK_SET, 0)
103 with open(fd, "rb", closefd=False) as fp:
104 output = fp.read()
105 output = output.decode('ascii', 'backslashreplace')
106 return output.splitlines(), exitcode
107
108 def check_error(self, code, lineno, fatal_error, *,
109 filename=None, all_threads=True, other_regex=None,

Calls 10

dedentFunction · 0.90
openFunction · 0.50
stripMethod · 0.45
appendMethod · 0.45
communicateMethod · 0.45
waitMethod · 0.45
decodeMethod · 0.45
assertEqualMethod · 0.45
readMethod · 0.45
splitlinesMethod · 0.45

Tested by

no test coverage detected