From 76104d323748926a5f20c412cde31cf216f02aaa Mon Sep 17 00:00:00 2001 From: yanyongyu Date: Thu, 23 Dec 2021 19:36:29 +0800 Subject: [PATCH] :bug: fix rule checker not parsed --- nonebot/rule.py | 4 +++- poetry.lock | 18 ++++++++++-------- tests/test_matcher.py | 2 -- tests/test_rule.py | 18 ++++++++++++++++++ 4 files changed, 31 insertions(+), 11 deletions(-) create mode 100644 tests/test_rule.py diff --git a/nonebot/rule.py b/nonebot/rule.py index 33ab18d5..f127230c 100644 --- a/nonebot/rule.py +++ b/nonebot/rule.py @@ -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 ) """ diff --git a/poetry.lock b/poetry.lock index b7b28986..7dc91309 100644 --- a/poetry.lock +++ b/poetry.lock @@ -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 = [ diff --git a/tests/test_matcher.py b/tests/test_matcher.py index 7df74850..3340afb8 100644 --- a/tests/test_matcher.py +++ b/tests/test_matcher.py @@ -1,5 +1,3 @@ -from typing import TYPE_CHECKING, Set - import pytest from nonebug import App diff --git a/tests/test_rule.py b/tests/test_rule.py new file mode 100644 index 00000000..3ca23196 --- /dev/null +++ b/tests/test_rule.py @@ -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)