Check that the fault handler for fatal errors is enabled and check the traceback from the child process output. Raise an error if the output doesn't match the expected format.
(self, code, lineno, fatal_error, *,
filename=None, all_threads=True, other_regex=None,
fd=None, know_current_thread=True,
py_fatal_error=False,
garbage_collecting=False,
c_stack=True,
function='<module>')
| 106 | return output.splitlines(), exitcode |
| 107 | |
| 108 | def check_error(self, code, lineno, fatal_error, *, |
| 109 | filename=None, all_threads=True, other_regex=None, |
| 110 | fd=None, know_current_thread=True, |
| 111 | py_fatal_error=False, |
| 112 | garbage_collecting=False, |
| 113 | c_stack=True, |
| 114 | function='<module>'): |
| 115 | """ |
| 116 | Check that the fault handler for fatal errors is enabled and check the |
| 117 | traceback from the child process output. |
| 118 | |
| 119 | Raise an error if the output doesn't match the expected format. |
| 120 | """ |
| 121 | all_threads_disabled = ( |
| 122 | all_threads |
| 123 | and (not sys._is_gil_enabled()) |
| 124 | ) |
| 125 | if all_threads and not all_threads_disabled: |
| 126 | if know_current_thread: |
| 127 | header = CURRENT_THREAD_HEADER |
| 128 | else: |
| 129 | header = THREAD_HEADER |
| 130 | else: |
| 131 | header = STACK_HEADER |
| 132 | regex = [f'^{fatal_error}'] |
| 133 | if py_fatal_error: |
| 134 | regex.append("Python runtime state: initialized") |
| 135 | regex.append('') |
| 136 | if all_threads_disabled and not py_fatal_error: |
| 137 | regex.append("<Cannot show all threads while the GIL is disabled>") |
| 138 | regex.append(fr'{header}') |
| 139 | if support.Py_GIL_DISABLED and py_fatal_error and not know_current_thread: |
| 140 | regex.append(" <tstate is freed>") |
| 141 | else: |
| 142 | if garbage_collecting and not all_threads_disabled: |
| 143 | regex.append(' Garbage-collecting') |
| 144 | regex.append(fr' File "<string>", line {lineno} in {function}') |
| 145 | if c_stack: |
| 146 | regex.extend(C_STACK_REGEX) |
| 147 | regex = '\n'.join(regex) |
| 148 | |
| 149 | if other_regex: |
| 150 | regex = f'(?:{regex}|{other_regex})' |
| 151 | |
| 152 | # Enable MULTILINE flag |
| 153 | regex = f'(?m){regex}' |
| 154 | output, exitcode = self.get_output(code, filename=filename, fd=fd) |
| 155 | output = '\n'.join(output) |
| 156 | self.assertRegex(output, regex) |
| 157 | self.assertNotEqual(exitcode, 0) |
| 158 | |
| 159 | def check_fatal_error(self, code, line_number, name_regex, func=None, **kw): |
| 160 | if func: |
no test coverage detected