Skip to content

Commit

Permalink
✅ fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyongyu authored Dec 7, 2024
1 parent 69e5ae1 commit 844d741
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions tests/test_dependent.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from nonebot.adapters import Event
from nonebot.params import EventParam
from nonebot.exception import TypeMisMatch
from exceptiongroup import BaseExceptionGroup

from nonebug import App

Expand All @@ -23,11 +24,20 @@ def _handle_fake(event: FakeEvent): # type: ignore
ctx.pass_params(event=FakeEvent())

event = FakeEvent2()
with pytest.raises(TypeMisMatch) as e:
with pytest.raises((TypeMisMatch, BaseExceptionGroup)) as exc_info:
async with app.test_dependent(_handle_fake, allow_types=[EventParam]) as ctx:
ctx.pass_params(event=event)
assert e.value.param.name == "event"
assert e.value.value is event

if isinstance(exc_info.value, BaseExceptionGroup):
assert exc_info.group_contains(TypeMisMatch)
exc_group = exc_info.value.subgroup(TypeMisMatch)
e = exc_group.exceptions[0] if exc_group else None
assert isinstance(e, TypeMisMatch)
else:
e = exc_info.value

assert e.param.name == "event"
assert e.value is event


@pytest.mark.asyncio
Expand Down

0 comments on commit 844d741

Please sign in to comment.