MCPcopy
hub / github.com/Textualize/rich / test_caused_exception

Function test_caused_exception

tests/test_traceback.py:165–189  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

163
164
165def test_caused_exception():
166 console = Console(width=100, file=io.StringIO())
167 value_error_message = "ValueError caused by ZeroDivisionError"
168
169 try:
170 try:
171 1 / 0
172 except ZeroDivisionError as e:
173 raise ValueError(value_error_message) from e
174 except Exception:
175 console.print_exception()
176 exception_text = console.file.getvalue()
177
178 text_should_contain = [
179 value_error_message,
180 "ZeroDivisionError",
181 "ValueError",
182 "The above exception was the direct cause",
183 ]
184
185 for msg in text_should_contain:
186 assert msg in exception_text
187
188 # ZeroDivisionError should come before ValueError
189 assert exception_text.find("ZeroDivisionError") < exception_text.find("ValueError")
190
191
192def test_filename_with_bracket():

Callers

nothing calls this directly

Calls 2

print_exceptionMethod · 0.95
ConsoleClass · 0.90

Tested by

no test coverage detected