add rule test cases

This commit is contained in:
yanyongyu
2022-01-05 18:29:11 +08:00
parent 7f54468868
commit e39539a3be
5 changed files with 586 additions and 484 deletions

View File

@ -129,3 +129,35 @@ async def test_permission_updater(app: App, load_plugin):
matcher = test_custom_updater()
new_perm = await matcher.update_permission(bot, event)
assert new_perm is default_permission
@pytest.mark.asyncio
async def test_run(app: App):
from nonebot.matcher import Matcher, matchers
assert not matchers
event = make_fake_event()()
async def reject():
await Matcher.reject()
test_reject = Matcher.new(handlers=[reject])
async with app.test_api() as ctx:
bot = ctx.create_bot()
await test_reject().run(bot, event, {})
assert len(matchers[0]) == 1
assert len(matchers[0][0].handlers) == 1
del matchers[0]
async def pause():
await Matcher.pause()
test_pause = Matcher.new(handlers=[pause])
async with app.test_api() as ctx:
bot = ctx.create_bot()
await test_pause().run(bot, event, {})
assert len(matchers[0]) == 1
assert len(matchers[0][0].handlers) == 0