Skip to content

Commit

Permalink
Merge pull request #147 from axiomiety/tests-exception-groups
Browse files Browse the repository at this point in the history
[tests] support trio's new exception groups, bump min trio rev to 0.25.0
  • Loading branch information
oremanj committed Apr 19, 2024
2 parents ffbd11c + 91c7360 commit dde84b3
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ sphinx >= 1.7.0
sphinx_rtd_theme
sphinxcontrib-trio
towncrier
trio >= 0.15.0,< 0.25.0
trio >= 0.25.0
outcome
attrs
greenlet
1 change: 1 addition & 0 deletions newsfragments/146.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updated test suite to cope with Trio 0.25.0 and later defaulting ``strict_exception_groups`` to ``True``. Trio 0.25.0 is now required to run the tests, although trio-asyncio itself still supports older versions.
2 changes: 1 addition & 1 deletion test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ pytest-cov
pytest-trio
outcome
pytest-timeout
trio >= 0.15.0,< 0.25.0
trio >= 0.25.0
2 changes: 1 addition & 1 deletion tests/interop/test_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ async def cancel_trio(seen):
seen.flag |= 8

seen = Seen()
with pytest.raises(asyncio.CancelledError):
with trio.testing.RaisesGroup(asyncio.CancelledError):
await cancel_trio(seen)
assert seen.flag == 1 | 8

Expand Down
17 changes: 12 additions & 5 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ async def run_asyncio_loop(nursery, *, task_status=trio.TASK_STATUS_IGNORED):
import signal
import threading

with pytest.raises(KeyboardInterrupt):
with trio.testing.RaisesGroup(KeyboardInterrupt):
async with trio.open_nursery() as nursery:
await nursery.start(run_asyncio_loop, nursery)
# Trigger KeyboardInterrupt that should propagate accross the coroutines
Expand Down Expand Up @@ -270,7 +270,7 @@ async def trio_task():
scope.cancel()
assert fut.done()
if throw_another:
with pytest.raises(ValueError, match="hi"):
with trio.testing.RaisesGroup(trio.testing.Matcher(ValueError, match="hi")):
fut.result()
else:
assert fut.cancelled()
Expand Down Expand Up @@ -333,12 +333,19 @@ def collect_exceptions(loop, context):
)
expected = [ValueError("hi"), ValueError("lo"), KeyError(), IndexError()]
await raise_in_aio_loop(expected[0])
with pytest.raises(SystemExit):
with trio.testing.RaisesGroup(SystemExit, strict=False):
await raise_in_aio_loop(SystemExit(0))
with pytest.raises(BaseExceptionGroup) as result:
with trio.testing.RaisesGroup(SystemExit, strict=False) as result:
await raise_in_aio_loop(BaseExceptionGroup("", [expected[1], SystemExit()]))

assert len(result.value.exceptions) == 1
assert isinstance(result.value.exceptions[0], SystemExit)

def innermost_exception(item):
if isinstance(item, BaseExceptionGroup):
return innermost_exception(item.exceptions[0])
return item

assert isinstance(innermost_exception(result.value), SystemExit)
await raise_in_aio_loop(ExceptionGroup("", expected[2:]))

assert len(exceptions) == 3
Expand Down
4 changes: 3 additions & 1 deletion tests/test_trio_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ async def test_cancel_loop_with_tasks(autojump_clock, shield, body_raises):
record = []

if body_raises:
catcher = pytest.raises(ValueError, match="hi")
catcher = trio.testing.RaisesGroup(
trio.testing.Matcher(ValueError, match="hi"), strict=False
)
else:
catcher = contextlib.nullcontext()

Expand Down

0 comments on commit dde84b3

Please sign in to comment.