mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-09-19 18:36:42 +00:00
⚗️ add more reject case
This commit is contained in:
@ -16,9 +16,11 @@ test_got = on_message()
|
||||
@test_got.got("key1", "prompt key1")
|
||||
@test_got.got("key2", "prompt key2")
|
||||
async def got(key1: str = ArgStr(), key2: str = ArgStr()):
|
||||
if key2 == "text":
|
||||
await test_got.reject("reject", at_sender=True)
|
||||
|
||||
assert key1 == "text"
|
||||
assert key2 == "text"
|
||||
await test_got.reject("reject", at_sender=True)
|
||||
assert key2 == "text_next"
|
||||
|
||||
|
||||
test_receive = on_message()
|
||||
@ -33,3 +35,22 @@ async def receive(
|
||||
assert str(z.get_message()) == "text"
|
||||
assert x is y
|
||||
await test_receive.pause("pause", at_sender=True)
|
||||
|
||||
|
||||
test_combine = on_message()
|
||||
|
||||
|
||||
@test_combine.got("a")
|
||||
@test_combine.receive()
|
||||
@test_combine.got("b")
|
||||
async def combine(a: str = ArgStr(), b: str = ArgStr(), r: Event = Received()):
|
||||
if a == "text":
|
||||
await test_combine.reject_arg("a")
|
||||
elif b == "text":
|
||||
await test_combine.reject_arg("b")
|
||||
elif str(r.get_message()) == "text":
|
||||
await test_combine.reject_receive()
|
||||
|
||||
assert a == "text_next"
|
||||
assert b == "text_next"
|
||||
assert str(r.get_message()) == "text_next"
|
||||
|
@ -8,10 +8,17 @@ from utils import load_plugin, make_fake_event, make_fake_message
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_matcher(app: App, load_plugin):
|
||||
from plugins.matcher import test_got, test_handle, test_receive
|
||||
from plugins.matcher import (
|
||||
test_got,
|
||||
test_handle,
|
||||
test_combine,
|
||||
test_receive,
|
||||
)
|
||||
|
||||
message = make_fake_message()("text")
|
||||
event = make_fake_event(_message=message)()
|
||||
message_next = make_fake_message()("text_next")
|
||||
event_next = make_fake_event(_message=message_next)()
|
||||
|
||||
assert len(test_handle.handlers) == 1
|
||||
async with app.test_matcher(test_handle) as ctx:
|
||||
@ -30,6 +37,7 @@ async def test_matcher(app: App, load_plugin):
|
||||
ctx.receive_event(bot, event)
|
||||
ctx.should_call_send(event, "reject", "result3", at_sender=True)
|
||||
ctx.should_rejected()
|
||||
ctx.receive_event(bot, event_next)
|
||||
|
||||
assert len(test_receive.handlers) == 1
|
||||
async with app.test_matcher(test_receive) as ctx:
|
||||
@ -39,3 +47,16 @@ async def test_matcher(app: App, load_plugin):
|
||||
ctx.receive_event(bot, event)
|
||||
ctx.should_call_send(event, "pause", "result", at_sender=True)
|
||||
ctx.should_paused()
|
||||
|
||||
assert len(test_receive.handlers) == 1
|
||||
async with app.test_matcher(test_combine) as ctx:
|
||||
bot = ctx.create_bot()
|
||||
ctx.receive_event(bot, event)
|
||||
ctx.receive_event(bot, event)
|
||||
ctx.receive_event(bot, event)
|
||||
ctx.should_rejected()
|
||||
ctx.receive_event(bot, event_next)
|
||||
ctx.should_rejected()
|
||||
ctx.receive_event(bot, event_next)
|
||||
ctx.should_rejected()
|
||||
ctx.receive_event(bot, event_next)
|
||||
|
Reference in New Issue
Block a user