mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-05 11:26:43 +08:00
update all test
This commit is contained in:
parent
e7a2ab43a8
commit
8d40ba504c
2
bot.py
2
bot.py
@ -12,4 +12,4 @@ nonebot.load_builtin_plugins("echo")
|
|||||||
nonebot.load_plugins("src/plugins")
|
nonebot.load_plugins("src/plugins")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
nonebot.run(app="bot:app")
|
nonebot.run()
|
||||||
|
@ -15,3 +15,4 @@ from . import (
|
|||||||
__help__version__ = "0.4.3"
|
__help__version__ = "0.4.3"
|
||||||
__help__plugin__name__ = "nonebot_bison"
|
__help__plugin__name__ = "nonebot_bison"
|
||||||
__usage__ = "本bot可以提供b站、微博等社交媒体的消息订阅,详情" "请查看本bot文档,或者at本bot发送“添加订阅”订阅第一个帐号"
|
__usage__ = "本bot可以提供b站、微博等社交媒体的消息订阅,详情" "请查看本bot文档,或者at本bot发送“添加订阅”订阅第一个帐号"
|
||||||
|
__module_name__ = "nonebot-bison"
|
||||||
|
@ -12,7 +12,7 @@ from .platform import platform_manager
|
|||||||
from .plugin_config import plugin_config
|
from .plugin_config import plugin_config
|
||||||
from .send import send_msgs, do_send_msgs
|
from .send import send_msgs, do_send_msgs
|
||||||
|
|
||||||
scheduler = AsyncIOScheduler()
|
scheduler = AsyncIOScheduler(timezone="Asia/Shanghai")
|
||||||
|
|
||||||
|
|
||||||
@get_driver().on_startup
|
@get_driver().on_startup
|
||||||
|
@ -219,3 +219,4 @@ if plugin_config.bison_filter_log:
|
|||||||
if config.log_level is None
|
if config.log_level is None
|
||||||
else config.log_level
|
else config.log_level
|
||||||
)
|
)
|
||||||
|
logger.warning("test")
|
||||||
|
@ -1,36 +1,23 @@
|
|||||||
import typing
|
import typing
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import nonebot
|
import nonebot
|
||||||
from nonebug.fixture import nonebug_init, nonebug_clear
|
from nonebug.app import App
|
||||||
|
|
||||||
if typing.TYPE_CHECKING:
|
|
||||||
import sys
|
|
||||||
|
|
||||||
sys.path.append("./src/plugins")
|
|
||||||
import nonebot_bison
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture # (scope="module")
|
|
||||||
def plugin_module(tmpdir):
|
|
||||||
nonebot.init(bison_config_path=str(tmpdir))
|
|
||||||
nonebot.load_plugins("src/plugins")
|
|
||||||
plugins = nonebot.get_loaded_plugins()
|
|
||||||
plugin = list(filter(lambda x: x.name == "nonebot_bison", plugins))[0]
|
|
||||||
return plugin.module
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def dummy_user_subinfo(plugin_module: "nonebot_bison"):
|
async def app(nonebug_init: None, tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
|
||||||
user = plugin_module.types.User("123", "group")
|
import nonebot
|
||||||
return plugin_module.types.UserSubInfo(
|
|
||||||
user=user, category_getter=lambda _: [], tag_getter=lambda _: []
|
config = nonebot.get_driver().config
|
||||||
)
|
config.bison_config_path = str(tmp_path)
|
||||||
|
return App(monkeypatch)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def n_plugin_module(tmpdir):
|
def dummy_user_subinfo(app: App):
|
||||||
nonebot.init(bison_config_path=str(tmpdir))
|
from nonebot_bison.types import User, UserSubInfo
|
||||||
nonebot.load_plugins("src/plugins")
|
|
||||||
yield None
|
user = User("123", "group")
|
||||||
nonebug_clear()
|
return UserSubInfo(user=user, category_getter=lambda _: [], tag_getter=lambda _: [])
|
||||||
|
@ -1,21 +1,16 @@
|
|||||||
import typing
|
|
||||||
|
|
||||||
import respx
|
import respx
|
||||||
import pytest
|
import pytest
|
||||||
from httpx import Response
|
from httpx import Response
|
||||||
|
from nonebug.app import App
|
||||||
if typing.TYPE_CHECKING:
|
|
||||||
import sys
|
|
||||||
|
|
||||||
sys.path.append("./src/plugins")
|
|
||||||
import nonebot_bison
|
|
||||||
|
|
||||||
from .utils import get_file, get_json
|
from .utils import get_file, get_json
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def arknights(plugin_module: "nonebot_bison"):
|
def arknights(app: App):
|
||||||
return plugin_module.platform.platform_manager["arknights"]
|
from nonebot_bison.platform import platform_manager
|
||||||
|
|
||||||
|
return platform_manager["arknights"]
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
|
@ -1,13 +1,6 @@
|
|||||||
import typing
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from httpx import Response
|
from httpx import Response
|
||||||
|
from nonebug.app import App
|
||||||
if typing.TYPE_CHECKING:
|
|
||||||
import sys
|
|
||||||
|
|
||||||
sys.path.append("./src/plugins")
|
|
||||||
import nonebot_bison
|
|
||||||
|
|
||||||
from .utils import get_json
|
from .utils import get_json
|
||||||
|
|
||||||
@ -18,8 +11,10 @@ def bing_dy_list():
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def bilibili(plugin_module: "nonebot_bison"):
|
def bilibili(app: App):
|
||||||
return plugin_module.platform.platform_manager["bilibili"]
|
from nonebot_bison.platform import platform_manager
|
||||||
|
|
||||||
|
return platform_manager["bilibili"]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
@ -1,22 +1,18 @@
|
|||||||
import time
|
import time
|
||||||
import typing
|
|
||||||
|
|
||||||
import respx
|
import respx
|
||||||
import pytest
|
import pytest
|
||||||
from httpx import Response
|
from httpx import Response
|
||||||
|
from nonebug.app import App
|
||||||
|
|
||||||
from .utils import get_json
|
from .utils import get_json
|
||||||
|
|
||||||
if typing.TYPE_CHECKING:
|
|
||||||
import sys
|
|
||||||
|
|
||||||
sys.path.append("./src/plugins")
|
|
||||||
import nonebot_bison
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def ncm_artist(plugin_module: "nonebot_bison"):
|
def ncm_artist(app: App):
|
||||||
return plugin_module.platform.platform_manager["ncm-artist"]
|
from nonebot_bison.platform import platform_manager
|
||||||
|
|
||||||
|
return platform_manager["ncm-artist"]
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
|
@ -1,22 +1,18 @@
|
|||||||
import time
|
import time
|
||||||
import typing
|
|
||||||
|
|
||||||
import respx
|
import respx
|
||||||
import pytest
|
import pytest
|
||||||
from httpx import Response
|
from httpx import Response
|
||||||
|
from nonebug.app import App
|
||||||
|
|
||||||
from .utils import get_json
|
from .utils import get_json
|
||||||
|
|
||||||
if typing.TYPE_CHECKING:
|
|
||||||
import sys
|
|
||||||
|
|
||||||
sys.path.append("./src/plugins")
|
|
||||||
import nonebot_bison
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def ncm_radio(plugin_module: "nonebot_bison"):
|
def ncm_radio(app: App):
|
||||||
return plugin_module.platform.platform_manager["ncm-radio"]
|
from nonebot_bison.platform import platform_manager
|
||||||
|
|
||||||
|
return platform_manager["ncm-radio"]
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
|
@ -1,18 +1,8 @@
|
|||||||
import sys
|
from time import time
|
||||||
import typing
|
|
||||||
from typing import Any, Optional
|
from typing import Any, Optional
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from nonebug.app import App
|
||||||
if typing.TYPE_CHECKING:
|
|
||||||
import sys
|
|
||||||
|
|
||||||
sys.path.append("./src/plugins")
|
|
||||||
import nonebot_bison
|
|
||||||
from nonebot_bison.types import *
|
|
||||||
from nonebot_bison.post import Post
|
|
||||||
|
|
||||||
from time import time
|
|
||||||
|
|
||||||
now = time()
|
now = time()
|
||||||
passed = now - 3 * 60 * 60
|
passed = now - 3 * 60 * 60
|
||||||
@ -29,22 +19,30 @@ raw_post_list_2 = raw_post_list_1 + [
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def dummy_user(plugin_module: "nonebot_bison"):
|
def dummy_user(app: App):
|
||||||
user = plugin_module.types.User("123", "group")
|
from nonebot_bison.types import User
|
||||||
|
|
||||||
|
user = User("123", "group")
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def user_info_factory(plugin_module: "nonebot_bison", dummy_user):
|
def user_info_factory(app: App, dummy_user):
|
||||||
|
from nonebot_bison.types import UserSubInfo
|
||||||
|
|
||||||
def _user_info(category_getter, tag_getter):
|
def _user_info(category_getter, tag_getter):
|
||||||
return plugin_module.types.UserSubInfo(dummy_user, category_getter, tag_getter)
|
return UserSubInfo(dummy_user, category_getter, tag_getter)
|
||||||
|
|
||||||
return _user_info
|
return _user_info
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_platform_without_cats_tags(plugin_module: "nonebot_bison"):
|
def mock_platform_without_cats_tags(app: App):
|
||||||
class MockPlatform(plugin_module.platform.platform.NewMessage):
|
from nonebot_bison.post import Post
|
||||||
|
from nonebot_bison.types import Target, RawPost
|
||||||
|
from nonebot_bison.platform.platform import NewMessage
|
||||||
|
|
||||||
|
class MockPlatform(NewMessage):
|
||||||
|
|
||||||
platform_name = "mock_platform"
|
platform_name = "mock_platform"
|
||||||
name = "Mock Platform"
|
name = "Mock Platform"
|
||||||
@ -70,7 +68,7 @@ def mock_platform_without_cats_tags(plugin_module: "nonebot_bison"):
|
|||||||
return raw_post["date"]
|
return raw_post["date"]
|
||||||
|
|
||||||
async def parse(self, raw_post: "RawPost") -> "Post":
|
async def parse(self, raw_post: "RawPost") -> "Post":
|
||||||
return plugin_module.post.Post(
|
return Post(
|
||||||
"mock_platform",
|
"mock_platform",
|
||||||
raw_post["text"],
|
raw_post["text"],
|
||||||
"http://t.tt/" + str(self.get_id(raw_post)),
|
"http://t.tt/" + str(self.get_id(raw_post)),
|
||||||
@ -88,8 +86,12 @@ def mock_platform_without_cats_tags(plugin_module: "nonebot_bison"):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_platform(plugin_module: "nonebot_bison"):
|
def mock_platform(app: App):
|
||||||
class MockPlatform(plugin_module.platform.platform.NewMessage):
|
from nonebot_bison.post import Post
|
||||||
|
from nonebot_bison.platform.platform import NewMessage
|
||||||
|
from nonebot_bison.types import Tag, Target, RawPost, Category
|
||||||
|
|
||||||
|
class MockPlatform(NewMessage):
|
||||||
|
|
||||||
platform_name = "mock_platform"
|
platform_name = "mock_platform"
|
||||||
name = "Mock Platform"
|
name = "Mock Platform"
|
||||||
@ -99,8 +101,8 @@ def mock_platform(plugin_module: "nonebot_bison"):
|
|||||||
enable_tag = True
|
enable_tag = True
|
||||||
has_target = True
|
has_target = True
|
||||||
categories = {
|
categories = {
|
||||||
1: "转发",
|
Category(1): "转发",
|
||||||
2: "视频",
|
Category(2): "视频",
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -124,7 +126,7 @@ def mock_platform(plugin_module: "nonebot_bison"):
|
|||||||
return raw_post["category"]
|
return raw_post["category"]
|
||||||
|
|
||||||
async def parse(self, raw_post: "RawPost") -> "Post":
|
async def parse(self, raw_post: "RawPost") -> "Post":
|
||||||
return plugin_module.post.Post(
|
return Post(
|
||||||
"mock_platform",
|
"mock_platform",
|
||||||
raw_post["text"],
|
raw_post["text"],
|
||||||
"http://t.tt/" + str(self.get_id(raw_post)),
|
"http://t.tt/" + str(self.get_id(raw_post)),
|
||||||
@ -142,8 +144,12 @@ def mock_platform(plugin_module: "nonebot_bison"):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_platform_no_target(plugin_module: "nonebot_bison"):
|
def mock_platform_no_target(app: App):
|
||||||
class MockPlatform(plugin_module.platform.platform.NewMessage):
|
from nonebot_bison.post import Post
|
||||||
|
from nonebot_bison.types import Tag, Target, RawPost, Category
|
||||||
|
from nonebot_bison.platform.platform import NewMessage, CategoryNotSupport
|
||||||
|
|
||||||
|
class MockPlatform(NewMessage):
|
||||||
|
|
||||||
platform_name = "mock_platform"
|
platform_name = "mock_platform"
|
||||||
name = "Mock Platform"
|
name = "Mock Platform"
|
||||||
@ -153,7 +159,7 @@ def mock_platform_no_target(plugin_module: "nonebot_bison"):
|
|||||||
schedule_kw = {"seconds": 30}
|
schedule_kw = {"seconds": 30}
|
||||||
enable_tag = True
|
enable_tag = True
|
||||||
has_target = False
|
has_target = False
|
||||||
categories = {1: "转发", 2: "视频", 3: "不支持"}
|
categories = {Category(1): "转发", Category(2): "视频", Category(3): "不支持"}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.sub_index = 0
|
self.sub_index = 0
|
||||||
@ -174,11 +180,11 @@ def mock_platform_no_target(plugin_module: "nonebot_bison"):
|
|||||||
|
|
||||||
def get_category(self, raw_post: "RawPost") -> "Category":
|
def get_category(self, raw_post: "RawPost") -> "Category":
|
||||||
if raw_post["category"] == 3:
|
if raw_post["category"] == 3:
|
||||||
raise plugin_module.platform.platform.CategoryNotSupport()
|
raise CategoryNotSupport()
|
||||||
return raw_post["category"]
|
return raw_post["category"]
|
||||||
|
|
||||||
async def parse(self, raw_post: "RawPost") -> "Post":
|
async def parse(self, raw_post: "RawPost") -> "Post":
|
||||||
return plugin_module.post.Post(
|
return Post(
|
||||||
"mock_platform",
|
"mock_platform",
|
||||||
raw_post["text"],
|
raw_post["text"],
|
||||||
"http://t.tt/" + str(self.get_id(raw_post)),
|
"http://t.tt/" + str(self.get_id(raw_post)),
|
||||||
@ -196,8 +202,12 @@ def mock_platform_no_target(plugin_module: "nonebot_bison"):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_platform_no_target_2(plugin_module: "nonebot_bison"):
|
def mock_platform_no_target_2(app: App):
|
||||||
class MockPlatform(plugin_module.platform.platform.NewMessage):
|
from nonebot_bison.post import Post
|
||||||
|
from nonebot_bison.platform.platform import NewMessage
|
||||||
|
from nonebot_bison.types import Tag, Target, RawPost, Category
|
||||||
|
|
||||||
|
class MockPlatform(NewMessage):
|
||||||
|
|
||||||
platform_name = "mock_platform"
|
platform_name = "mock_platform"
|
||||||
name = "Mock Platform"
|
name = "Mock Platform"
|
||||||
@ -208,8 +218,8 @@ def mock_platform_no_target_2(plugin_module: "nonebot_bison"):
|
|||||||
enable_tag = True
|
enable_tag = True
|
||||||
has_target = False
|
has_target = False
|
||||||
categories = {
|
categories = {
|
||||||
4: "leixing4",
|
Category(4): "leixing4",
|
||||||
5: "leixing5",
|
Category(5): "leixing5",
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -233,7 +243,7 @@ def mock_platform_no_target_2(plugin_module: "nonebot_bison"):
|
|||||||
return raw_post["category"]
|
return raw_post["category"]
|
||||||
|
|
||||||
async def parse(self, raw_post: "RawPost") -> "Post":
|
async def parse(self, raw_post: "RawPost") -> "Post":
|
||||||
return plugin_module.post.Post(
|
return Post(
|
||||||
"mock_platform_2",
|
"mock_platform_2",
|
||||||
raw_post["text"],
|
raw_post["text"],
|
||||||
"http://t.tt/" + str(self.get_id(raw_post)),
|
"http://t.tt/" + str(self.get_id(raw_post)),
|
||||||
@ -259,8 +269,12 @@ def mock_platform_no_target_2(plugin_module: "nonebot_bison"):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_status_change(plugin_module: "nonebot_bison"):
|
def mock_status_change(app: App):
|
||||||
class MockPlatform(plugin_module.platform.platform.StatusChange):
|
from nonebot_bison.post import Post
|
||||||
|
from nonebot_bison.platform.platform import StatusChange
|
||||||
|
from nonebot_bison.types import Tag, Target, RawPost, Category
|
||||||
|
|
||||||
|
class MockPlatform(StatusChange):
|
||||||
|
|
||||||
platform_name = "mock_platform"
|
platform_name = "mock_platform"
|
||||||
name = "Mock Platform"
|
name = "Mock Platform"
|
||||||
@ -271,8 +285,8 @@ def mock_status_change(plugin_module: "nonebot_bison"):
|
|||||||
schedule_kw = {"seconds": 10}
|
schedule_kw = {"seconds": 10}
|
||||||
has_target = False
|
has_target = False
|
||||||
categories = {
|
categories = {
|
||||||
1: "转发",
|
Category(1): "转发",
|
||||||
2: "视频",
|
Category(2): "视频",
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -297,7 +311,7 @@ def mock_status_change(plugin_module: "nonebot_bison"):
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
async def parse(self, raw_post) -> "Post":
|
async def parse(self, raw_post) -> "Post":
|
||||||
return plugin_module.post.Post("mock_status", raw_post["text"], "")
|
return Post("mock_status", raw_post["text"], "")
|
||||||
|
|
||||||
def get_category(self, raw_post):
|
def get_category(self, raw_post):
|
||||||
return raw_post["cat"]
|
return raw_post["cat"]
|
||||||
@ -420,14 +434,17 @@ async def test_status_change(mock_status_change, user_info_factory):
|
|||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_group(
|
async def test_group(
|
||||||
plugin_module: "nonebot_bison",
|
app: App,
|
||||||
mock_platform_no_target,
|
mock_platform_no_target,
|
||||||
mock_platform_no_target_2,
|
mock_platform_no_target_2,
|
||||||
user_info_factory,
|
user_info_factory,
|
||||||
):
|
):
|
||||||
group_platform = plugin_module.platform.platform.NoTargetGroup(
|
|
||||||
[mock_platform_no_target, mock_platform_no_target_2]
|
from nonebot_bison.post import Post
|
||||||
)
|
from nonebot_bison.platform.platform import NoTargetGroup
|
||||||
|
from nonebot_bison.types import Tag, Target, RawPost, Category
|
||||||
|
|
||||||
|
group_platform = NoTargetGroup([mock_platform_no_target, mock_platform_no_target_2])
|
||||||
res1 = await group_platform.fetch_new_post(
|
res1 = await group_platform.fetch_new_post(
|
||||||
"dummy", [user_info_factory(lambda _: [1, 4], lambda _: [])]
|
"dummy", [user_info_factory(lambda _: [1, 4], lambda _: [])]
|
||||||
)
|
)
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import typing
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import respx
|
import respx
|
||||||
@ -6,19 +5,16 @@ import pytest
|
|||||||
import feedparser
|
import feedparser
|
||||||
from pytz import timezone
|
from pytz import timezone
|
||||||
from httpx import Response
|
from httpx import Response
|
||||||
|
from nonebug.app import App
|
||||||
if typing.TYPE_CHECKING:
|
|
||||||
import sys
|
|
||||||
|
|
||||||
sys.path.append("./src/plugins")
|
|
||||||
import nonebot_bison
|
|
||||||
|
|
||||||
from .utils import get_file, get_json
|
from .utils import get_file, get_json
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def weibo(plugin_module: "nonebot_bison"):
|
def weibo(app: App):
|
||||||
return plugin_module.platform.platform_manager["weibo"]
|
from nonebot_bison.platform import platform_manager
|
||||||
|
|
||||||
|
return platform_manager["weibo"]
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
path = Path(__file__).parent
|
path = Path(__file__).parent / "static"
|
||||||
|
|
||||||
|
|
||||||
def get_json(file_name: str):
|
def get_json(file_name: str):
|
||||||
|
@ -1,23 +1,28 @@
|
|||||||
import typing
|
import typing
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from nonebug.app import App
|
||||||
|
|
||||||
if typing.TYPE_CHECKING:
|
if typing.TYPE_CHECKING:
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
sys.path.append("./src/plugins")
|
sys.path.append("./src/plugins")
|
||||||
import nonebot_bison
|
import nonebot_bison
|
||||||
|
from nonebot_bison.config import Config
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def config(plugin_module):
|
def config(app: App):
|
||||||
plugin_module.config.start_up()
|
from nonebot_bison import config
|
||||||
return plugin_module.config.Config()
|
|
||||||
|
config.start_up()
|
||||||
|
return config.Config()
|
||||||
|
|
||||||
|
|
||||||
def test_create_and_get(
|
def test_create_and_get(config: "Config", app: App):
|
||||||
config: "nonebot_bison.config.Config", plugin_module: "nonebot_bison"
|
from nonebot_bison import types
|
||||||
):
|
from nonebot_bison.types import Target
|
||||||
|
|
||||||
config.add_subscribe(
|
config.add_subscribe(
|
||||||
user="123",
|
user="123",
|
||||||
user_type="group",
|
user_type="group",
|
||||||
@ -29,8 +34,8 @@ def test_create_and_get(
|
|||||||
)
|
)
|
||||||
confs = config.list_subscribe("123", "group")
|
confs = config.list_subscribe("123", "group")
|
||||||
assert len(confs) == 1
|
assert len(confs) == 1
|
||||||
assert config.target_user_cache["weibo"]["weibo_id"] == [
|
assert config.target_user_cache["weibo"][Target("weibo_id")] == [
|
||||||
plugin_module.types.User("123", "group")
|
types.User("123", "group")
|
||||||
]
|
]
|
||||||
assert confs[0]["cats"] == []
|
assert confs[0]["cats"] == []
|
||||||
config.update_subscribe(
|
config.update_subscribe(
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import typing
|
import typing
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from nonebug.app import App
|
||||||
|
|
||||||
if typing.TYPE_CHECKING:
|
if typing.TYPE_CHECKING:
|
||||||
import sys
|
import sys
|
||||||
@ -40,48 +41,56 @@ merge_source_9_2 = [
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_9_merge(plugin_module: "nonebot_bison"):
|
async def test_9_merge(app: App):
|
||||||
post = plugin_module.post.Post("", "", "", pics=merge_source_9)
|
from nonebot_bison.post import Post
|
||||||
|
|
||||||
|
post = Post("", "", "", pics=merge_source_9)
|
||||||
await post._pic_merge()
|
await post._pic_merge()
|
||||||
assert len(post.pics) == 5
|
assert len(post.pics) == 5
|
||||||
await post.generate_messages()
|
await post.generate_messages()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_9_merge_2(plugin_module: "nonebot_bison"):
|
async def test_9_merge_2(app: App):
|
||||||
post = plugin_module.post.Post("", "", "", pics=merge_source_9_2)
|
from nonebot_bison.post import Post
|
||||||
|
|
||||||
|
post = Post("", "", "", pics=merge_source_9_2)
|
||||||
await post._pic_merge()
|
await post._pic_merge()
|
||||||
assert len(post.pics) == 4
|
assert len(post.pics) == 4
|
||||||
await post.generate_messages()
|
await post.generate_messages()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_6_merge(plugin_module):
|
async def test_6_merge(app: App):
|
||||||
post = plugin_module.post.Post(
|
from nonebot_bison.post import Post
|
||||||
"", "", "", pics=merge_source_9[0:6] + merge_source_9[9:]
|
|
||||||
)
|
post = Post("", "", "", pics=merge_source_9[0:6] + merge_source_9[9:])
|
||||||
await post._pic_merge()
|
await post._pic_merge()
|
||||||
assert len(post.pics) == 5
|
assert len(post.pics) == 5
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_3_merge(plugin_module):
|
async def test_3_merge(app: App):
|
||||||
post = plugin_module.post.Post(
|
from nonebot_bison.post import Post
|
||||||
"", "", "", pics=merge_source_9[0:3] + merge_source_9[9:]
|
|
||||||
)
|
post = Post("", "", "", pics=merge_source_9[0:3] + merge_source_9[9:])
|
||||||
await post._pic_merge()
|
await post._pic_merge()
|
||||||
assert len(post.pics) == 5
|
assert len(post.pics) == 5
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_6_merge_only(plugin_module):
|
async def test_6_merge_only(app: App):
|
||||||
post = plugin_module.post.Post("", "", "", pics=merge_source_9[0:6])
|
from nonebot_bison.post import Post
|
||||||
|
|
||||||
|
post = Post("", "", "", pics=merge_source_9[0:6])
|
||||||
await post._pic_merge()
|
await post._pic_merge()
|
||||||
assert len(post.pics) == 1
|
assert len(post.pics) == 1
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_3_merge_only(plugin_module):
|
async def test_3_merge_only(app: App):
|
||||||
post = plugin_module.post.Post("", "", "", pics=merge_source_9[0:3])
|
from nonebot_bison.post import Post
|
||||||
|
|
||||||
|
post = Post("", "", "", pics=merge_source_9[0:3])
|
||||||
await post._pic_merge()
|
await post._pic_merge()
|
||||||
assert len(post.pics) == 1
|
assert len(post.pics) == 1
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
import pytest
|
|
||||||
|
|
||||||
|
|
||||||
def test_add(n_plugin_module):
|
|
||||||
from nonebot_bison.config import Config
|
|
||||||
|
|
||||||
config = Config()
|
|
||||||
config.add_subscribe(
|
|
||||||
user="123",
|
|
||||||
user_type="group",
|
|
||||||
target="weibo_id",
|
|
||||||
target_name="weibo_name",
|
|
||||||
target_type="weibo",
|
|
||||||
cats=[],
|
|
||||||
tags=[],
|
|
||||||
)
|
|
@ -1,6 +1,7 @@
|
|||||||
import typing
|
import typing
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from nonebug.app import App
|
||||||
|
|
||||||
if typing.TYPE_CHECKING:
|
if typing.TYPE_CHECKING:
|
||||||
import sys
|
import sys
|
||||||
@ -11,8 +12,10 @@ if typing.TYPE_CHECKING:
|
|||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@pytest.mark.render
|
@pytest.mark.render
|
||||||
async def test_render(plugin_module: "nonebot_bison"):
|
async def test_render(app: App):
|
||||||
render = plugin_module.utils.Render()
|
from nonebot_bison.utils import Render
|
||||||
|
|
||||||
|
render = Render()
|
||||||
res = await render.text_to_pic(
|
res = await render.text_to_pic(
|
||||||
"""a\nbbbbbbbbbbbbbbbbbbbbbb\ncd
|
"""a\nbbbbbbbbbbbbbbbbbbbbbb\ncd
|
||||||
<h1>中文</h1>
|
<h1>中文</h1>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user