🐛 fix matcher got receive type error

This commit is contained in:
yanyongyu
2021-12-31 22:43:29 +08:00
parent c48231454e
commit ec35f292bd
6 changed files with 130 additions and 43 deletions

View File

@ -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()

View File

@ -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()