Skip to content

Commit

Permalink
fix(store_test): 跳过测试的插件需要从之前的数据中提取验证所需数据 (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
he0119 authored Aug 28, 2023
1 parent ec11579 commit 6d0fde0
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/lang/zh-CN/
### Fixed

- 修正字段名称为 skip_test
- 跳过测试的插件需要从之前的数据中提取验证所需数据

## [3.0.1] - 2023-08-28

Expand Down
2 changes: 1 addition & 1 deletion src/utils/store_test/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Plugin(TypedDict):
valid: bool
time: str
version: str | None
skip_plugin_test: bool
skip_test: bool


class Metadata(TypedDict):
Expand Down
16 changes: 9 additions & 7 deletions src/utils/store_test/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ async def run(

print(f"正在测试插件 {key} ...")
new_results[key], new_plugin = await validate_plugin(
self._store_plugins[key],
config or "",
self.skip_plugin_test(key),
data,
plugin=self._store_plugins[key],
config=config or "",
skip_test=self.skip_plugin_test(key),
data=data,
previous_plugin=self._previous_plugins.get(key),
)
if new_plugin:
new_plugins[key] = new_plugin
Expand All @@ -133,9 +134,10 @@ async def run(
print(f"{i}/{self._limit} 正在测试插件 {key} ...")

new_results[key], new_plugin = await validate_plugin(
plugin,
plugin_configs.get(key, ""),
self.skip_plugin_test(key),
plugin=plugin,
config=plugin_configs.get(key, ""),
skip_test=self.skip_plugin_test(key),
previous_plugin=self._previous_plugins.get(key),
)
if new_plugin:
new_plugins[key] = new_plugin
Expand Down
12 changes: 11 additions & 1 deletion src/utils/store_test/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ def extract_version(path: Path) -> str | None:


async def validate_plugin(
plugin: StorePlugin, config: str, skip_test: bool, data: str | None = None
plugin: StorePlugin,
config: str,
skip_test: bool,
data: str | None = None,
previous_plugin: Plugin | None = None,
) -> tuple[TestResult, Plugin | None]:
"""验证插件
Expand Down Expand Up @@ -115,6 +119,12 @@ async def validate_plugin(
raw_data["homepage"] = metadata.get("homepage")
raw_data["type"] = metadata.get("type")
raw_data["supported_adapters"] = metadata.get("supported_adapters")
elif skip_test and previous_plugin:
raw_data["name"] = previous_plugin.get("name")
raw_data["desc"] = previous_plugin.get("desc")
raw_data["homepage"] = previous_plugin.get("homepage")
raw_data["type"] = previous_plugin.get("type")
raw_data["supported_adapters"] = previous_plugin.get("supported_adapters")

validation_info_result = validate_info(PublishType.PLUGIN, raw_data)

Expand Down
16 changes: 16 additions & 0 deletions tests/utils/store_test/output_failed.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
RESULT=False
OUTPUT<<EOF
插件 nonebot-plugin-treehelp 的信息如下:
name : nonebot-plugin-treehelp
version : 0.3.0
description : 适用于 Nonebot2 的树形帮助插件

dependencies
- nonebot2 >=2.0.0,<3.0.0
插件 nonebot-plugin-treehelp 依赖的插件如下:

插件 nonebot_plugin_treehelp 加载正常:
08-23 09:00:03 [SUCCESS] nonebot | NoneBot is initializing...
08-23 09:00:03 [INFO] nonebot | Current Env: prod
08-23 09:00:03 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_treehelp"
EOF
55 changes: 42 additions & 13 deletions tests/utils/store_test/test_store_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,37 @@ async def test_store_test(
time="2023-08-28T00:00:00.000000+08:00",
is_official=True,
valid=True,
skip_plugin_test=False,
skip_test=False,
),
)

test = StoreTest(0, 1, False)
await test.run()

mocked_validate_plugin.assert_called_once_with(
{
plugin={
"module_name": "nonebot_plugin_treehelp",
"project_link": "nonebot-plugin-treehelp",
"author": "he0119",
"tags": [],
"is_official": False,
},
"",
False,
config="",
skip_test=False,
previous_plugin={
"module_name": "nonebot_plugin_treehelp",
"project_link": "nonebot-plugin-treehelp",
"name": "帮助",
"desc": "获取插件帮助信息",
"author": "he0119",
"homepage": "https://github.com/he0119/nonebot-plugin-treehelp",
"tags": [],
"is_official": False,
"type": "application",
"supported_adapters": None,
"valid": True,
"time": "2023-06-22 12:10:18",
},
)
assert mocked_api["project_link_treehelp"].called
assert mocked_api["project_link_datastore"].called
Expand All @@ -157,7 +171,7 @@ async def test_store_test(
)
assert (
mocked_store_data["plugins"].read_text(encoding="utf8")
== '[{"module_name":"nonebot_plugin_datastore","project_link":"nonebot-plugin-datastore","name":"数据存储","desc":"NoneBot 数据存储插件","author":"he0119","homepage":"https://github.com/he0119/nonebot-plugin-datastore","tags":[],"is_official":false,"type":"library","supported_adapters":null,"valid":true,"time":"2023-06-22 11:58:18"},{"name":"帮助","module_name":"module_name","author":"author","version":"0.3.0","desc":"获取插件帮助信息","homepage":"https://nonebot.dev/","project_link":"project_link","tags":[],"supported_adapters":null,"type":"application","time":"2023-08-28T00:00:00.000000+08:00","is_official":true,"valid":true,"skip_plugin_test":false}]'
== '[{"module_name":"nonebot_plugin_datastore","project_link":"nonebot-plugin-datastore","name":"数据存储","desc":"NoneBot 数据存储插件","author":"he0119","homepage":"https://github.com/he0119/nonebot-plugin-datastore","tags":[],"is_official":false,"type":"library","supported_adapters":null,"valid":true,"time":"2023-06-22 11:58:18"},{"name":"帮助","module_name":"module_name","author":"author","version":"0.3.0","desc":"获取插件帮助信息","homepage":"https://nonebot.dev/","project_link":"project_link","tags":[],"supported_adapters":null,"type":"application","time":"2023-08-28T00:00:00.000000+08:00","is_official":true,"valid":true,"skip_test":false}]'
)


Expand All @@ -174,16 +188,30 @@ async def test_store_test_with_key(
await test.run(key="nonebot-plugin-treehelp:nonebot_plugin_treehelp")

mocked_validate_plugin.assert_called_once_with(
{
plugin={
"module_name": "nonebot_plugin_treehelp",
"project_link": "nonebot-plugin-treehelp",
"author": "he0119",
"tags": [],
"is_official": False,
},
config="",
skip_test=False,
data=None,
previous_plugin={
"module_name": "nonebot_plugin_treehelp",
"project_link": "nonebot-plugin-treehelp",
"name": "帮助",
"desc": "获取插件帮助信息",
"author": "he0119",
"homepage": "https://github.com/he0119/nonebot-plugin-treehelp",
"tags": [],
"is_official": False,
"type": "application",
"supported_adapters": None,
"valid": True,
"time": "2023-06-22 12:10:18",
},
"",
False,
None,
)
assert mocked_api["project_link_treehelp"].called
assert not mocked_api["project_link_datastore"].called
Expand Down Expand Up @@ -218,16 +246,17 @@ async def test_store_test_with_key_not_in_previous(
await test.run(key="nonebot-plugin-wordcloud:nonebot_plugin_wordcloud")

mocked_validate_plugin.assert_called_once_with(
{
plugin={
"module_name": "nonebot_plugin_wordcloud",
"project_link": "nonebot-plugin-wordcloud",
"author": "he0119",
"tags": [],
"is_official": False,
},
"",
False,
None,
config="",
skip_test=False,
data=None,
previous_plugin=None,
)

# 不需要判断版本号
Expand Down
35 changes: 24 additions & 11 deletions tests/utils/store_test/test_validate_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ async def test_validate_plugin_skip_test_plugin_test_failed(
plugin_test_dir = tmp_path / "plugin_test"
plugin_test_dir.mkdir()

output_path = Path(__file__).parent / "output.txt"
output_path = Path(__file__).parent / "output_failed.txt"
temp_output_path = plugin_test_dir / "output.txt"
shutil.copyfile(output_path, temp_output_path)

Expand All @@ -301,27 +301,40 @@ async def test_validate_plugin_skip_test_plugin_test_failed(
is_official=False,
)

result, new_plugin = await validate_plugin(plugin, "", True)
result, new_plugin = await validate_plugin(
plugin,
"",
True,
previous_plugin={
"module_name": "nonebot_plugin_treehelp",
"project_link": "nonebot-plugin-treehelp",
"name": "帮助",
"desc": "获取插件帮助信息",
"author": "he0119",
"homepage": "https://nonebot.dev/",
"tags": [],
"is_official": False,
"type": "application",
"supported_adapters": None,
"valid": True,
"time": "2023-06-22 12:10:18",
"version": "0.3.0",
"skip_test": True,
},
)

assert result == {
"time": "2023-08-23T09:22:14.836035+08:00",
"version": "0.3.0",
"inputs": {"config": ""},
"results": {
"load": False,
"metadata": True,
"metadata": False,
"validation": True,
},
"outputs": {
"load": "output",
"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://nonebot.dev/",
"supported_adapters": None,
},
"metadata": None,
"validation": None,
},
}
Expand Down
4 changes: 2 additions & 2 deletions tests/utils/validation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def generate_plugin_data(
homepage: str | None = "https://nonebot.dev",
type: str | None = "application",
supported_adapters: list[str] | None = None,
skip_plugin_test: bool | None = False,
skip_test: bool | None = False,
plugin_test_result: bool | None = True,
plugin_test_output: str | None = "plugin_test_output",
previous_data: list[Any] | None = [],
Expand All @@ -78,7 +78,7 @@ def generate_plugin_data(
"supported_adapters": json.dumps(supported_adapters)
if supported_adapters is not None
else None,
"skip_plugin_test": skip_plugin_test,
"skip_test": skip_test,
"plugin_test_result": plugin_test_result,
"plugin_test_output": plugin_test_output,
"plugin_test_metadata": {},
Expand Down

0 comments on commit 6d0fde0

Please sign in to comment.