mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-09-04 02:56:45 +00:00
🚨 Develop: 完全使用 ruff 替代 isort 与 black (#3151)
This commit is contained in:
@ -1,20 +1,20 @@
|
||||
import os
|
||||
import threading
|
||||
from pathlib import Path
|
||||
from functools import wraps
|
||||
from collections.abc import Generator
|
||||
from functools import wraps
|
||||
import os
|
||||
from pathlib import Path
|
||||
import threading
|
||||
from typing import TYPE_CHECKING, Callable, TypeVar
|
||||
from typing_extensions import ParamSpec
|
||||
from typing import TYPE_CHECKING, TypeVar, Callable
|
||||
|
||||
import pytest
|
||||
from nonebug import NONEBOT_INIT_KWARGS
|
||||
import pytest
|
||||
from werkzeug.serving import BaseWSGIServer, make_server
|
||||
|
||||
import nonebot
|
||||
from nonebot.config import Env
|
||||
from fake_server import request_handler
|
||||
from nonebot.drivers import URL, Driver
|
||||
import nonebot
|
||||
from nonebot import _resolve_combine_expr
|
||||
from nonebot.config import Env
|
||||
from nonebot.drivers import URL, Driver
|
||||
|
||||
os.environ["CONFIG_FROM_ENV"] = '{"test": "test"}'
|
||||
os.environ["CONFIG_OVERRIDE"] = "new"
|
||||
|
@ -1,15 +1,20 @@
|
||||
import json
|
||||
import base64
|
||||
import json
|
||||
import socket
|
||||
from typing import Union, TypeVar
|
||||
from typing import TypeVar, Union
|
||||
|
||||
from wsproto.events import Ping
|
||||
from werkzeug import Request, Response
|
||||
from werkzeug.datastructures import MultiDict
|
||||
from wsproto.frame_protocol import CloseReason
|
||||
from wsproto import ConnectionType, WSConnection
|
||||
from wsproto.events import (
|
||||
AcceptConnection,
|
||||
BytesMessage,
|
||||
CloseConnection,
|
||||
Ping,
|
||||
TextMessage,
|
||||
)
|
||||
from wsproto.events import Request as WSRequest
|
||||
from wsproto import WSConnection, ConnectionType
|
||||
from wsproto.events import TextMessage, BytesMessage, CloseConnection, AcceptConnection
|
||||
from wsproto.frame_protocol import CloseReason
|
||||
|
||||
K = TypeVar("K")
|
||||
V = TypeVar("V")
|
||||
|
@ -1,7 +1,7 @@
|
||||
from nonebot import on_message
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.adapters import Event, Message
|
||||
from nonebot.params import ArgStr, Received, EventMessage, LastReceived
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.params import ArgStr, EventMessage, LastReceived, Received
|
||||
|
||||
test_handle = on_message()
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
from typing import Annotated
|
||||
|
||||
from nonebot.adapters import Message
|
||||
from nonebot.params import Arg, ArgStr, ArgPlainText
|
||||
from nonebot.params import Arg, ArgPlainText, ArgStr
|
||||
|
||||
|
||||
async def arg(key: Message = Arg()) -> Message:
|
||||
@ -34,6 +34,6 @@ async def annotated_prior_arg(key: Annotated[str, ArgStr("foo")] = ArgPlainText(
|
||||
|
||||
|
||||
async def annotated_multi_arg(
|
||||
key: Annotated[Annotated[str, ArgStr("foo")], ArgPlainText()]
|
||||
key: Annotated[Annotated[str, ArgStr("foo")], ArgPlainText()],
|
||||
):
|
||||
return key
|
||||
|
@ -1,4 +1,4 @@
|
||||
from typing import Union, TypeVar
|
||||
from typing import TypeVar, Union
|
||||
|
||||
from nonebot.adapters import Bot
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
from typing import Annotated
|
||||
from dataclasses import dataclass
|
||||
from typing import Annotated
|
||||
|
||||
import anyio
|
||||
from pydantic import Field
|
||||
@ -74,13 +74,13 @@ async def annotated_class_depend(c: Annotated[ClassDependency, Depends()]):
|
||||
|
||||
# test dependency priority
|
||||
async def annotated_prior_depend(
|
||||
x: Annotated[int, Depends(lambda: 2)] = Depends(dependency)
|
||||
x: Annotated[int, Depends(lambda: 2)] = Depends(dependency),
|
||||
):
|
||||
return x
|
||||
|
||||
|
||||
async def annotated_multi_depend(
|
||||
x: Annotated[Annotated[int, Depends(lambda: 2)], Depends(dependency)]
|
||||
x: Annotated[Annotated[int, Depends(lambda: 2)], Depends(dependency)],
|
||||
):
|
||||
return x
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
from typing import Union, TypeVar
|
||||
from typing import TypeVar, Union
|
||||
|
||||
from nonebot.adapters import Event, Message
|
||||
from nonebot.params import EventToMe, EventType, EventMessage, EventPlainText
|
||||
from nonebot.params import EventMessage, EventPlainText, EventToMe, EventType
|
||||
|
||||
|
||||
async def event(e: Event) -> Event:
|
||||
|
@ -1,8 +1,8 @@
|
||||
from typing import Union, TypeVar
|
||||
from typing import TypeVar, Union
|
||||
|
||||
from nonebot.adapters import Event
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.params import Received, LastReceived
|
||||
from nonebot.params import LastReceived, Received
|
||||
|
||||
|
||||
async def matcher(m: Matcher) -> Matcher:
|
||||
|
@ -1,24 +1,24 @@
|
||||
from re import Match
|
||||
|
||||
from nonebot.typing import T_State
|
||||
from nonebot.adapters import Message
|
||||
from nonebot.params import (
|
||||
Command,
|
||||
Keyword,
|
||||
Endswith,
|
||||
RegexStr,
|
||||
Fullmatch,
|
||||
RegexDict,
|
||||
CommandArg,
|
||||
RawCommand,
|
||||
RegexGroup,
|
||||
Startswith,
|
||||
CommandStart,
|
||||
CommandWhitespace,
|
||||
Endswith,
|
||||
Fullmatch,
|
||||
Keyword,
|
||||
RawCommand,
|
||||
RegexDict,
|
||||
RegexGroup,
|
||||
RegexMatched,
|
||||
RegexStr,
|
||||
ShellCommandArgs,
|
||||
ShellCommandArgv,
|
||||
CommandWhitespace,
|
||||
Startswith,
|
||||
)
|
||||
from nonebot.typing import T_State
|
||||
|
||||
|
||||
async def state(x: T_State) -> T_State:
|
||||
|
@ -1,9 +1,9 @@
|
||||
from typing import Optional
|
||||
|
||||
from nonebot.typing import T_State
|
||||
from nonebot.adapters import Bot, Event, Message
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.params import Arg, Depends
|
||||
from nonebot.adapters import Bot, Event, Message
|
||||
from nonebot.typing import T_State
|
||||
|
||||
|
||||
def dependency():
|
||||
|
@ -1,24 +1,24 @@
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from nonebot.adapters import Event
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot import (
|
||||
CommandGroup,
|
||||
MatcherGroup,
|
||||
on,
|
||||
on_type,
|
||||
on_regex,
|
||||
on_notice,
|
||||
on_command,
|
||||
on_keyword,
|
||||
on_message,
|
||||
on_request,
|
||||
on_endswith,
|
||||
on_fullmatch,
|
||||
on_keyword,
|
||||
on_message,
|
||||
on_metaevent,
|
||||
on_startswith,
|
||||
on_notice,
|
||||
on_regex,
|
||||
on_request,
|
||||
on_shell_command,
|
||||
on_startswith,
|
||||
on_type,
|
||||
)
|
||||
from nonebot.adapters import Event
|
||||
from nonebot.matcher import Matcher
|
||||
|
||||
|
||||
async def rule() -> bool:
|
||||
|
5
tests/pyproject.toml
Normal file
5
tests/pyproject.toml
Normal file
@ -0,0 +1,5 @@
|
||||
[tool.ruff]
|
||||
extend = "../pyproject.toml"
|
||||
|
||||
[tool.ruff.lint.isort]
|
||||
known-first-party = ["nonebot", "fake_server", "utils"]
|
@ -1,20 +1,20 @@
|
||||
from typing import Optional
|
||||
from contextlib import asynccontextmanager
|
||||
from typing import Optional
|
||||
|
||||
import pytest
|
||||
from nonebug import App
|
||||
import pytest
|
||||
|
||||
from utils import FakeAdapter
|
||||
from nonebot.adapters import Bot
|
||||
from nonebot.drivers import (
|
||||
URL,
|
||||
Driver,
|
||||
HTTPServerSetup,
|
||||
Request,
|
||||
Response,
|
||||
WebSocket,
|
||||
HTTPServerSetup,
|
||||
WebSocketServerSetup,
|
||||
)
|
||||
from utils import FakeAdapter
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
|
@ -1,8 +1,8 @@
|
||||
from typing import Any, Optional
|
||||
|
||||
import anyio
|
||||
import pytest
|
||||
from nonebug import App
|
||||
import pytest
|
||||
|
||||
from nonebot.adapters import Bot
|
||||
from nonebot.exception import MockApiException
|
||||
|
@ -1,9 +1,9 @@
|
||||
import pytest
|
||||
from pydantic import ValidationError
|
||||
import pytest
|
||||
|
||||
from nonebot.adapters import Message, MessageSegment
|
||||
from nonebot.compat import type_validate_python
|
||||
from utils import FakeMessage, FakeMessageSegment
|
||||
from nonebot.adapters import Message, MessageSegment
|
||||
|
||||
|
||||
def test_segment_data():
|
||||
|
@ -1,24 +1,24 @@
|
||||
import sys
|
||||
from typing import Optional
|
||||
|
||||
import pytest
|
||||
from nonebug import App
|
||||
import pytest
|
||||
|
||||
from nonebot import on_message
|
||||
import nonebot.message as message
|
||||
from utils import make_fake_event
|
||||
from nonebot.params import Depends
|
||||
from nonebot.typing import T_State
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.adapters import Bot, Event
|
||||
from nonebot.exception import IgnoredException
|
||||
from nonebot.log import logger, default_filter, default_format
|
||||
from nonebot.log import default_filter, default_format, logger
|
||||
from nonebot.matcher import Matcher
|
||||
import nonebot.message as message
|
||||
from nonebot.message import (
|
||||
run_preprocessor,
|
||||
run_postprocessor,
|
||||
event_preprocessor,
|
||||
event_postprocessor,
|
||||
event_preprocessor,
|
||||
run_postprocessor,
|
||||
run_preprocessor,
|
||||
)
|
||||
from nonebot.params import Depends
|
||||
from nonebot.typing import T_State
|
||||
from utils import make_fake_event
|
||||
|
||||
|
||||
async def _dependency() -> int:
|
||||
|
@ -1,17 +1,17 @@
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Optional, Annotated
|
||||
from typing import Annotated, Any, Optional
|
||||
|
||||
import pytest
|
||||
from pydantic import BaseModel, ValidationError
|
||||
import pytest
|
||||
|
||||
from nonebot.compat import (
|
||||
DEFAULT_CONFIG,
|
||||
Required,
|
||||
FieldInfo,
|
||||
TypeAdapter,
|
||||
PydanticUndefined,
|
||||
model_dump,
|
||||
Required,
|
||||
TypeAdapter,
|
||||
custom_validation,
|
||||
model_dump,
|
||||
type_validate_json,
|
||||
type_validate_python,
|
||||
)
|
||||
|
@ -1,10 +1,10 @@
|
||||
from typing import TYPE_CHECKING, Union, Optional
|
||||
from typing import TYPE_CHECKING, Optional, Union
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
import pytest
|
||||
from pydantic import Field, BaseModel
|
||||
|
||||
from nonebot.compat import PYDANTIC_V2
|
||||
from nonebot.config import DOTENV_TYPE, BaseSettings, SettingsError, SettingsConfig
|
||||
from nonebot.config import DOTENV_TYPE, BaseSettings, SettingsConfig, SettingsError
|
||||
|
||||
|
||||
class Simple(BaseModel):
|
||||
|
@ -1,28 +1,28 @@
|
||||
from http.cookies import SimpleCookie
|
||||
import json
|
||||
from typing import Any, Optional
|
||||
from http.cookies import SimpleCookie
|
||||
|
||||
import anyio
|
||||
import pytest
|
||||
from nonebug import App
|
||||
import pytest
|
||||
|
||||
from utils import FakeAdapter
|
||||
from nonebot.adapters import Bot
|
||||
from nonebot.params import Depends
|
||||
from nonebot.dependencies import Dependent
|
||||
from nonebot.exception import WebSocketClosed
|
||||
from nonebot.drivers import (
|
||||
URL,
|
||||
Driver,
|
||||
Request,
|
||||
Response,
|
||||
ASGIMixin,
|
||||
WebSocket,
|
||||
Driver,
|
||||
HTTPClientMixin,
|
||||
HTTPServerSetup,
|
||||
Request,
|
||||
Response,
|
||||
WebSocket,
|
||||
WebSocketClientMixin,
|
||||
WebSocketServerSetup,
|
||||
)
|
||||
from nonebot.exception import WebSocketClosed
|
||||
from nonebot.params import Depends
|
||||
from utils import FakeAdapter
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
|
@ -1,5 +1,5 @@
|
||||
import pytest
|
||||
from nonebug import App
|
||||
import pytest
|
||||
|
||||
from utils import FakeMessage, FakeMessageSegment, make_fake_event
|
||||
|
||||
|
@ -1,17 +1,17 @@
|
||||
import pytest
|
||||
from nonebug import App
|
||||
import pytest
|
||||
|
||||
import nonebot
|
||||
from nonebot.drivers import Driver, ASGIMixin, ReverseDriver
|
||||
from nonebot import (
|
||||
get_app,
|
||||
get_bot,
|
||||
get_asgi,
|
||||
get_bots,
|
||||
get_driver,
|
||||
get_adapter,
|
||||
get_adapters,
|
||||
get_app,
|
||||
get_asgi,
|
||||
get_bot,
|
||||
get_bots,
|
||||
get_driver,
|
||||
)
|
||||
from nonebot.drivers import ASGIMixin, Driver, ReverseDriver
|
||||
|
||||
|
||||
def test_init():
|
||||
|
@ -1,15 +1,15 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
from nonebug import App
|
||||
import pytest
|
||||
|
||||
from nonebot.rule import Rule
|
||||
from nonebot import get_plugin
|
||||
from nonebot.matcher import Matcher, matchers
|
||||
from utils import FakeMessage, make_fake_event
|
||||
from nonebot.permission import User, Permission
|
||||
from nonebot.message import _check_matcher, check_and_run_matcher
|
||||
from nonebot.permission import Permission, User
|
||||
from nonebot.rule import Rule
|
||||
from utils import FakeMessage, make_fake_event
|
||||
|
||||
|
||||
def test_matcher_info(app: App):
|
||||
@ -211,7 +211,7 @@ async def test_matcher_destroy(app: App):
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_type_updater(app: App):
|
||||
from plugins.matcher.matcher_type import test_type_updater, test_custom_updater
|
||||
from plugins.matcher.matcher_type import test_custom_updater, test_type_updater
|
||||
|
||||
event = make_fake_event()()
|
||||
|
||||
@ -276,8 +276,8 @@ async def test_user_permission_updater(app: App):
|
||||
@pytest.mark.anyio
|
||||
async def test_custom_permission_updater(app: App):
|
||||
from plugins.matcher.matcher_permission import (
|
||||
new_permission,
|
||||
default_permission,
|
||||
new_permission,
|
||||
test_custom_updater,
|
||||
)
|
||||
|
||||
|
@ -1,38 +1,38 @@
|
||||
import re
|
||||
|
||||
import pytest
|
||||
from nonebug import App
|
||||
from exceptiongroup import BaseExceptionGroup
|
||||
from nonebug import App
|
||||
import pytest
|
||||
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.consts import (
|
||||
CMD_ARG_KEY,
|
||||
CMD_KEY,
|
||||
CMD_START_KEY,
|
||||
CMD_WHITESPACE_KEY,
|
||||
ENDSWITH_KEY,
|
||||
FULLMATCH_KEY,
|
||||
KEYWORD_KEY,
|
||||
PREFIX_KEY,
|
||||
RAW_CMD_KEY,
|
||||
REGEX_MATCHED,
|
||||
SHELL_ARGS,
|
||||
SHELL_ARGV,
|
||||
STARTSWITH_KEY,
|
||||
)
|
||||
from nonebot.dependencies import Dependent
|
||||
from nonebot.exception import TypeMisMatch
|
||||
from utils import FakeMessage, make_fake_event
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.params import (
|
||||
ArgParam,
|
||||
BotParam,
|
||||
EventParam,
|
||||
StateParam,
|
||||
DependParam,
|
||||
DefaultParam,
|
||||
MatcherParam,
|
||||
DependParam,
|
||||
EventParam,
|
||||
ExceptionParam,
|
||||
MatcherParam,
|
||||
StateParam,
|
||||
)
|
||||
from nonebot.consts import (
|
||||
CMD_KEY,
|
||||
PREFIX_KEY,
|
||||
SHELL_ARGS,
|
||||
SHELL_ARGV,
|
||||
CMD_ARG_KEY,
|
||||
KEYWORD_KEY,
|
||||
RAW_CMD_KEY,
|
||||
ENDSWITH_KEY,
|
||||
CMD_START_KEY,
|
||||
FULLMATCH_KEY,
|
||||
REGEX_MATCHED,
|
||||
STARTSWITH_KEY,
|
||||
CMD_WHITESPACE_KEY,
|
||||
)
|
||||
from utils import FakeMessage, make_fake_event
|
||||
|
||||
UNKNOWN_PARAM = "Unknown parameter"
|
||||
|
||||
@ -41,21 +41,21 @@ UNKNOWN_PARAM = "Unknown parameter"
|
||||
async def test_depend(app: App):
|
||||
from plugins.param.param_depend import (
|
||||
ClassDependency,
|
||||
runned,
|
||||
depends,
|
||||
validate,
|
||||
class_depend,
|
||||
test_depends,
|
||||
validate_fail,
|
||||
validate_field,
|
||||
annotated_depend,
|
||||
sub_type_mismatch,
|
||||
validate_field_fail,
|
||||
cache_exception_func1,
|
||||
cache_exception_func2,
|
||||
annotated_class_depend,
|
||||
annotated_depend,
|
||||
annotated_multi_depend,
|
||||
annotated_prior_depend,
|
||||
cache_exception_func1,
|
||||
cache_exception_func2,
|
||||
class_depend,
|
||||
depends,
|
||||
runned,
|
||||
sub_type_mismatch,
|
||||
test_depends,
|
||||
validate,
|
||||
validate_fail,
|
||||
validate_field,
|
||||
validate_field_fail,
|
||||
)
|
||||
|
||||
async with app.test_dependent(depends, allow_types=[DependParam]) as ctx:
|
||||
@ -157,15 +157,15 @@ async def test_depend(app: App):
|
||||
async def test_bot(app: App):
|
||||
from plugins.param.param_bot import (
|
||||
FooBot,
|
||||
generic_bot,
|
||||
generic_bot_none,
|
||||
get_bot,
|
||||
legacy_bot,
|
||||
not_bot,
|
||||
not_legacy_bot,
|
||||
postpone_bot,
|
||||
sub_bot,
|
||||
union_bot,
|
||||
legacy_bot,
|
||||
generic_bot,
|
||||
postpone_bot,
|
||||
not_legacy_bot,
|
||||
generic_bot_none,
|
||||
)
|
||||
|
||||
async with app.test_dependent(get_bot, allow_types=[BotParam]) as ctx:
|
||||
@ -223,18 +223,18 @@ async def test_event(app: App):
|
||||
from plugins.param.param_event import (
|
||||
FooEvent,
|
||||
event,
|
||||
not_event,
|
||||
sub_event,
|
||||
event_type,
|
||||
event_to_me,
|
||||
union_event,
|
||||
legacy_event,
|
||||
event_message,
|
||||
generic_event,
|
||||
postpone_event,
|
||||
event_plain_text,
|
||||
not_legacy_event,
|
||||
event_to_me,
|
||||
event_type,
|
||||
generic_event,
|
||||
generic_event_none,
|
||||
legacy_event,
|
||||
not_event,
|
||||
not_legacy_event,
|
||||
postpone_event,
|
||||
sub_event,
|
||||
union_event,
|
||||
)
|
||||
|
||||
fake_message = FakeMessage("text")
|
||||
@ -310,25 +310,25 @@ async def test_event(app: App):
|
||||
@pytest.mark.anyio
|
||||
async def test_state(app: App):
|
||||
from plugins.param.param_state import (
|
||||
state,
|
||||
command,
|
||||
keyword,
|
||||
command_arg,
|
||||
command_start,
|
||||
command_whitespace,
|
||||
endswith,
|
||||
fullmatch,
|
||||
regex_str,
|
||||
regex_dict,
|
||||
startswith,
|
||||
command_arg,
|
||||
raw_command,
|
||||
regex_group,
|
||||
keyword,
|
||||
legacy_state,
|
||||
command_start,
|
||||
regex_matched,
|
||||
postpone_state,
|
||||
not_legacy_state,
|
||||
command_whitespace,
|
||||
postpone_state,
|
||||
raw_command,
|
||||
regex_dict,
|
||||
regex_group,
|
||||
regex_matched,
|
||||
regex_str,
|
||||
shell_command_args,
|
||||
shell_command_argv,
|
||||
startswith,
|
||||
state,
|
||||
)
|
||||
|
||||
fake_message = FakeMessage("text")
|
||||
@ -462,17 +462,17 @@ async def test_state(app: App):
|
||||
async def test_matcher(app: App):
|
||||
from plugins.param.param_matcher import (
|
||||
FooMatcher,
|
||||
matcher,
|
||||
receive,
|
||||
not_matcher,
|
||||
sub_matcher,
|
||||
last_receive,
|
||||
union_matcher,
|
||||
legacy_matcher,
|
||||
generic_matcher,
|
||||
postpone_matcher,
|
||||
not_legacy_matcher,
|
||||
generic_matcher_none,
|
||||
last_receive,
|
||||
legacy_matcher,
|
||||
matcher,
|
||||
not_legacy_matcher,
|
||||
not_matcher,
|
||||
postpone_matcher,
|
||||
receive,
|
||||
sub_matcher,
|
||||
union_matcher,
|
||||
)
|
||||
|
||||
fake_matcher = Matcher()
|
||||
@ -542,14 +542,14 @@ async def test_matcher(app: App):
|
||||
@pytest.mark.anyio
|
||||
async def test_arg(app: App):
|
||||
from plugins.param.param_arg import (
|
||||
arg,
|
||||
arg_str,
|
||||
annotated_arg,
|
||||
arg_plain_text,
|
||||
annotated_arg_plain_text,
|
||||
annotated_arg_str,
|
||||
annotated_multi_arg,
|
||||
annotated_prior_arg,
|
||||
annotated_arg_plain_text,
|
||||
arg,
|
||||
arg_plain_text,
|
||||
arg_str,
|
||||
)
|
||||
|
||||
matcher = Matcher()
|
||||
|
@ -1,25 +1,25 @@
|
||||
from typing import Optional
|
||||
|
||||
import pytest
|
||||
from nonebug import App
|
||||
import pytest
|
||||
|
||||
from utils import make_fake_event
|
||||
from nonebot.exception import SkippedException
|
||||
from nonebot.permission import (
|
||||
USER,
|
||||
NOTICE,
|
||||
MESSAGE,
|
||||
REQUEST,
|
||||
METAEVENT,
|
||||
NOTICE,
|
||||
REQUEST,
|
||||
SUPERUSER,
|
||||
User,
|
||||
Notice,
|
||||
USER,
|
||||
Message,
|
||||
Request,
|
||||
MetaEvent,
|
||||
SuperUser,
|
||||
Notice,
|
||||
Permission,
|
||||
Request,
|
||||
SuperUser,
|
||||
User,
|
||||
)
|
||||
from utils import make_fake_event
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
|
@ -1,8 +1,8 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from functools import wraps
|
||||
from dataclasses import asdict
|
||||
from typing import TypeVar, Callable
|
||||
from functools import wraps
|
||||
from pathlib import Path
|
||||
import sys
|
||||
from typing import Callable, TypeVar
|
||||
from typing_extensions import ParamSpec
|
||||
|
||||
import pytest
|
||||
@ -11,8 +11,8 @@ import nonebot
|
||||
from nonebot.plugin import (
|
||||
Plugin,
|
||||
PluginManager,
|
||||
_plugins,
|
||||
_managers,
|
||||
_plugins,
|
||||
inherit_supported_adapters,
|
||||
)
|
||||
|
||||
@ -21,7 +21,6 @@ R = TypeVar("R")
|
||||
|
||||
|
||||
def _recover(func: Callable[P, R]) -> Callable[P, R]:
|
||||
|
||||
@wraps(func)
|
||||
def _wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
|
||||
origin_managers = _managers.copy()
|
||||
|
@ -4,18 +4,18 @@ import pytest
|
||||
|
||||
import nonebot
|
||||
from nonebot.adapters import Event
|
||||
from nonebot.typing import T_RuleChecker
|
||||
from nonebot.matcher import Matcher, matchers
|
||||
from nonebot.rule import (
|
||||
RegexRule,
|
||||
IsTypeRule,
|
||||
CommandRule,
|
||||
EndswithRule,
|
||||
KeywordsRule,
|
||||
FullmatchRule,
|
||||
StartswithRule,
|
||||
IsTypeRule,
|
||||
KeywordsRule,
|
||||
RegexRule,
|
||||
ShellCommandRule,
|
||||
StartswithRule,
|
||||
)
|
||||
from nonebot.typing import T_RuleChecker
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@ -109,12 +109,12 @@ def test_on(
|
||||
import plugins.plugin.matchers as module
|
||||
from plugins.plugin.matchers import (
|
||||
TestEvent,
|
||||
expire_time,
|
||||
handler,
|
||||
permission,
|
||||
priority,
|
||||
rule,
|
||||
state,
|
||||
handler,
|
||||
priority,
|
||||
permission,
|
||||
expire_time,
|
||||
)
|
||||
|
||||
matcher = getattr(module, matcher_name)
|
||||
|
@ -1,52 +1,52 @@
|
||||
import re
|
||||
from re import Match
|
||||
from typing import Union, Optional
|
||||
from typing import Optional, Union
|
||||
|
||||
import pytest
|
||||
from nonebug import App
|
||||
import pytest
|
||||
|
||||
from nonebot.typing import T_State
|
||||
from nonebot.exception import ParserExit, SkippedException
|
||||
from utils import FakeMessage, FakeMessageSegment, make_fake_event
|
||||
from nonebot.consts import (
|
||||
CMD_KEY,
|
||||
PREFIX_KEY,
|
||||
SHELL_ARGS,
|
||||
SHELL_ARGV,
|
||||
CMD_ARG_KEY,
|
||||
KEYWORD_KEY,
|
||||
CMD_KEY,
|
||||
CMD_WHITESPACE_KEY,
|
||||
ENDSWITH_KEY,
|
||||
FULLMATCH_KEY,
|
||||
KEYWORD_KEY,
|
||||
PREFIX_KEY,
|
||||
REGEX_MATCHED,
|
||||
SHELL_ARGS,
|
||||
SHELL_ARGV,
|
||||
STARTSWITH_KEY,
|
||||
CMD_WHITESPACE_KEY,
|
||||
)
|
||||
from nonebot.exception import ParserExit, SkippedException
|
||||
from nonebot.rule import (
|
||||
CMD_RESULT,
|
||||
TRIE_VALUE,
|
||||
Rule,
|
||||
ToMeRule,
|
||||
TrieRule,
|
||||
Namespace,
|
||||
RegexRule,
|
||||
IsTypeRule,
|
||||
ArgumentParser,
|
||||
CommandRule,
|
||||
EndswithRule,
|
||||
KeywordsRule,
|
||||
FullmatchRule,
|
||||
ArgumentParser,
|
||||
StartswithRule,
|
||||
IsTypeRule,
|
||||
KeywordsRule,
|
||||
Namespace,
|
||||
RegexRule,
|
||||
Rule,
|
||||
ShellCommandRule,
|
||||
regex,
|
||||
to_me,
|
||||
StartswithRule,
|
||||
ToMeRule,
|
||||
TrieRule,
|
||||
command,
|
||||
is_type,
|
||||
keyword,
|
||||
endswith,
|
||||
fullmatch,
|
||||
startswith,
|
||||
is_type,
|
||||
keyword,
|
||||
regex,
|
||||
shell_command,
|
||||
startswith,
|
||||
to_me,
|
||||
)
|
||||
from nonebot.typing import T_State
|
||||
from utils import FakeMessage, FakeMessageSegment, make_fake_event
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
|
@ -7,7 +7,7 @@ from utils import make_fake_event
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_matcher_mutex():
|
||||
from nonebot.plugins.single_session import matcher_mutex, _running_matcher
|
||||
from nonebot.plugins.single_session import _running_matcher, matcher_mutex
|
||||
|
||||
am = asynccontextmanager(matcher_mutex)
|
||||
event = make_fake_event()()
|
||||
|
@ -1,15 +1,15 @@
|
||||
import json
|
||||
from typing import Dict, List, Union, Literal, TypeVar, ClassVar # noqa: UP035
|
||||
from typing import ClassVar, Dict, List, Literal, TypeVar, Union # noqa: UP035
|
||||
|
||||
from utils import FakeMessage, FakeMessageSegment
|
||||
from nonebot.utils import (
|
||||
DataclassEncoder,
|
||||
escape_tag,
|
||||
is_gen_callable,
|
||||
generic_check_issubclass,
|
||||
is_async_gen_callable,
|
||||
is_coroutine_callable,
|
||||
generic_check_issubclass,
|
||||
is_gen_callable,
|
||||
)
|
||||
from utils import FakeMessage, FakeMessageSegment
|
||||
|
||||
|
||||
def test_loguru_escape_tag():
|
||||
|
@ -1,10 +1,10 @@
|
||||
from typing import Union, Optional
|
||||
from collections.abc import Iterable, Mapping
|
||||
from typing import Optional, Union
|
||||
from typing_extensions import override
|
||||
from collections.abc import Mapping, Iterable
|
||||
|
||||
from pydantic import Extra, create_model
|
||||
from pydantic import create_model
|
||||
|
||||
from nonebot.adapters import Bot, Event, Adapter, Message, MessageSegment
|
||||
from nonebot.adapters import Adapter, Bot, Event, Message, MessageSegment
|
||||
|
||||
|
||||
def escape_text(s: str, *, escape_comma: bool = True) -> str:
|
||||
@ -89,7 +89,7 @@ def make_fake_event(
|
||||
) -> type[Event]:
|
||||
Base = _base or Event
|
||||
|
||||
class FakeEvent(Base, extra=Extra.forbid):
|
||||
class FakeEvent(Base):
|
||||
@override
|
||||
def get_type(self) -> str:
|
||||
return _type
|
||||
|
Reference in New Issue
Block a user