Skip to content

Commit

Permalink
fix(store_test): 修复指定 key 时无法正确读取配置的问题 (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
he0119 authored Feb 17, 2024
1 parent 99324d3 commit e4eeb37
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions src/utils/store_test/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = {}

Expand Down
2 changes: 1 addition & 1 deletion tests/utils/store_test/store/registry_results.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"metadata": true
},
"inputs": {
"config": ""
"config": "TEST_CONFIG=true"
},
"outputs": {
"validation": "通过",
Expand Down
10 changes: 5 additions & 5 deletions tests/utils/store_test/test_store_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={
Expand Down Expand Up @@ -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={
Expand Down Expand Up @@ -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={
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit e4eeb37

Please sign in to comment.