From e4eeb37ea0743607cea796cbe234c1ae16ad7326 Mon Sep 17 00:00:00 2001 From: uy/sun Date: Sat, 17 Feb 2024 22:36:25 +0800 Subject: [PATCH] =?UTF-8?q?fix(store=5Ftest):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=20key=20=E6=97=B6=E6=97=A0=E6=B3=95=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E8=AF=BB=E5=8F=96=E9=85=8D=E7=BD=AE=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20(#204)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 4 ++++ src/utils/store_test/store.py | 12 +++++++----- tests/utils/store_test/store/registry_results.json | 2 +- tests/utils/store_test/test_store_test.py | 10 +++++----- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9759e01..6a43ebac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/lang/zh-CN/ - 使用 Pydantic 2.0 +### Fixed + +- 修复指定 key 时无法正确读取配置的问题 + ## [3.2.4] - 2024-02-04 ### Fixed diff --git a/src/utils/store_test/store.py b/src/utils/store_test/store.py index 27f2dda0..8e2c7c8b 100644 --- a/src/utils/store_test/store.py +++ b/src/utils/store_test/store.py @@ -85,6 +85,10 @@ def skip_plugin_test(self, key: str) -> bool: return self._previous_plugins[key].get("skip_test", False) return False + def read_plugin_config(self, key: str) -> str: + """读取插件配置""" + return self._previous_results.get(key, {}).get("inputs", {}).get("config", "") + async def test_plugins( self, key: str | None = None, @@ -97,15 +101,13 @@ async def test_plugins( if key: test_plugins = [(key, self._store_plugins[key])] - plugin_configs = {key: config or ""} + # 优先使用传入的配置 + plugin_configs = {key: config if config else self.read_plugin_config(key)} plugin_datas = {key: data} else: test_plugins = list(self._store_plugins.items())[self._offset :] plugin_configs = { - key: self._previous_results.get(key, {}) - .get("inputs", {}) - .get("config", "") - for key, _ in test_plugins + key: self.read_plugin_config(key) for key, _ in test_plugins } plugin_datas = {} diff --git a/tests/utils/store_test/store/registry_results.json b/tests/utils/store_test/store/registry_results.json index 282d1fb2..e5d5210c 100644 --- a/tests/utils/store_test/store/registry_results.json +++ b/tests/utils/store_test/store/registry_results.json @@ -32,7 +32,7 @@ "metadata": true }, "inputs": { - "config": "" + "config": "TEST_CONFIG=true" }, "outputs": { "validation": "通过", diff --git a/tests/utils/store_test/test_store_test.py b/tests/utils/store_test/test_store_test.py index 005d8171..566028a3 100644 --- a/tests/utils/store_test/test_store_test.py +++ b/tests/utils/store_test/test_store_test.py @@ -130,7 +130,7 @@ async def test_store_test( "tags": [], "is_official": False, }, - config="", + config="TEST_CONFIG=true", skip_test=False, data=None, previous_plugin={ @@ -193,7 +193,7 @@ async def test_store_test_with_key( "tags": [], "is_official": False, }, - config="", + config="TEST_CONFIG=true", skip_test=False, data=None, previous_plugin={ @@ -292,7 +292,7 @@ async def test_store_test_raise( "tags": [], "is_official": False, }, - config="", + config="TEST_CONFIG=true", skip_test=False, data=None, previous_plugin={ @@ -329,7 +329,7 @@ async def test_store_test_raise( # 数据没有更新,只是被压缩 assert ( mocked_store_data["results"].read_text(encoding="utf8") - == '{"nonebot-plugin-datastore:nonebot_plugin_datastore":{"time":"2023-06-26T22:08:18.945584+08:00","version":"1.0.0","results":{"validation":true,"load":true,"metadata":true},"inputs":{"config":""},"outputs":{"validation":"通过","load":"datastore","metadata":{"name":"数据存储","description":"NoneBot 数据存储插件","usage":"请参考文档","type":"library","homepage":"https://github.com/he0119/nonebot-plugin-datastore","supported_adapters":null}}},"nonebot-plugin-treehelp:nonebot_plugin_treehelp":{"time":"2023-06-26T22:20:41.833311+08:00","version":"0.3.0","results":{"validation":true,"load":true,"metadata":true},"inputs":{"config":""},"outputs":{"validation":"通过","load":"treehelp","metadata":{"name":"帮助","description":"获取插件帮助信息","usage":"获取插件列表\\n/help\\n获取插件树\\n/help -t\\n/help --tree\\n获取某个插件的帮助\\n/help 插件名\\n获取某个插件的树\\n/help --tree 插件名\\n","type":"application","homepage":"https://github.com/he0119/nonebot-plugin-treehelp","supported_adapters":null}}}}' + == '{"nonebot-plugin-datastore:nonebot_plugin_datastore":{"time":"2023-06-26T22:08:18.945584+08:00","version":"1.0.0","results":{"validation":true,"load":true,"metadata":true},"inputs":{"config":""},"outputs":{"validation":"通过","load":"datastore","metadata":{"name":"数据存储","description":"NoneBot 数据存储插件","usage":"请参考文档","type":"library","homepage":"https://github.com/he0119/nonebot-plugin-datastore","supported_adapters":null}}},"nonebot-plugin-treehelp:nonebot_plugin_treehelp":{"time":"2023-06-26T22:20:41.833311+08:00","version":"0.3.0","results":{"validation":true,"load":true,"metadata":true},"inputs":{"config":"TEST_CONFIG=true"},"outputs":{"validation":"通过","load":"treehelp","metadata":{"name":"帮助","description":"获取插件帮助信息","usage":"获取插件列表\\n/help\\n获取插件树\\n/help -t\\n/help --tree\\n获取某个插件的帮助\\n/help 插件名\\n获取某个插件的树\\n/help --tree 插件名\\n","type":"application","homepage":"https://github.com/he0119/nonebot-plugin-treehelp","supported_adapters":null}}}}' ) assert ( mocked_store_data["adapters"].read_text(encoding="utf8") @@ -378,7 +378,7 @@ async def test_store_test_with_key_raise( # 数据没有更新,只是被压缩 assert ( mocked_store_data["results"].read_text(encoding="utf8") - == '{"nonebot-plugin-datastore:nonebot_plugin_datastore":{"time":"2023-06-26T22:08:18.945584+08:00","version":"1.0.0","results":{"validation":true,"load":true,"metadata":true},"inputs":{"config":""},"outputs":{"validation":"通过","load":"datastore","metadata":{"name":"数据存储","description":"NoneBot 数据存储插件","usage":"请参考文档","type":"library","homepage":"https://github.com/he0119/nonebot-plugin-datastore","supported_adapters":null}}},"nonebot-plugin-treehelp:nonebot_plugin_treehelp":{"time":"2023-06-26T22:20:41.833311+08:00","version":"0.3.0","results":{"validation":true,"load":true,"metadata":true},"inputs":{"config":""},"outputs":{"validation":"通过","load":"treehelp","metadata":{"name":"帮助","description":"获取插件帮助信息","usage":"获取插件列表\\n/help\\n获取插件树\\n/help -t\\n/help --tree\\n获取某个插件的帮助\\n/help 插件名\\n获取某个插件的树\\n/help --tree 插件名\\n","type":"application","homepage":"https://github.com/he0119/nonebot-plugin-treehelp","supported_adapters":null}}}}' + == '{"nonebot-plugin-datastore:nonebot_plugin_datastore":{"time":"2023-06-26T22:08:18.945584+08:00","version":"1.0.0","results":{"validation":true,"load":true,"metadata":true},"inputs":{"config":""},"outputs":{"validation":"通过","load":"datastore","metadata":{"name":"数据存储","description":"NoneBot 数据存储插件","usage":"请参考文档","type":"library","homepage":"https://github.com/he0119/nonebot-plugin-datastore","supported_adapters":null}}},"nonebot-plugin-treehelp:nonebot_plugin_treehelp":{"time":"2023-06-26T22:20:41.833311+08:00","version":"0.3.0","results":{"validation":true,"load":true,"metadata":true},"inputs":{"config":"TEST_CONFIG=true"},"outputs":{"validation":"通过","load":"treehelp","metadata":{"name":"帮助","description":"获取插件帮助信息","usage":"获取插件列表\\n/help\\n获取插件树\\n/help -t\\n/help --tree\\n获取某个插件的帮助\\n/help 插件名\\n获取某个插件的树\\n/help --tree 插件名\\n","type":"application","homepage":"https://github.com/he0119/nonebot-plugin-treehelp","supported_adapters":null}}}}' ) assert ( mocked_store_data["adapters"].read_text(encoding="utf8")