Skip to content

Commit

Permalink
Added an extra test for EG loop rendering
Browse files Browse the repository at this point in the history
Closes #35.
  • Loading branch information
agronholm committed Oct 27, 2022
1 parent 8a13751 commit a47534f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
5 changes: 4 additions & 1 deletion CHANGES.rst
Expand Up @@ -8,7 +8,10 @@ This library adheres to `Semantic Versioning 2.0 <http://semver.org/>`_.
- Fixed
``AttributeError: 'PatchedTracebackException' object has no attribute '__cause__'``
on Python 3.10 (only) when a traceback is printed from an exception where an exception
group is set as the cause
group is set as the cause (#33)
- Fixed a loop in exception groups being rendered incorrectly (#35)
- Fixed the patched formatting functions (``format_exc()``etc.) not passing the
``compact=True`` flag on Python 3.10 like the original functions do

**1.0.0rc9**

Expand Down
38 changes: 38 additions & 0 deletions tests/test_formatting.py
Expand Up @@ -114,6 +114,44 @@ def test_exceptiongroup_as_cause(capsys: CaptureFixture) -> None:
)


def test_exceptiongroup_loop(capsys: CaptureFixture) -> None:
e0 = Exception("e0")
eg0 = ExceptionGroup("eg0", (e0,))
eg1 = ExceptionGroup("eg1", (eg0,))

try:
raise eg0 from eg1
except ExceptionGroup as exc:
sys.excepthook(type(exc), exc, exc.__traceback__)

lineno = test_exceptiongroup_loop.__code__.co_firstlineno + 6
module_prefix = "" if sys.version_info >= (3, 11) else "exceptiongroup."
output = capsys.readouterr().err
assert output == (
f"""\
| {module_prefix}ExceptionGroup: eg1 (1 sub-exception)
+-+---------------- 1 ----------------
| Exception Group Traceback (most recent call last):
| File "{__file__}", line {lineno}, in test_exceptiongroup_loop
| raise eg0 from eg1
| {module_prefix}ExceptionGroup: eg0 (1 sub-exception)
+-+---------------- 1 ----------------
| Exception: e0
+------------------------------------
The above exception was the direct cause of the following exception:
+ Exception Group Traceback (most recent call last):
| File "{__file__}", line {lineno}, in test_exceptiongroup_loop
| raise eg0 from eg1
| {module_prefix}ExceptionGroup: eg0 (1 sub-exception)
+-+---------------- 1 ----------------
| Exception: e0
+------------------------------------
"""
)


def test_exceptionhook_format_exception_only(capsys: CaptureFixture) -> None:
try:
raise_excgroup()
Expand Down

0 comments on commit a47534f

Please sign in to comment.