Adapt SIGINT test to `trio` strict exception-groups
`test_cancel_via_SIGINT_other_task` opened its nursery with the now-deprecated `strict_exception_groups=False`. Under strict EGs (trio's default since 0.25) the SIGINT-induced `KeyboardInterrupt` surfaces wrapped in a `BaseExceptionGroup` — alongside the child tasks' `Cancelled`s, so it's MULTI-exc and `collapse_eg()` can't fold it back to a bare KI (the `# why no work!?` the author hit). Drop the deprecated flag, use a default (strict) nursery, and assert the result is a bare `KeyboardInterrupt` OR a `BaseExceptionGroup` whose `.subgroup(KeyboardInterrupt)` is non-empty. (this patch was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-codewkt/rm_test_warnings
parent
4607090a5d
commit
dc8562cf14
|
|
@ -780,21 +780,28 @@ def test_cancel_via_SIGINT_other_task(
|
||||||
async def main():
|
async def main():
|
||||||
# should never timeout since SIGINT should cancel the current program
|
# should never timeout since SIGINT should cancel the current program
|
||||||
with trio.fail_after(timeout):
|
with trio.fail_after(timeout):
|
||||||
async with (
|
async with trio.open_nursery() as tn:
|
||||||
|
|
||||||
# XXX ?TODO? why no work!?
|
|
||||||
# tractor.trionics.collapse_eg(),
|
|
||||||
trio.open_nursery(
|
|
||||||
strict_exception_groups=False,
|
|
||||||
) as tn,
|
|
||||||
):
|
|
||||||
await tn.start(spawn_and_sleep_forever)
|
await tn.start(spawn_and_sleep_forever)
|
||||||
if 'mp' in spawn_backend:
|
if 'mp' in spawn_backend:
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
os.kill(pid, signal.SIGINT)
|
os.kill(pid, signal.SIGINT)
|
||||||
|
|
||||||
with pytest.raises(KeyboardInterrupt):
|
# SIGINT -> `KeyboardInterrupt`; under `trio>=0.25`'s strict
|
||||||
|
# exception-groups the KI surfaces wrapped in a (cancel-padded)
|
||||||
|
# `BaseExceptionGroup` rather than bare — so accept either form
|
||||||
|
# (replaces the now-deprecated `strict_exception_groups=False`,
|
||||||
|
# and `collapse_eg()` can't help since the group is multi-exc:
|
||||||
|
# the KI rides alongside the child-task `Cancelled`s).
|
||||||
|
with pytest.raises(BaseException) as excinfo:
|
||||||
trio.run(main)
|
trio.run(main)
|
||||||
|
exc = excinfo.value
|
||||||
|
assert (
|
||||||
|
isinstance(exc, KeyboardInterrupt)
|
||||||
|
or (
|
||||||
|
isinstance(exc, BaseExceptionGroup)
|
||||||
|
and exc.subgroup(KeyboardInterrupt) is not None
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def spin_for(period=3):
|
async def spin_for(period=3):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue