Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: 添加用于动态继承支持适配器数据的方法 #2127

Merged
merged 4 commits into from
Jun 27, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
✅ 为 inherit_supported_adapters 添加测试
NCBM committed Jun 25, 2023

Unverified

This user has not yet uploaded their public signing key.
commit 9633c10c292b36068911c997908378cef95a72e1
11 changes: 11 additions & 0 deletions tests/plugins/metadata_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from nonebot.plugin import PluginMetadata

__plugin_meta__ = PluginMetadata(
name="测试插件2",
description="测试继承适配器",
usage="无法使用",
type="application",
homepage="https://nonebot.dev",
supported_adapters={"~onebot.v11", "~onebot.v12"},
extra={"author": "NoneBot"},
)
31 changes: 30 additions & 1 deletion tests/test_plugin/test_load.py
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
import pytest

import nonebot
from nonebot.plugin import Plugin, PluginManager, _managers
from nonebot.plugin import Plugin, PluginManager, _managers, inherit_supported_adapters


@pytest.mark.asyncio
@@ -147,3 +147,32 @@ async def test_plugin_metadata():
}

assert plugin.metadata.get_supported_adapters() == {FakeAdapter}


@pytest.mark.asyncio
async def test_inherit_supported_adapters():
with pytest.raises(RuntimeError):
inherit_supported_adapters("some_plugin_not_exist")

with pytest.raises(ValueError, match="has no metadata!"):
inherit_supported_adapters("export")

echo = nonebot.get_plugin("echo")
assert echo
assert echo.metadata
assert inherit_supported_adapters("echo") is None

plugin_1 = nonebot.get_plugin("metadata")
assert plugin_1
assert plugin_1.metadata
assert (
inherit_supported_adapters("metadata") == plugin_1.metadata.supported_adapters
)

plugin_2 = nonebot.get_plugin("metadata_2")
assert plugin_2
assert plugin_2.metadata
assert inherit_supported_adapters("metadata", "metadata_2") == {"~onebot.v11"}
assert inherit_supported_adapters("metadata", "echo", "metadata_2") == {
"~onebot.v11"
}