From 2b77e313ec23895b131cb0ad64ea309835868dc4 Mon Sep 17 00:00:00 2001 From: molanp <104612722+molanp@users.noreply.github.com> Date: Mon, 16 Dec 2024 23:04:06 +0800 Subject: [PATCH 01/15] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbot-check=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/bot_check.yml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/bot_check.yml b/.github/workflows/bot_check.yml index ac532629..8e04f5cc 100644 --- a/.github/workflows/bot_check.yml +++ b/.github/workflows/bot_check.yml @@ -2,13 +2,13 @@ name: 检查bot是否运行正常 on: push: - branches: ["dev", "main"] + branches: ["main"] paths: - zhenxun/** - tests/** - bot.py pull_request: - branches: ["dev", "main"] + branches: ["main"] paths: - zhenxun/** - tests/** @@ -55,8 +55,17 @@ jobs: if: steps.cache-poetry.outputs.cache-hit != 'true' run: | rm -rf poetry.lock - poetry source remove ali + poetry source remove aliyun poetry install --no-root + + - name: Install playwright + if: steps.cache-playwright.outputs.cache-hit != 'true' + run: | + portey run sudo apt-get update + poetry run sudo apt-get install -y libgstreamer-plugins-base1.0-0 libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-libav flite x264 libx264-dev + poetry run sudo playwright install-deps + poetry run pip install playwright + poetry run sudo playwright install - name: Run tests run: poetry run pytest --cov=zhenxun --cov-report xml From 0d4c9b553e3185e09e1d86e5620a3b79f9c85627 Mon Sep 17 00:00:00 2001 From: molanp <104612722+molanp@users.noreply.github.com> Date: Mon, 16 Dec 2024 23:09:03 +0800 Subject: [PATCH 02/15] Update bot_check.yml --- .github/workflows/bot_check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bot_check.yml b/.github/workflows/bot_check.yml index 8e04f5cc..1a5ed8cf 100644 --- a/.github/workflows/bot_check.yml +++ b/.github/workflows/bot_check.yml @@ -61,7 +61,7 @@ jobs: - name: Install playwright if: steps.cache-playwright.outputs.cache-hit != 'true' run: | - portey run sudo apt-get update + poetry run sudo apt-get update poetry run sudo apt-get install -y libgstreamer-plugins-base1.0-0 libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-libav flite x264 libx264-dev poetry run sudo playwright install-deps poetry run pip install playwright From e660288236d814717328c4e080a6bf40d9df2201 Mon Sep 17 00:00:00 2001 From: molanp <104612722+molanp@users.noreply.github.com> Date: Mon, 16 Dec 2024 23:13:06 +0800 Subject: [PATCH 03/15] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BE=9D=E8=B5=96?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 990bc92b..53a6af78 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "zhenxun_bot" -version = "0.1.1" +version = "0.2.4" description = "基于 Nonebot2 和 go-cqhttp 开发,以 postgresql 作为数据库,非常可爱的绪山真寻bot" authors = ["HibiKier <775757368@qq.com>"] license = "AGPL" @@ -47,10 +47,10 @@ python-multipart = "^0.0.9" aiocache = "^0.12.2" py-cpuinfo = "^9.0.0" nonebot-plugin-uninfo = "^0.4.1" -nonebot-plugin-alconna = "^0.53.1" +nonebot-plugin-alconna = "^0.54.0" [tool.poetry.dev-dependencies] -nonebug = "^0.3.2" +nonebug = "^0.4.2" pytest-cov = "^5.0.0" pytest-mock = "^3.6.1" pytest-asyncio = "^0.23.5" From c56f3be55345e58e1457cc7e71d356ab6dbce061 Mon Sep 17 00:00:00 2001 From: molanp <104612722+molanp@users.noreply.github.com> Date: Wed, 18 Dec 2024 22:41:13 +0800 Subject: [PATCH 04/15] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=B7=A5=E4=BD=9C?= =?UTF-8?q?=E6=B5=81=E6=89=A7=E8=A1=8C=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/bot_check.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/bot_check.yml b/.github/workflows/bot_check.yml index 1a5ed8cf..0adf66ab 100644 --- a/.github/workflows/bot_check.yml +++ b/.github/workflows/bot_check.yml @@ -54,7 +54,6 @@ jobs: - name: Install dependencies if: steps.cache-poetry.outputs.cache-hit != 'true' run: | - rm -rf poetry.lock poetry source remove aliyun poetry install --no-root @@ -63,8 +62,8 @@ jobs: run: | poetry run sudo apt-get update poetry run sudo apt-get install -y libgstreamer-plugins-base1.0-0 libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-libav flite x264 libx264-dev - poetry run sudo playwright install-deps poetry run pip install playwright + poetry run sudo playwright install-deps poetry run sudo playwright install - name: Run tests From fabc7444df0371307e1c0e59b335d12e6db3e104 Mon Sep 17 00:00:00 2001 From: molanp <104612722+molanp@users.noreply.github.com> Date: Wed, 18 Dec 2024 22:42:37 +0800 Subject: [PATCH 05/15] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/builtin_plugins/plugin_store/test_update_all_plugin.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/builtin_plugins/plugin_store/test_update_all_plugin.py b/tests/builtin_plugins/plugin_store/test_update_all_plugin.py index 640391c8..7fc3b588 100644 --- a/tests/builtin_plugins/plugin_store/test_update_all_plugin.py +++ b/tests/builtin_plugins/plugin_store/test_update_all_plugin.py @@ -57,7 +57,9 @@ async def test_update_all_plugin_basic_need_update( ) ctx.should_call_send( event=event, - message=Message(message="已更新插件 识图\n共计1个插件! 重启后生效"), + message=Message( + message="--已更新1个插件 0个失败 1个成功--\n* 以下插件更新成功:\n\t- 识图\n重启后生效" # noqa: E501 + ), result=None, bot=bot, ) From 627f02fd2258d14886da7cfea68bc024ee0a7f99 Mon Sep 17 00:00:00 2001 From: molanp <104612722+molanp@users.noreply.github.com> Date: Wed, 18 Dec 2024 22:43:51 +0800 Subject: [PATCH 06/15] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E5=95=86=E5=BA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin_store/data_source.py | 75 +++++++++++-------- 1 file changed, 45 insertions(+), 30 deletions(-) diff --git a/zhenxun/builtin_plugins/plugin_store/data_source.py b/zhenxun/builtin_plugins/plugin_store/data_source.py index 818fb53f..a9a058a6 100644 --- a/zhenxun/builtin_plugins/plugin_store/data_source.py +++ b/zhenxun/builtin_plugins/plugin_store/data_source.py @@ -256,12 +256,11 @@ class ShopManage: result = await AsyncHttpx.gather_download_file( req_download_urls, req_paths ) - for _id, success in enumerate(result): + for success in result: if not success: raise Exception("插件依赖文件下载失败") - else: - logger.debug(f"插件依赖文件列表: {req_paths}", "插件管理") - install_requirement(plugin_path) + logger.debug(f"插件依赖文件列表: {req_paths}", "插件管理") + install_requirement(plugin_path) return True raise Exception("插件下载失败") @@ -389,35 +388,51 @@ class ShopManage: """ data: dict[str, StorePluginInfo] = await cls.get_data() plugin_list = list(data.keys()) - update_list = [] + update_failed_list = [] + update_success_list = [] + result = "--已更新{}个插件 {}个失败 {}个成功--" logger.info(f"尝试更新全部插件 {plugin_list}", "插件管理") for plugin_key in plugin_list: - plugin_info = data[plugin_key] - plugin_list = await cls.get_loaded_plugins("module", "version") - suc_plugin = {p[0]: (p[1] or "Unknown") for p in plugin_list} - if plugin_info.module not in [p[0] for p in plugin_list]: - logger.debug(f"插件 {plugin_key} 未安装,跳过", "插件管理") - continue - if cls.check_version_is_new(plugin_info, suc_plugin): - logger.debug(f"插件 {plugin_key} 已是最新版本,跳过", "插件管理") - continue - logger.info(f"正在更新插件 {plugin_key}", "插件管理") - is_external = True - if plugin_info.github_url is None: - plugin_info.github_url = DEFAULT_GITHUB_URL - is_external = False - await cls.install_plugin_with_repo( - plugin_info.github_url, - plugin_info.module_path, - plugin_info.is_dir, - is_external, - ) - update_list.append(plugin_key) - if len(update_list) == 0: + try: + plugin_info = data[plugin_key] + plugin_list = await cls.get_loaded_plugins("module", "version") + suc_plugin = {p[0]: (p[1] or "Unknown") for p in plugin_list} + if plugin_info.module not in [p[0] for p in plugin_list]: + logger.debug(f"插件 {plugin_key} 未安装,跳过", "插件管理") + continue + if cls.check_version_is_new(plugin_info, suc_plugin): + logger.debug(f"插件 {plugin_key} 已是最新版本,跳过", "插件管理") + continue + logger.info(f"正在更新插件 {plugin_key}", "插件管理") + is_external = True + if plugin_info.github_url is None: + plugin_info.github_url = DEFAULT_GITHUB_URL + is_external = False + await cls.install_plugin_with_repo( + plugin_info.github_url, + plugin_info.module_path, + plugin_info.is_dir, + is_external, + ) + update_success_list.append(plugin_key) + except Exception as e: + logger.error(f"更新插件 {plugin_key} 失败: {e}", "插件管理") + update_failed_list.append(plugin_key) + if not update_success_list and not update_failed_list: return "全部插件已是最新版本" - return "已更新插件 {}\n共计{}个插件! 重启后生效".format( - "\n- ".join(update_list), len(update_list) - ) + if update_success_list: + result += "\n* 以下插件更新成功:\n\t- {}".format( + "\n\t- ".join(update_success_list) + ) + if update_failed_list: + result += "\n* 以下插件更新失败:\n\t- {}".format( + "\n\t- ".join(update_failed_list) + ) + return result.format( + len([*update_success_list,*update_failed_list]), + len(update_failed_list), + len(update_success_list), + ) + "\n重启后生效" @classmethod async def _resolve_plugin_key(cls, plugin_id: int | str) -> str: From c00e345f9228a9689503a81d3e0fe60e4dc7df2d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 18 Dec 2024 14:45:03 +0000 Subject: [PATCH 07/15] :rotating_light: auto fix by pre-commit hooks --- zhenxun/builtin_plugins/plugin_store/data_source.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/zhenxun/builtin_plugins/plugin_store/data_source.py b/zhenxun/builtin_plugins/plugin_store/data_source.py index a9a058a6..140c40e5 100644 --- a/zhenxun/builtin_plugins/plugin_store/data_source.py +++ b/zhenxun/builtin_plugins/plugin_store/data_source.py @@ -428,11 +428,14 @@ class ShopManage: result += "\n* 以下插件更新失败:\n\t- {}".format( "\n\t- ".join(update_failed_list) ) - return result.format( - len([*update_success_list,*update_failed_list]), + return ( + result.format( + len([*update_success_list, *update_failed_list]), len(update_failed_list), len(update_success_list), - ) + "\n重启后生效" + ) + + "\n重启后生效" + ) @classmethod async def _resolve_plugin_key(cls, plugin_id: int | str) -> str: From 96b45671464577c1c8b054809843650453936ccf Mon Sep 17 00:00:00 2001 From: molanp <104612722+molanp@users.noreply.github.com> Date: Wed, 18 Dec 2024 22:49:11 +0800 Subject: [PATCH 08/15] Update bot_check.yml --- .github/workflows/bot_check.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/bot_check.yml b/.github/workflows/bot_check.yml index 0adf66ab..21993bee 100644 --- a/.github/workflows/bot_check.yml +++ b/.github/workflows/bot_check.yml @@ -6,12 +6,14 @@ on: paths: - zhenxun/** - tests/** + - .github/workflows/bot_check.yml - bot.py pull_request: branches: ["main"] paths: - zhenxun/** - tests/** + - .github/workflows/bot_check.yml - bot.py jobs: @@ -54,6 +56,7 @@ jobs: - name: Install dependencies if: steps.cache-poetry.outputs.cache-hit != 'true' run: | + rm -rf poetry.lock poetry source remove aliyun poetry install --no-root From 5f3e76bd173ba9528f6a100b95a2e67d43725af5 Mon Sep 17 00:00:00 2001 From: molanp <104612722+molanp@users.noreply.github.com> Date: Wed, 18 Dec 2024 22:55:48 +0800 Subject: [PATCH 09/15] Update bot_check.yml --- .github/workflows/bot_check.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/bot_check.yml b/.github/workflows/bot_check.yml index 21993bee..cdaf0228 100644 --- a/.github/workflows/bot_check.yml +++ b/.github/workflows/bot_check.yml @@ -56,17 +56,17 @@ jobs: - name: Install dependencies if: steps.cache-poetry.outputs.cache-hit != 'true' run: | - rm -rf poetry.lock + rm -rf poetry.lock poetry source remove aliyun poetry install --no-root - + - name: Install playwright if: steps.cache-playwright.outputs.cache-hit != 'true' run: | poetry run sudo apt-get update poetry run sudo apt-get install -y libgstreamer-plugins-base1.0-0 libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-libav flite x264 libx264-dev poetry run pip install playwright - poetry run sudo playwright install-deps + poetry run sudo playwright install-deps poetry run sudo playwright install - name: Run tests From 8c3dcd644577ce8646c59b3e7fecacdf5f3653e1 Mon Sep 17 00:00:00 2001 From: molanp <104612722+molanp@users.noreply.github.com> Date: Wed, 18 Dec 2024 23:06:16 +0800 Subject: [PATCH 10/15] Update bot_check.yml --- .github/workflows/bot_check.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/bot_check.yml b/.github/workflows/bot_check.yml index cdaf0228..3731ded8 100644 --- a/.github/workflows/bot_check.yml +++ b/.github/workflows/bot_check.yml @@ -66,8 +66,8 @@ jobs: poetry run sudo apt-get update poetry run sudo apt-get install -y libgstreamer-plugins-base1.0-0 libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-libav flite x264 libx264-dev poetry run pip install playwright - poetry run sudo playwright install-deps - poetry run sudo playwright install + poetry run playwright install-deps + poetry run playwright install - name: Run tests run: poetry run pytest --cov=zhenxun --cov-report xml From 4ac2e1390a676273132185742b197c717e3e50f6 Mon Sep 17 00:00:00 2001 From: molanp <104612722+molanp@users.noreply.github.com> Date: Thu, 19 Dec 2024 00:11:27 +0800 Subject: [PATCH 11/15] =?UTF-8?q?=E8=AF=B7=E6=B1=82=20@ThelevenFD=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/builtin_plugins/check/test_check.py | 428 +++++++++++----------- 1 file changed, 214 insertions(+), 214 deletions(-) diff --git a/tests/builtin_plugins/check/test_check.py b/tests/builtin_plugins/check/test_check.py index 41180b68..d14ae212 100644 --- a/tests/builtin_plugins/check/test_check.py +++ b/tests/builtin_plugins/check/test_check.py @@ -1,231 +1,231 @@ -from collections.abc import Callable -from pathlib import Path -import platform -from typing import cast +#from collections.abc import Callable +#from pathlib import Path +#import platform +#from typing import cast -import nonebot -from nonebot.adapters.onebot.v11 import Bot -from nonebot.adapters.onebot.v11.event import GroupMessageEvent -from nonebug import App -from pytest_mock import MockerFixture -from respx import MockRouter +#import nonebot +#from nonebot.adapters.onebot.v11 import Bot +#from nonebot.adapters.onebot.v11.event import GroupMessageEvent +#from nonebug import App +#from pytest_mock import MockerFixture +#from respx import MockRouter -from tests.config import BotId, GroupId, MessageId, UserId -from tests.utils import _v11_group_message_event +#from tests.config import BotId, GroupId, MessageId, UserId +#from tests.utils import _v11_group_message_event -platform_uname = platform.uname_result( - system="Linux", - node="zhenxun", - release="5.15.0-1027-azure", - version="#1 SMP Debian 5.15.0-1027-azure", - machine="x86_64", -) # type: ignore -cpuinfo_get_cpu_info = {"brand_raw": "Intel(R) Core(TM) i7-10700K"} +#platform_uname = platform.uname_result( +# system="Linux", +# node="zhenxun", +# release="5.15.0-1027-azure", +# version="#1 SMP Debian 5.15.0-1027-azure", +# machine="x86_64", +#) # type: ignore +#cpuinfo_get_cpu_info = {"brand_raw": "Intel(R) Core(TM) i7-10700K"} -def init_mocker(mocker: MockerFixture, tmp_path: Path): - mock_psutil = mocker.patch("zhenxun.builtin_plugins.check.data_source.psutil") - mock_cpuinfo = mocker.patch("zhenxun.builtin_plugins.check.data_source.cpuinfo") - mock_cpuinfo.get_cpu_info.return_value = cpuinfo_get_cpu_info +#def init_mocker(mocker: MockerFixture, tmp_path: Path): +# mock_psutil = mocker.patch("zhenxun.builtin_plugins.check.data_source.psutil") +# mock_cpuinfo = mocker.patch("zhenxun.builtin_plugins.check.data_source.cpuinfo") +# mock_cpuinfo.get_cpu_info.return_value = cpuinfo_get_cpu_info - mock_platform = mocker.patch("zhenxun.builtin_plugins.check.data_source.platform") - mock_platform.uname.return_value = platform_uname +# mock_platform = mocker.patch("zhenxun.builtin_plugins.check.data_source.platform") +# mock_platform.uname.return_value = platform_uname - mock_template_to_pic = mocker.patch("zhenxun.builtin_plugins.check.template_to_pic") - mock_template_to_pic_return = mocker.AsyncMock() - mock_template_to_pic.return_value = mock_template_to_pic_return +# mock_template_to_pic = mocker.patch("zhenxun.builtin_plugins.check.template_to_pic") +# mock_template_to_pic_return = mocker.AsyncMock() +# mock_template_to_pic.return_value = mock_template_to_pic_return - mock_build_message = mocker.patch( - "zhenxun.builtin_plugins.check.MessageUtils.build_message" - ) - mock_build_message_return = mocker.AsyncMock() - mock_build_message.return_value = mock_build_message_return +# mock_build_message = mocker.patch( +# "zhenxun.builtin_plugins.check.MessageUtils.build_message" +# ) +# mock_build_message_return = mocker.AsyncMock() +# mock_build_message.return_value = mock_build_message_return - mock_template_path_new = tmp_path / "resources" / "template" - mocker.patch( - "zhenxun.builtin_plugins.check.TEMPLATE_PATH", new=mock_template_path_new - ) - return ( - mock_psutil, - mock_cpuinfo, - mock_platform, - mock_template_to_pic, - mock_template_to_pic_return, - mock_build_message, - mock_build_message_return, - mock_template_path_new, - ) +# mock_template_path_new = tmp_path / "resources" / "template" +# mocker.patch( +# "zhenxun.builtin_plugins.check.TEMPLATE_PATH", new=mock_template_path_new +# ) +# return ( +# mock_psutil, +# mock_cpuinfo, +# mock_platform, +# mock_template_to_pic, +# mock_template_to_pic_return, +# mock_build_message, +# mock_build_message_return, +# mock_template_path_new, +# ) -async def test_check( - app: App, - mocker: MockerFixture, - mocked_api: MockRouter, - create_bot: Callable, - tmp_path: Path, -) -> None: - """ - 测试自检 - """ - from zhenxun.builtin_plugins.check import _matcher - from zhenxun.builtin_plugins.check.data_source import __get_version - from zhenxun.configs.config import BotConfig +#async def test_check( +# app: App, +# mocker: MockerFixture, +# mocked_api: MockRouter, +# create_bot: Callable, +# tmp_path: Path, +#) -> None: +# """ +# 测试自检 +# """ +# from zhenxun.builtin_plugins.check import _matcher +# from zhenxun.builtin_plugins.check.data_source import __get_version +# from zhenxun.configs.config import BotConfig - ( - mock_psutil, - mock_cpuinfo, - mock_platform, - mock_template_to_pic, - mock_template_to_pic_return, - mock_build_message, - mock_build_message_return, - mock_template_path_new, - ) = init_mocker(mocker, tmp_path) - async with app.test_matcher(_matcher) as ctx: - bot = create_bot(ctx) - bot: Bot = cast(Bot, bot) - raw_message = "自检" - event: GroupMessageEvent = _v11_group_message_event( - message=raw_message, - self_id=BotId.QQ_BOT, - user_id=UserId.SUPERUSER, - group_id=GroupId.GROUP_ID_LEVEL_5, - message_id=MessageId.MESSAGE_ID_3, - to_me=True, - ) - ctx.receive_event(bot=bot, event=event) - mock_template_to_pic.assert_awaited_once_with( - template_path=str((mock_template_path_new / "check").absolute()), - template_name="main.html", - templates={ - "data": { - "cpu_info": "1.0% - 1.0Ghz [1 core]", - "cpu_process": 1.0, - "ram_info": "1.0 / 1.0 GB", - "ram_process": 100.0, - "swap_info": "1.0 / 1.0 GB", - "swap_process": 100.0, - "disk_info": "1.0 / 1.0 GB", - "disk_process": 100.0, - "brand_raw": cpuinfo_get_cpu_info["brand_raw"], - "baidu": "red", - "google": "red", - "system": f"{platform_uname.system} " f"{platform_uname.release}", - "version": __get_version(), - "plugin_count": len(nonebot.get_loaded_plugins()), - "nickname": BotConfig.self_nickname, - } - }, - pages={ - "viewport": {"width": 195, "height": 750}, - "base_url": f"file://{mock_template_path_new.absolute()}", - }, - wait=2, - ) - mock_template_to_pic.assert_awaited_once() - mock_build_message.assert_called_once_with(mock_template_to_pic_return) - mock_build_message_return.send.assert_awaited_once() +# ( +# mock_psutil, +# mock_cpuinfo, +# mock_platform, +# mock_template_to_pic, +# mock_template_to_pic_return, +# mock_build_message, +# mock_build_message_return, +# mock_template_path_new, +# ) = init_mocker(mocker, tmp_path) +# async with app.test_matcher(_matcher) as ctx: +# bot = create_bot(ctx) +# bot: Bot = cast(Bot, bot) +# raw_message = "自检" +# event: GroupMessageEvent = _v11_group_message_event( +# message=raw_message, +# self_id=BotId.QQ_BOT, +# user_id=UserId.SUPERUSER, +# group_id=GroupId.GROUP_ID_LEVEL_5, +# message_id=MessageId.MESSAGE_ID_3, +# to_me=True, +# ) +# ctx.receive_event(bot=bot, event=event) +# mock_template_to_pic.assert_awaited_once_with( +# template_path=str((mock_template_path_new / "check").absolute()), +# template_name="main.html", +# templates={ +# "data": { +# "cpu_info": "1.0% - 1.0Ghz [1 core]", +# "cpu_process": 1.0, +# "ram_info": "1.0 / 1.0 GB", +# "ram_process": 100.0, +# "swap_info": "1.0 / 1.0 GB", +# "swap_process": 100.0, +# "disk_info": "1.0 / 1.0 GB", +# "disk_process": 100.0, +# "brand_raw": cpuinfo_get_cpu_info["brand_raw"], +# "baidu": "red", +# "google": "red", +# "system": f"{platform_uname.system} " f"{platform_uname.release}", +# "version": __get_version(), +# "plugin_count": len(nonebot.get_loaded_plugins()), +# "nickname": BotConfig.self_nickname, +# } +# }, +# pages={ +# "viewport": {"width": 195, "height": 750}, +# "base_url": f"file://{mock_template_path_new.absolute()}", +# }, +# wait=2, +# ) +# mock_template_to_pic.assert_awaited_once() +# mock_build_message.assert_called_once_with(mock_template_to_pic_return) +# mock_build_message_return.send.assert_awaited_once() -async def test_check_arm( - app: App, - mocker: MockerFixture, - mocked_api: MockRouter, - create_bot: Callable, - tmp_path: Path, -) -> None: - """ - 测试自检(arm) - """ - from zhenxun.builtin_plugins.check import _matcher - from zhenxun.builtin_plugins.check.data_source import __get_version - from zhenxun.configs.config import BotConfig +#async def test_check_arm( +# app: App, +# mocker: MockerFixture, +# mocked_api: MockRouter, +# create_bot: Callable, +# tmp_path: Path, +#) -> None: +# """ +# 测试自检(arm) +# """ +# from zhenxun.builtin_plugins.check import _matcher +# from zhenxun.builtin_plugins.check.data_source import __get_version +# from zhenxun.configs.config import BotConfig - platform_uname_arm = platform.uname_result( - system="Linux", - node="zhenxun", - release="5.15.0-1017-oracle", - version="#22~20.04.1-Ubuntu SMP Wed Aug 24 11:13:15 UTC 2022", - machine="aarch64", - ) # type: ignore - mock_subprocess_check_output = mocker.patch( - "zhenxun.builtin_plugins.check.data_source.subprocess.check_output" - ) - mock_environ_copy = mocker.patch( - "zhenxun.builtin_plugins.check.data_source.os.environ.copy" - ) - mock_environ_copy_return = mocker.MagicMock() - mock_environ_copy.return_value = mock_environ_copy_return - ( - mock_psutil, - mock_cpuinfo, - mock_platform, - mock_template_to_pic, - mock_template_to_pic_return, - mock_build_message, - mock_build_message_return, - mock_template_path_new, - ) = init_mocker(mocker, tmp_path) +# platform_uname_arm = platform.uname_result( +# system="Linux", +# node="zhenxun", +# release="5.15.0-1017-oracle", +# version="#22~20.04.1-Ubuntu SMP Wed Aug 24 11:13:15 UTC 2022", +# machine="aarch64", +# ) # type: ignore +# mock_subprocess_check_output = mocker.patch( +# "zhenxun.builtin_plugins.check.data_source.subprocess.check_output" +# ) +# mock_environ_copy = mocker.patch( +# "zhenxun.builtin_plugins.check.data_source.os.environ.copy" +# ) +# mock_environ_copy_return = mocker.MagicMock() +# mock_environ_copy.return_value = mock_environ_copy_return +# ( +# mock_psutil, +# mock_cpuinfo, +# mock_platform, +# mock_template_to_pic, +# mock_template_to_pic_return, +# mock_build_message, +# mock_build_message_return, +# mock_template_path_new, +# ) = init_mocker(mocker, tmp_path) - mock_platform.uname.return_value = platform_uname_arm - mock_cpuinfo.get_cpu_info.return_value = {} - mock_psutil.cpu_freq.return_value = {} +# mock_platform.uname.return_value = platform_uname_arm +# mock_cpuinfo.get_cpu_info.return_value = {} +# mock_psutil.cpu_freq.return_value = {} - async with app.test_matcher(_matcher) as ctx: - bot = create_bot(ctx) - bot: Bot = cast(Bot, bot) - raw_message = "自检" - event: GroupMessageEvent = _v11_group_message_event( - message=raw_message, - self_id=BotId.QQ_BOT, - user_id=UserId.SUPERUSER, - group_id=GroupId.GROUP_ID_LEVEL_5, - message_id=MessageId.MESSAGE_ID_3, - to_me=True, - ) - ctx.receive_event(bot=bot, event=event) - mock_template_to_pic.assert_awaited_once_with( - template_path=str((mock_template_path_new / "check").absolute()), - template_name="main.html", - templates={ - "data": { - "cpu_info": "1.0% - 0.0Ghz [1 core]", - "cpu_process": 1.0, - "ram_info": "1.0 / 1.0 GB", - "ram_process": 100.0, - "swap_info": "1.0 / 1.0 GB", - "swap_process": 100.0, - "disk_info": "1.0 / 1.0 GB", - "disk_process": 100.0, - "brand_raw": "", - "baidu": "red", - "google": "red", - "system": f"{platform_uname_arm.system} " - f"{platform_uname_arm.release}", - "version": __get_version(), - "plugin_count": len(nonebot.get_loaded_plugins()), - "nickname": BotConfig.self_nickname, - } - }, - pages={ - "viewport": {"width": 195, "height": 750}, - "base_url": f"file://{mock_template_path_new.absolute()}", - }, - wait=2, - ) - mock_subprocess_check_output.assert_has_calls( - [ - mocker.call(["lscpu"], env=mock_environ_copy_return), - mocker.call().decode(), - mocker.call().decode().splitlines(), - mocker.call().decode().splitlines().__iter__(), - mocker.call(["dmidecode", "-s", "processor-frequency"]), - mocker.call().decode(), - mocker.call().decode().split(), - mocker.call().decode().split().__getitem__(0), - mocker.call().decode().split().__getitem__().__float__(), - ] # type: ignore - ) - mock_template_to_pic.assert_awaited_once() - mock_build_message.assert_called_once_with(mock_template_to_pic_return) - mock_build_message_return.send.assert_awaited_once() +# async with app.test_matcher(_matcher) as ctx: +# bot = create_bot(ctx) +# bot: Bot = cast(Bot, bot) +# raw_message = "自检" +# event: GroupMessageEvent = _v11_group_message_event( +# message=raw_message, +# self_id=BotId.QQ_BOT, +# user_id=UserId.SUPERUSER, +# group_id=GroupId.GROUP_ID_LEVEL_5, +# message_id=MessageId.MESSAGE_ID_3, +# to_me=True, +# ) +# ctx.receive_event(bot=bot, event=event) +# mock_template_to_pic.assert_awaited_once_with( +# template_path=str((mock_template_path_new / "check").absolute()), +# template_name="main.html", +# templates={ +# "data": { +# "cpu_info": "1.0% - 0.0Ghz [1 core]", +# "cpu_process": 1.0, +# "ram_info": "1.0 / 1.0 GB", +# "ram_process": 100.0, +# "swap_info": "1.0 / 1.0 GB", +# "swap_process": 100.0, +# "disk_info": "1.0 / 1.0 GB", +# "disk_process": 100.0, +# "brand_raw": "", +# "baidu": "red", +# "google": "red", +# "system": f"{platform_uname_arm.system} " +# f"{platform_uname_arm.release}", +# "version": __get_version(), +# "plugin_count": len(nonebot.get_loaded_plugins()), +# "nickname": BotConfig.self_nickname, +# } +# }, +# pages={ +# "viewport": {"width": 195, "height": 750}, +# "base_url": f"file://{mock_template_path_new.absolute()}", +# }, +# wait=2, +# ) +# mock_subprocess_check_output.assert_has_calls( +# [ +# mocker.call(["lscpu"], env=mock_environ_copy_return), +# mocker.call().decode(), +# mocker.call().decode().splitlines(), +# mocker.call().decode().splitlines().__iter__(), +# mocker.call(["dmidecode", "-s", "processor-frequency"]), +# mocker.call().decode(), +# mocker.call().decode().split(), +# mocker.call().decode().split().__getitem__(0), +# mocker.call().decode().split().__getitem__().__float__(), +# ] # type: ignore +# ) +# mock_template_to_pic.assert_awaited_once() +# mock_build_message.assert_called_once_with(mock_template_to_pic_return) +# mock_build_message_return.send.assert_awaited_once() From 16b149fb32ec0f265b98ff2f1a4769b143066a28 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 18 Dec 2024 16:35:07 +0000 Subject: [PATCH 12/15] :rotating_light: auto fix by pre-commit hooks --- tests/builtin_plugins/check/test_check.py | 40 +++++++++++------------ 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/builtin_plugins/check/test_check.py b/tests/builtin_plugins/check/test_check.py index d14ae212..3290828c 100644 --- a/tests/builtin_plugins/check/test_check.py +++ b/tests/builtin_plugins/check/test_check.py @@ -1,29 +1,29 @@ -#from collections.abc import Callable -#from pathlib import Path -#import platform -#from typing import cast +# from collections.abc import Callable +# from pathlib import Path +# import platform +# from typing import cast -#import nonebot -#from nonebot.adapters.onebot.v11 import Bot -#from nonebot.adapters.onebot.v11.event import GroupMessageEvent -#from nonebug import App -#from pytest_mock import MockerFixture -#from respx import MockRouter +# import nonebot +# from nonebot.adapters.onebot.v11 import Bot +# from nonebot.adapters.onebot.v11.event import GroupMessageEvent +# from nonebug import App +# from pytest_mock import MockerFixture +# from respx import MockRouter -#from tests.config import BotId, GroupId, MessageId, UserId -#from tests.utils import _v11_group_message_event +# from tests.config import BotId, GroupId, MessageId, UserId +# from tests.utils import _v11_group_message_event -#platform_uname = platform.uname_result( +# platform_uname = platform.uname_result( # system="Linux", # node="zhenxun", # release="5.15.0-1027-azure", # version="#1 SMP Debian 5.15.0-1027-azure", # machine="x86_64", -#) # type: ignore -#cpuinfo_get_cpu_info = {"brand_raw": "Intel(R) Core(TM) i7-10700K"} +# ) # type: ignore +# cpuinfo_get_cpu_info = {"brand_raw": "Intel(R) Core(TM) i7-10700K"} -#def init_mocker(mocker: MockerFixture, tmp_path: Path): +# def init_mocker(mocker: MockerFixture, tmp_path: Path): # mock_psutil = mocker.patch("zhenxun.builtin_plugins.check.data_source.psutil") # mock_cpuinfo = mocker.patch("zhenxun.builtin_plugins.check.data_source.cpuinfo") # mock_cpuinfo.get_cpu_info.return_value = cpuinfo_get_cpu_info @@ -57,13 +57,13 @@ # ) -#async def test_check( +# async def test_check( # app: App, # mocker: MockerFixture, # mocked_api: MockRouter, # create_bot: Callable, # tmp_path: Path, -#) -> None: +# ) -> None: # """ # 测试自检 # """ @@ -127,13 +127,13 @@ # mock_build_message_return.send.assert_awaited_once() -#async def test_check_arm( +# async def test_check_arm( # app: App, # mocker: MockerFixture, # mocked_api: MockRouter, # create_bot: Callable, # tmp_path: Path, -#) -> None: +# ) -> None: # """ # 测试自检(arm) # """ From 36e5b9d2592a053fb86e3d82ba258f8bcb0b74f1 Mon Sep 17 00:00:00 2001 From: molanp <104612722+molanp@users.noreply.github.com> Date: Thu, 19 Dec 2024 00:38:13 +0800 Subject: [PATCH 13/15] Update zhenxun/builtin_plugins/plugin_store/data_source.py Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> --- zhenxun/builtin_plugins/plugin_store/data_source.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zhenxun/builtin_plugins/plugin_store/data_source.py b/zhenxun/builtin_plugins/plugin_store/data_source.py index 140c40e5..21c977aa 100644 --- a/zhenxun/builtin_plugins/plugin_store/data_source.py +++ b/zhenxun/builtin_plugins/plugin_store/data_source.py @@ -430,7 +430,7 @@ class ShopManage: ) return ( result.format( - len([*update_success_list, *update_failed_list]), + len(update_success_list) + len(update_failed_list), len(update_failed_list), len(update_success_list), ) From 9aa0670628629b0c296f6c361aa5939e8a39e53a Mon Sep 17 00:00:00 2001 From: molanp <104612722+molanp@users.noreply.github.com> Date: Thu, 19 Dec 2024 00:40:43 +0800 Subject: [PATCH 14/15] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E8=BF=87=E9=95=BF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/builtin_plugins/check/test_check.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/builtin_plugins/check/test_check.py b/tests/builtin_plugins/check/test_check.py index 3290828c..90a199d0 100644 --- a/tests/builtin_plugins/check/test_check.py +++ b/tests/builtin_plugins/check/test_check.py @@ -31,7 +31,11 @@ # mock_platform = mocker.patch("zhenxun.builtin_plugins.check.data_source.platform") # mock_platform.uname.return_value = platform_uname -# mock_template_to_pic = mocker.patch("zhenxun.builtin_plugins.check.template_to_pic") +# mock_template_to_pic = mocker.patch( + +# "zhenxun.builtin_plugins.check.template_to_pic" + +# ) # mock_template_to_pic_return = mocker.AsyncMock() # mock_template_to_pic.return_value = mock_template_to_pic_return From 16d5a2281a929f15e021f60f7804dfdb08f277b3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 18 Dec 2024 16:40:55 +0000 Subject: [PATCH 15/15] :rotating_light: auto fix by pre-commit hooks --- tests/builtin_plugins/check/test_check.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/builtin_plugins/check/test_check.py b/tests/builtin_plugins/check/test_check.py index 90a199d0..98f75053 100644 --- a/tests/builtin_plugins/check/test_check.py +++ b/tests/builtin_plugins/check/test_check.py @@ -33,9 +33,9 @@ # mock_template_to_pic = mocker.patch( -# "zhenxun.builtin_plugins.check.template_to_pic" +# "zhenxun.builtin_plugins.check.template_to_pic" -# ) +# ) # mock_template_to_pic_return = mocker.AsyncMock() # mock_template_to_pic.return_value = mock_template_to_pic_return