mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
✅ Sourcery建议
This commit is contained in:
parent
5b3f0271cb
commit
ec9b2abb53
@ -43,17 +43,6 @@ def init_mocked_api(mocked_api: MockRouter) -> None:
|
|||||||
).respond(content=b"")
|
).respond(content=b"")
|
||||||
|
|
||||||
|
|
||||||
def init_mocker(mocker: MockerFixture, tmp_path: Path) -> None:
|
|
||||||
mocker.patch(
|
|
||||||
"zhenxun.builtin_plugins.plugin_store.data_source.BASE_PATH",
|
|
||||||
return_value=tmp_path / "zhenxun",
|
|
||||||
)
|
|
||||||
mocker.patch(
|
|
||||||
"zhenxun.builtin_plugins.plugin_store.data_source.install_requirement",
|
|
||||||
return_value=None,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_add_plugin_basic(
|
async def test_add_plugin_basic(
|
||||||
app: App,
|
app: App,
|
||||||
mocker: MockerFixture,
|
mocker: MockerFixture,
|
||||||
@ -67,7 +56,10 @@ async def test_add_plugin_basic(
|
|||||||
from zhenxun.builtin_plugins.plugin_store import _matcher
|
from zhenxun.builtin_plugins.plugin_store import _matcher
|
||||||
|
|
||||||
init_mocked_api(mocked_api)
|
init_mocked_api(mocked_api)
|
||||||
init_mocker(mocker, tmp_path)
|
mocker.patch(
|
||||||
|
"zhenxun.builtin_plugins.plugin_store.data_source.BASE_PATH",
|
||||||
|
return_value=tmp_path / "zhenxun",
|
||||||
|
)
|
||||||
|
|
||||||
plugin_id = 1
|
plugin_id = 1
|
||||||
|
|
||||||
@ -114,8 +106,11 @@ async def test_add_plugin_extra(
|
|||||||
"""
|
"""
|
||||||
from zhenxun.builtin_plugins.plugin_store import _matcher
|
from zhenxun.builtin_plugins.plugin_store import _matcher
|
||||||
|
|
||||||
init_mocker(mocker, tmp_path)
|
|
||||||
init_mocked_api(mocked_api)
|
init_mocked_api(mocked_api)
|
||||||
|
mocker.patch(
|
||||||
|
"zhenxun.builtin_plugins.plugin_store.data_source.BASE_PATH",
|
||||||
|
return_value=tmp_path / "zhenxun",
|
||||||
|
)
|
||||||
|
|
||||||
plugin_id = 3
|
plugin_id = 3
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@ -13,8 +12,6 @@ from nonebug.mixin.process import MatcherContext
|
|||||||
|
|
||||||
from tests.config import BotId, UserId
|
from tests.config import BotId, UserId
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
pass
|
|
||||||
nonebot.load_plugin("nonebot_plugin_session")
|
nonebot.load_plugin("nonebot_plugin_session")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -6,13 +6,19 @@ from nonebot.adapters.onebot.v11 import Message, MessageSegment, GroupMessageEve
|
|||||||
|
|
||||||
|
|
||||||
def get_response_json(path: str) -> dict:
|
def get_response_json(path: str) -> dict:
|
||||||
return json.loads(
|
try:
|
||||||
(Path(__file__).parent / "response" / path).read_text(encoding="utf8")
|
return json.loads(
|
||||||
)
|
(Path(__file__).parent / "response" / path).read_text(encoding="utf8")
|
||||||
|
)
|
||||||
|
except (FileNotFoundError, json.JSONDecodeError) as e:
|
||||||
|
raise ValueError(f"Error reading or parsing JSON file: {e}") from e
|
||||||
|
|
||||||
|
|
||||||
def get_content_bytes(path: str) -> bytes:
|
def get_content_bytes(path: str) -> bytes:
|
||||||
return (Path(__file__).parent / "content" / path).read_bytes()
|
try:
|
||||||
|
return (Path(__file__).parent / "content" / path).read_bytes()
|
||||||
|
except FileNotFoundError as e:
|
||||||
|
raise ValueError(f"Error reading file: {e}") from e
|
||||||
|
|
||||||
|
|
||||||
def _v11_group_message_event(
|
def _v11_group_message_event(
|
||||||
|
|||||||
@ -86,8 +86,8 @@ async def download_file(url: str, _is: bool = False, api_url: str | None = None)
|
|||||||
for download_url, path in data_list:
|
for download_url, path in data_list:
|
||||||
if download_url and "." in path:
|
if download_url and "." in path:
|
||||||
logger.debug(f"下载文件: {path}", "插件管理")
|
logger.debug(f"下载文件: {path}", "插件管理")
|
||||||
base_path = "zhenxun/plugins/" if _is else "zhenxun/"
|
base_path = BASE_PATH / "plugins" if _is else BASE_PATH
|
||||||
file = Path(f"{base_path}{path}")
|
file = base_path / path
|
||||||
file.parent.mkdir(parents=True, exist_ok=True)
|
file.parent.mkdir(parents=True, exist_ok=True)
|
||||||
r = await AsyncHttpx.get(download_url)
|
r = await AsyncHttpx.get(download_url)
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user