🐛 fix rule checker not parsed

This commit is contained in:
yanyongyu 2021-12-23 19:36:29 +08:00
parent e3aba26080
commit 76104d3237
4 changed files with 31 additions and 11 deletions

View File

@ -98,7 +98,9 @@ class Rule:
self.checkers: Set[Dependent[bool]] = set(
checker
if isinstance(checker, Dependent)
else Dependent[bool](call=checker, allow_types=self.HANDLER_PARAM_TYPES)
else Dependent[bool].parse(
call=checker, allow_types=self.HANDLER_PARAM_TYPES
)
for checker in checkers
)
"""

18
poetry.lock generated
View File

@ -319,7 +319,7 @@ name = "h2"
version = "4.1.0"
description = "HTTP/2 State-Machine based protocol implementation"
category = "main"
optional = false
optional = true
python-versions = ">=3.6.1"
[package.dependencies]
@ -331,7 +331,7 @@ name = "hpack"
version = "4.0.0"
description = "Pure-Python HPACK header compression"
category = "main"
optional = false
optional = true
python-versions = ">=3.6.1"
[[package]]
@ -347,7 +347,7 @@ name = "httpcore"
version = "0.14.3"
description = "A minimal low-level HTTP client."
category = "main"
optional = false
optional = true
python-versions = ">=3.6"
[package.dependencies]
@ -375,7 +375,7 @@ name = "httpx"
version = "0.21.1"
description = "The next generation HTTP client."
category = "main"
optional = false
optional = true
python-versions = ">=3.6"
[package.dependencies]
@ -417,7 +417,7 @@ name = "hyperframe"
version = "6.0.1"
description = "HTTP/2 framing layer for Python"
category = "main"
optional = false
optional = true
python-versions = ">=3.6.1"
[[package]]
@ -819,7 +819,7 @@ name = "rfc3986"
version = "1.5.0"
description = "Validating URI References per RFC 3986"
category = "main"
optional = false
optional = true
python-versions = "*"
[package.dependencies]
@ -1176,13 +1176,15 @@ testing = ["pytest (>=4.6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytes
[extras]
aiohttp = ["aiohttp"]
all = ["Quart", "aiohttp"]
all = ["Quart", "aiohttp", "httpx", "websockets"]
httpx = ["httpx"]
quart = ["Quart"]
websockets = ["websockets"]
[metadata]
lock-version = "1.1"
python-versions = "^3.7.3"
content-hash = "e32c99ae82181567b69bc70580e3c0d816a522d0174fce2ce04c773219f1bb50"
content-hash = "f917cb99a90280fb78a3d5e51410d89c364a05d917951a90c1c5af0bda1f08c3"
[metadata.files]
aiodns = [

View File

@ -1,5 +1,3 @@
from typing import TYPE_CHECKING, Set
import pytest
from nonebug import App

18
tests/test_rule.py Normal file
View File

@ -0,0 +1,18 @@
import pytest
from nonebug import App
@pytest.mark.asyncio
async def test_command(app: App):
from nonebot.consts import CMD_KEY, PREFIX_KEY
from nonebot.rule import Rule, CommandRule, command
test_command = command("help")
dependent = list(test_command.checkers)[0]
checker = dependent.call
assert isinstance(checker, CommandRule)
assert checker.cmds == [("help",)]
state = {PREFIX_KEY: {CMD_KEY: ("help",)}}
assert await dependent(state=state)