mirror of
https://github.com/Textualize/rich.git
synced 2025-08-04 01:58:24 +00:00
test for nested exceptions
This commit is contained in:
parent
c5c06d1fa7
commit
45eea9472a
1 changed files with 27 additions and 1 deletions
|
@ -6,7 +6,7 @@ import pytest
|
|||
from rich.console import Console
|
||||
from rich.traceback import install, Traceback
|
||||
|
||||
from .render import render
|
||||
# from .render import render
|
||||
|
||||
try:
|
||||
from ._exception_render import expected
|
||||
|
@ -92,6 +92,32 @@ def test_syntax_error():
|
|||
assert "SyntaxError" in exception_text
|
||||
|
||||
|
||||
def test_nested_exception():
|
||||
console = Console(width=100, file=io.StringIO())
|
||||
value_error_message = "ValueError because of ZeroDivisionEerror"
|
||||
|
||||
try:
|
||||
try:
|
||||
1 / 0
|
||||
except ZeroDivisionError:
|
||||
raise ValueError(value_error_message)
|
||||
except Exception:
|
||||
console.print_exception()
|
||||
exception_text = console.file.getvalue()
|
||||
|
||||
text_should_contain = [
|
||||
value_error_message,
|
||||
"ZeroDivisionError",
|
||||
"ValueError",
|
||||
"During handling of the above exception",
|
||||
]
|
||||
|
||||
assert [msg in exception_text for msg in text_should_contain]
|
||||
|
||||
# ZeroDivisionError should come before ValueError
|
||||
assert exception_text.find("ZeroDivisionError") < exception_text.find("ValueError")
|
||||
|
||||
|
||||
if __name__ == "__main__": # pragma: no cover
|
||||
|
||||
expected = render(get_exception())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue