-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
95 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,56 @@ | ||
import sys | ||
|
||
from exceptiongroup import ExceptionGroup | ||
|
||
|
||
def test_formatting(capsys): | ||
exceptions = [] | ||
try: | ||
raise ValueError("foo") | ||
except ValueError as exc: | ||
exceptions.append(exc) | ||
|
||
try: | ||
raise RuntimeError("bar") | ||
except RuntimeError as exc: | ||
exc.__note__ = "Note from bar handler" | ||
exceptions.append(exc) | ||
|
||
try: | ||
raise ExceptionGroup("test message", exceptions) | ||
except ExceptionGroup as exc: | ||
exc.__note__ = "Displays notes attached to the group too" | ||
sys.excepthook(type(exc), exc, exc.__traceback__) | ||
|
||
lineno = test_formatting.__code__.co_firstlineno | ||
if sys.version_info >= (3, 11): | ||
module_prefix = "" | ||
underline1 = "\n | " + "^" * 48 | ||
underline2 = "\n | " + "^" * 23 | ||
underline3 = "\n | " + "^" * 25 | ||
else: | ||
module_prefix = "exceptiongroup." | ||
underline1 = underline2 = underline3 = "" | ||
|
||
output = capsys.readouterr().err | ||
assert output == ( | ||
f"""\ | ||
+ Exception Group Traceback (most recent call last): | ||
| File "{__file__}", line {lineno + 14}, in test_formatting | ||
| raise ExceptionGroup("test message", exceptions){underline1} | ||
| {module_prefix}ExceptionGroup: test message (2 sub-exceptions) | ||
| Displays notes attached to the group too | ||
+-+---------------- 1 ---------------- | ||
| Traceback (most recent call last): | ||
| File "{__file__}", line {lineno + 3}, in test_formatting | ||
| raise ValueError("foo"){underline2} | ||
| ValueError: foo | ||
+---------------- 2 ---------------- | ||
| Traceback (most recent call last): | ||
| File "{__file__}", line {lineno + 8}, in test_formatting | ||
| raise RuntimeError("bar"){underline3} | ||
| RuntimeError: bar | ||
| Note from bar handler | ||
+------------------------------------ | ||
""" | ||
) | ||
import sys | ||
|
||
from exceptiongroup import ExceptionGroup | ||
|
||
|
||
def test_formatting(capsys): | ||
exceptions = [] | ||
try: | ||
raise ValueError("foo") | ||
except ValueError as exc: | ||
exceptions.append(exc) | ||
|
||
try: | ||
raise RuntimeError("bar") | ||
except RuntimeError as exc: | ||
exc.__notes__ = ["Note from bar handler"] | ||
exceptions.append(exc) | ||
|
||
try: | ||
raise ExceptionGroup("test message", exceptions) | ||
except ExceptionGroup as exc: | ||
exc.add_note("Displays notes attached to the group too") | ||
sys.excepthook(type(exc), exc, exc.__traceback__) | ||
|
||
lineno = test_formatting.__code__.co_firstlineno | ||
if sys.version_info >= (3, 11): | ||
module_prefix = "" | ||
underline1 = "\n | " + "^" * 48 | ||
underline2 = "\n | " + "^" * 23 | ||
underline3 = "\n | " + "^" * 25 | ||
else: | ||
module_prefix = "exceptiongroup." | ||
underline1 = underline2 = underline3 = "" | ||
|
||
output = capsys.readouterr().err | ||
assert output == ( | ||
f"""\ | ||
+ Exception Group Traceback (most recent call last): | ||
| File "{__file__}", line {lineno + 14}, in test_formatting | ||
| raise ExceptionGroup("test message", exceptions){underline1} | ||
| {module_prefix}ExceptionGroup: test message (2 sub-exceptions) | ||
| Displays notes attached to the group too | ||
+-+---------------- 1 ---------------- | ||
| Traceback (most recent call last): | ||
| File "{__file__}", line {lineno + 3}, in test_formatting | ||
| raise ValueError("foo"){underline2} | ||
| ValueError: foo | ||
+---------------- 2 ---------------- | ||
| Traceback (most recent call last): | ||
| File "{__file__}", line {lineno + 8}, in test_formatting | ||
| raise RuntimeError("bar"){underline3} | ||
| RuntimeError: bar | ||
| Note from bar handler | ||
+------------------------------------ | ||
""" | ||
) |