mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-09-07 04:26:45 +00:00
🐛 fix matcher got receive type error
This commit is contained in:
@ -66,8 +66,27 @@ async def preset(matcher: Matcher, message: Message = EventMessage()):
|
||||
|
||||
|
||||
@test_preset.got("a")
|
||||
async def reject_preset(a: str = ArgStr()):
|
||||
@test_preset.got("b")
|
||||
async def reject_preset(a: str = ArgStr(), b: str = ArgStr()):
|
||||
if a == "text":
|
||||
await test_preset.reject_arg("a")
|
||||
|
||||
assert a == "text_next"
|
||||
assert b == "text"
|
||||
|
||||
|
||||
test_overload = on_message()
|
||||
|
||||
|
||||
class FakeEvent(Event):
|
||||
...
|
||||
|
||||
|
||||
@test_overload.got("a")
|
||||
async def overload(event: FakeEvent):
|
||||
await test_overload.reject_arg("a")
|
||||
|
||||
|
||||
@test_overload.handle()
|
||||
async def finish():
|
||||
await test_overload.finish()
|
||||
|
@ -12,6 +12,7 @@ async def test_matcher(app: App, load_plugin):
|
||||
test_preset,
|
||||
test_combine,
|
||||
test_receive,
|
||||
test_overload,
|
||||
)
|
||||
|
||||
message = make_fake_message()("text")
|
||||
@ -64,5 +65,12 @@ async def test_matcher(app: App, load_plugin):
|
||||
async with app.test_matcher(test_preset) as ctx:
|
||||
bot = ctx.create_bot()
|
||||
ctx.receive_event(bot, event)
|
||||
ctx.receive_event(bot, event)
|
||||
ctx.should_rejected()
|
||||
ctx.receive_event(bot, event_next)
|
||||
|
||||
assert len(test_overload.handlers) == 2
|
||||
async with app.test_matcher(test_overload) as ctx:
|
||||
bot = ctx.create_bot()
|
||||
ctx.receive_event(bot, event)
|
||||
ctx.should_finished()
|
||||
|
Reference in New Issue
Block a user