mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2026-05-11 03:18:29 +08:00
🧑💻 使用 Ruff 包办所有格式化和检查 (#663)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import typing
|
||||
|
||||
import pytest
|
||||
from nonebug.app import App
|
||||
import pytest
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
import sys
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import pytest
|
||||
from nonebug.app import App
|
||||
import pytest
|
||||
|
||||
|
||||
async def test_add_subscribe(app: App, init_scheduler):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
from sqlalchemy.sql.expression import select
|
||||
from nonebot_plugin_datastore.db import get_engine
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
from sqlalchemy.ext.asyncio.session import AsyncSession
|
||||
from sqlalchemy.sql.expression import select
|
||||
|
||||
from nonebot_bison.config.db_config import config
|
||||
from nonebot_bison.config.db_model import Subscribe, Target, User
|
||||
from nonebot_bison.types import Target as TTarget
|
||||
from nonebot_bison.config.db_model import User, Target, Subscribe
|
||||
|
||||
await config.add_subscribe(
|
||||
TargetQQGroup(group_id=123),
|
||||
@@ -69,8 +69,8 @@ async def test_add_subscribe(app: App, init_scheduler):
|
||||
async def test_add_dup_sub(init_scheduler):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
from nonebot_bison.types import Target as TTarget
|
||||
from nonebot_bison.config.db_config import SubscribeDupException, config
|
||||
from nonebot_bison.types import Target as TTarget
|
||||
|
||||
await config.add_subscribe(
|
||||
TargetQQGroup(group_id=123),
|
||||
@@ -93,15 +93,15 @@ async def test_add_dup_sub(init_scheduler):
|
||||
|
||||
|
||||
async def test_del_subsribe(init_scheduler):
|
||||
from sqlalchemy.sql.functions import func
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
from sqlalchemy.sql.expression import select
|
||||
from nonebot_plugin_datastore.db import get_engine
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
from sqlalchemy.ext.asyncio.session import AsyncSession
|
||||
from sqlalchemy.sql.expression import select
|
||||
from sqlalchemy.sql.functions import func
|
||||
|
||||
from nonebot_bison.config.db_config import config
|
||||
from nonebot_bison.config.db_model import Subscribe, Target
|
||||
from nonebot_bison.types import Target as TTarget
|
||||
from nonebot_bison.config.db_model import Target, Subscribe
|
||||
|
||||
await config.add_subscribe(
|
||||
TargetQQGroup(group_id=123),
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
from datetime import datetime
|
||||
import json
|
||||
from typing import cast
|
||||
from datetime import datetime
|
||||
|
||||
import pytest
|
||||
from nonebug import App
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("_patch_weibo_get_cookie_name")
|
||||
@@ -11,9 +11,9 @@ async def test_cookie(app: App, init_scheduler):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
from nonebot_bison.config.db_config import config
|
||||
from nonebot_bison.config.utils import DuplicateCookieTargetException
|
||||
from nonebot_bison.scheduler import scheduler_dict
|
||||
from nonebot_bison.types import Target as T_Target
|
||||
from nonebot_bison.config.utils import DuplicateCookieTargetException
|
||||
from nonebot_bison.utils.site import CookieClientManager, site_manager
|
||||
|
||||
target = T_Target("weibo_id")
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
async def test_migration(use_legacy_config):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
from nonebot_plugin_datastore.db import init_db
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
from nonebot_bison.config.db_config import config
|
||||
from nonebot_bison.config.config_legacy import Config
|
||||
from nonebot_bison.config.db_config import config
|
||||
|
||||
config_legacy = Config()
|
||||
config_legacy.add_subscribe(
|
||||
@@ -57,11 +57,11 @@ async def test_migration(use_legacy_config):
|
||||
|
||||
|
||||
async def test_migrate_dup(use_legacy_config):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
from nonebot_plugin_datastore.db import init_db
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
from nonebot_bison.config.db_config import config
|
||||
from nonebot_bison.config.config_legacy import Config
|
||||
from nonebot_bison.config.db_config import config
|
||||
|
||||
config_legacy = Config()
|
||||
config_legacy.add_subscribe(
|
||||
|
||||
@@ -7,8 +7,8 @@ from pytest_mock import MockerFixture
|
||||
async def test_create_config(init_scheduler):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
from nonebot_bison.config.db_config import TimeWeightConfig, WeightConfig, config
|
||||
from nonebot_bison.types import Target as T_Target
|
||||
from nonebot_bison.config.db_config import WeightConfig, TimeWeightConfig, config
|
||||
|
||||
await config.add_subscribe(
|
||||
TargetQQGroup(group_id=123),
|
||||
@@ -49,8 +49,8 @@ async def test_get_current_weight(init_scheduler, mocker: MockerFixture):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
from nonebot_bison.config import db_config
|
||||
from nonebot_bison.config.db_config import TimeWeightConfig, WeightConfig, config
|
||||
from nonebot_bison.types import Target as T_Target
|
||||
from nonebot_bison.config.db_config import WeightConfig, TimeWeightConfig, config
|
||||
|
||||
await config.add_subscribe(
|
||||
TargetQQGroup(group_id=123),
|
||||
@@ -108,13 +108,13 @@ async def test_get_current_weight(init_scheduler, mocker: MockerFixture):
|
||||
|
||||
|
||||
async def test_get_platform_target(app: App, init_scheduler):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
from sqlalchemy.sql.expression import select
|
||||
from nonebot_plugin_datastore.db import get_engine
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
from sqlalchemy.ext.asyncio.session import AsyncSession
|
||||
from sqlalchemy.sql.expression import select
|
||||
|
||||
from nonebot_bison.config.db_model import Target
|
||||
from nonebot_bison.config.db_config import config
|
||||
from nonebot_bison.config.db_model import Target
|
||||
from nonebot_bison.types import Target as T_Target
|
||||
|
||||
await config.add_subscribe(
|
||||
@@ -158,9 +158,9 @@ async def test_get_platform_target(app: App, init_scheduler):
|
||||
async def test_get_platform_target_subscribers(app: App, init_scheduler):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
from nonebot_bison.types import UserSubInfo
|
||||
from nonebot_bison.config.db_config import config
|
||||
from nonebot_bison.types import Target as T_Target
|
||||
from nonebot_bison.types import UserSubInfo
|
||||
|
||||
await config.add_subscribe(
|
||||
TargetQQGroup(group_id=123),
|
||||
|
||||
+10
-10
@@ -1,13 +1,13 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from shutil import rmtree
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
import nonebot
|
||||
from sqlalchemy import delete
|
||||
from nonebug import NONEBOT_INIT_KWARGS, App
|
||||
from pytest_mock.plugin import MockerFixture
|
||||
from nonebot.adapters.onebot.v11 import Adapter as OnebotV11Adapter
|
||||
from nonebug import NONEBOT_INIT_KWARGS, App
|
||||
import pytest
|
||||
from pytest_mock.plugin import MockerFixture
|
||||
from sqlalchemy import delete
|
||||
|
||||
from .utils import AppReq
|
||||
|
||||
@@ -44,12 +44,12 @@ async def app(tmp_path: Path, request: pytest.FixtureRequest, mocker: MockerFixt
|
||||
sys.path.append(str(Path(__file__).parent.parent / "src" / "plugins"))
|
||||
|
||||
nonebot.require("nonebot_bison")
|
||||
from nonebot_plugin_htmlrender.browser import shutdown_browser
|
||||
from nonebot_plugin_datastore.db import init_db, create_session
|
||||
from nonebot_plugin_datastore.config import plugin_config as datastore_config
|
||||
from nonebot_plugin_datastore.db import create_session, init_db
|
||||
from nonebot_plugin_htmlrender.browser import shutdown_browser
|
||||
|
||||
from nonebot_bison import plugin_config
|
||||
from nonebot_bison.config.db_model import User, Target, Subscribe, ScheduleTimeWeight
|
||||
from nonebot_bison.config.db_model import ScheduleTimeWeight, Subscribe, Target, User
|
||||
|
||||
plugin_config.bison_config_path = str(tmp_path / "legacy_config")
|
||||
plugin_config.bison_filter_log = False
|
||||
@@ -111,8 +111,8 @@ async def init_scheduler(app: App):
|
||||
async def use_legacy_config(app: App):
|
||||
import aiofiles
|
||||
|
||||
from nonebot_bison.utils import Singleton
|
||||
from nonebot_bison.config.config_legacy import Config, get_config_path
|
||||
from nonebot_bison.utils import Singleton
|
||||
|
||||
# 默认不创建配置所在的文件夹
|
||||
# 如果需要测试需要手动创建相关文件夹
|
||||
@@ -132,8 +132,8 @@ async def use_legacy_config(app: App):
|
||||
|
||||
@pytest.fixture
|
||||
async def _no_browser(app: App, mocker: MockerFixture):
|
||||
from nonebot_bison.plugin_config import plugin_config
|
||||
from nonebot_bison.platform import _get_unavailable_platforms
|
||||
from nonebot_bison.plugin_config import plugin_config
|
||||
|
||||
mocker.patch.object(plugin_config, "bison_use_browser", False)
|
||||
mocker.patch("nonebot_bison.platform.unavailable_paltforms", _get_unavailable_platforms())
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
from time import time
|
||||
|
||||
import respx
|
||||
import pytest
|
||||
from httpx import Response
|
||||
from nonebug.app import App
|
||||
from nonebot.compat import model_dump, type_validate_python
|
||||
from nonebug.app import App
|
||||
import pytest
|
||||
import respx
|
||||
|
||||
from .utils import get_file, get_json
|
||||
|
||||
@@ -12,7 +12,7 @@ from .utils import get_file, get_json
|
||||
@pytest.fixture
|
||||
def arknights(app: App):
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
from nonebot_bison.utils import DefaultClientManager, ProcessContext
|
||||
|
||||
return platform_manager["arknights"](ProcessContext(DefaultClientManager()))
|
||||
|
||||
@@ -44,8 +44,8 @@ def monster_siren_list_1():
|
||||
|
||||
@respx.mock
|
||||
async def test_url_parse(app: App):
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
from nonebot_bison.platform.arknights import Arknights, BulletinData, BulletinListItem, ArkBulletinResponse
|
||||
from nonebot_bison.platform.arknights import ArkBulletinResponse, Arknights, BulletinData, BulletinListItem
|
||||
from nonebot_bison.utils import DefaultClientManager, ProcessContext
|
||||
|
||||
cid_router = respx.get("https://ak-webview.hypergryph.com/api/game/bulletin/1")
|
||||
|
||||
@@ -110,10 +110,10 @@ async def test_url_parse(app: App):
|
||||
assert p4.url == "http://www.baidu.com/"
|
||||
|
||||
|
||||
@pytest.mark.asyncio()
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_date_in_bulletin(app: App):
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
from nonebot_bison.platform.arknights import Arknights, BulletinListItem
|
||||
from nonebot_bison.utils import DefaultClientManager, ProcessContext
|
||||
|
||||
arknights = Arknights(ProcessContext(DefaultClientManager()))
|
||||
assert (
|
||||
@@ -131,11 +131,11 @@ async def test_get_date_in_bulletin(app: App):
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio()
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_parse_with_breakline(app: App):
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
from nonebot_bison.platform.arknights import Arknights, BulletinListItem
|
||||
from nonebot_bison.utils import DefaultClientManager, ProcessContext
|
||||
|
||||
detail = get_json("arknights-detail-805")
|
||||
detail["data"]["header"] = ""
|
||||
@@ -158,7 +158,7 @@ async def test_parse_with_breakline(app: App):
|
||||
assert post.title == "【公开招募】 - 标签刷新通知"
|
||||
|
||||
|
||||
@pytest.mark.asyncio()
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_fetch_new(
|
||||
arknights,
|
||||
@@ -168,9 +168,9 @@ async def test_fetch_new(
|
||||
monster_siren_list_0,
|
||||
monster_siren_list_1,
|
||||
):
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import Target, SubUnit
|
||||
from nonebot_bison.platform.arknights import ArknightsPost
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import SubUnit, Target
|
||||
|
||||
ak_list_router = respx.get("https://ak-webview.hypergryph.com/api/game/bulletinList?target=IOS")
|
||||
detail_router = respx.get("https://ak-webview.hypergryph.com/api/game/bulletin/5716")
|
||||
@@ -229,7 +229,7 @@ async def test_fetch_new(
|
||||
assert "brief" == post3.get_priority_themes()[0]
|
||||
|
||||
|
||||
@pytest.mark.render()
|
||||
@pytest.mark.render
|
||||
@respx.mock
|
||||
async def test_send_with_render(
|
||||
arknights,
|
||||
@@ -239,8 +239,8 @@ async def test_send_with_render(
|
||||
monster_siren_list_0,
|
||||
monster_siren_list_1,
|
||||
):
|
||||
from nonebot_bison.types import Target, SubUnit
|
||||
from nonebot_bison.platform.arknights import ArknightsPost
|
||||
from nonebot_bison.types import SubUnit, Target
|
||||
|
||||
ak_list_router = respx.get("https://ak-webview.hypergryph.com/api/game/bulletinList?target=IOS")
|
||||
detail_router = respx.get("https://ak-webview.hypergryph.com/api/game/bulletin/8397")
|
||||
@@ -284,13 +284,13 @@ async def test_send_with_render(
|
||||
assert r
|
||||
|
||||
|
||||
@pytest.mark.render()
|
||||
@pytest.mark.render
|
||||
@respx.mock
|
||||
async def test_parse_title(
|
||||
app: App,
|
||||
):
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
from nonebot_bison.platform.arknights import Arknights, BulletinListItem
|
||||
from nonebot_bison.utils import DefaultClientManager, ProcessContext
|
||||
|
||||
detail_router = respx.get("https://ak-webview.hypergryph.com/api/game/bulletin/8397")
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
from datetime import datetime
|
||||
import random
|
||||
from time import time
|
||||
from datetime import datetime
|
||||
from typing import TYPE_CHECKING, Any
|
||||
from typing import TYPE_CHECKING, Any, ClassVar
|
||||
|
||||
import respx
|
||||
import pytest
|
||||
from loguru import logger
|
||||
from nonebug.app import App
|
||||
from httpx import URL, Response
|
||||
from freezegun import freeze_time
|
||||
from pytest_mock import MockerFixture
|
||||
from httpx import URL, Response
|
||||
from loguru import logger
|
||||
from nonebot.compat import model_dump, type_validate_python
|
||||
from nonebug.app import App
|
||||
import pytest
|
||||
from pytest_mock import MockerFixture
|
||||
import respx
|
||||
|
||||
from .utils import get_json
|
||||
|
||||
@@ -28,9 +28,9 @@ if TYPE_CHECKING:
|
||||
|
||||
@pytest.fixture
|
||||
def bilibili(app: App) -> "Bilibili":
|
||||
from nonebot_bison.utils import ProcessContext
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.platform.bilibili import BilibiliClientManager
|
||||
from nonebot_bison.utils import ProcessContext
|
||||
|
||||
return platform_manager["bilibili"](ProcessContext(BilibiliClientManager())) # type: ignore
|
||||
|
||||
@@ -62,7 +62,7 @@ def without_dynamic(app: App):
|
||||
async def test_reset_on_exception(app: App):
|
||||
from strenum import StrEnum
|
||||
|
||||
from nonebot_bison.platform.bilibili.fsm import FSM, StateGraph, Transition, ActionReturn, reset_on_exception
|
||||
from nonebot_bison.platform.bilibili.fsm import FSM, ActionReturn, StateGraph, Transition, reset_on_exception
|
||||
|
||||
class State(StrEnum):
|
||||
A = "A"
|
||||
@@ -146,12 +146,12 @@ async def test_reset_on_exception(app: App):
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_retry_for_352(app: App, mocker: MockerFixture):
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import Target, RawPost
|
||||
from nonebot_bison.platform.platform import NewMessage
|
||||
from nonebot_bison.platform.bilibili.platforms import ApiCode352Error
|
||||
from nonebot_bison.utils import ClientManager, ProcessContext, http_client
|
||||
from nonebot_bison.platform.bilibili.retry import RetryAddon, RetryState, _retry_fsm, retry_for_352
|
||||
from nonebot_bison.platform.platform import NewMessage
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import RawPost, Target
|
||||
from nonebot_bison.utils import ClientManager, ProcessContext, http_client
|
||||
|
||||
mocker.patch.object(random, "random", return_value=0.0) # 稳定触发RAISE阶段的随缘刷新
|
||||
|
||||
@@ -166,7 +166,7 @@ async def test_retry_for_352(app: App, mocker: MockerFixture):
|
||||
is_common = True
|
||||
schedule_interval = 10
|
||||
enable_tag = False
|
||||
categories = {}
|
||||
categories: ClassVar[dict] = {}
|
||||
has_target = True
|
||||
|
||||
raise352 = False
|
||||
@@ -422,7 +422,7 @@ async def test_dynamic_forword_deleted(bilibili: "Bilibili", bing_dy_list: list)
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_fetch_new_without_dynamic(bilibili, dummy_user_subinfo, without_dynamic):
|
||||
from nonebot_bison.types import Target, SubUnit
|
||||
from nonebot_bison.types import SubUnit, Target
|
||||
|
||||
target = Target("161775300")
|
||||
post_router = respx.get(
|
||||
@@ -439,8 +439,8 @@ async def test_fetch_new_without_dynamic(bilibili, dummy_user_subinfo, without_d
|
||||
async def test_fetch_new(bilibili, dummy_user_subinfo):
|
||||
from nonebot.compat import model_dump, type_validate_python
|
||||
|
||||
from nonebot_bison.types import Target, SubUnit
|
||||
from nonebot_bison.platform.bilibili.models import PostAPI
|
||||
from nonebot_bison.types import SubUnit, Target
|
||||
|
||||
target = Target("161775300")
|
||||
|
||||
@@ -483,8 +483,8 @@ async def test_fetch_new(bilibili, dummy_user_subinfo):
|
||||
async def test_fetch_new_live_rcmd(bilibili: "Bilibili", dummy_user_subinfo):
|
||||
from nonebot.compat import model_dump, type_validate_python
|
||||
|
||||
from nonebot_bison.types import Target, SubUnit
|
||||
from nonebot_bison.platform.bilibili.models import PostAPI
|
||||
from nonebot_bison.types import SubUnit, Target
|
||||
|
||||
target = Target("13164144")
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import typing
|
||||
|
||||
import respx
|
||||
import pytest
|
||||
from httpx import Response
|
||||
from nonebug.app import App
|
||||
import pytest
|
||||
import respx
|
||||
|
||||
from .utils import get_json
|
||||
|
||||
@@ -14,7 +14,7 @@ if typing.TYPE_CHECKING:
|
||||
@pytest.fixture
|
||||
def bili_bangumi(app: App):
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
from nonebot_bison.utils import DefaultClientManager, ProcessContext
|
||||
|
||||
return platform_manager["bilibili-bangumi"](ProcessContext(DefaultClientManager()))
|
||||
|
||||
@@ -38,7 +38,7 @@ async def test_parse_target(bili_bangumi: "BilibiliBangumi"):
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_fetch_bilibili_bangumi_status(bili_bangumi: "BilibiliBangumi", dummy_user_subinfo):
|
||||
from nonebot_bison.types import Target, SubUnit
|
||||
from nonebot_bison.types import SubUnit, Target
|
||||
|
||||
bili_bangumi_router = respx.get("https://api.bilibili.com/pgc/review/user?media_id=28235413")
|
||||
bili_bangumi_detail_router = respx.get("https://api.bilibili.com/pgc/view/web/season?season_id=39719")
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
from copy import deepcopy
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import respx
|
||||
import pytest
|
||||
from httpx import Response
|
||||
from nonebug.app import App
|
||||
import pytest
|
||||
import respx
|
||||
|
||||
from .utils import get_json
|
||||
|
||||
@@ -15,7 +15,7 @@ if TYPE_CHECKING:
|
||||
@pytest.fixture
|
||||
def bili_live(app: App):
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
from nonebot_bison.utils import DefaultClientManager, ProcessContext
|
||||
|
||||
return platform_manager["bilibili-live"](ProcessContext(DefaultClientManager()))
|
||||
|
||||
@@ -33,7 +33,7 @@ def dummy_only_open_user_subinfo(app: App):
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_fetch_bililive_no_room(bili_live, dummy_only_open_user_subinfo):
|
||||
from nonebot_bison.types import Target, SubUnit
|
||||
from nonebot_bison.types import SubUnit, Target
|
||||
|
||||
mock_bili_live_status = get_json("bili_live_status.json")
|
||||
mock_bili_live_status["data"] = {}
|
||||
@@ -53,7 +53,7 @@ async def test_fetch_bililive_no_room(bili_live, dummy_only_open_user_subinfo):
|
||||
@respx.mock
|
||||
async def test_fetch_first_live(bili_live, dummy_only_open_user_subinfo):
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import Target, SubUnit
|
||||
from nonebot_bison.types import SubUnit, Target
|
||||
|
||||
mock_bili_live_status = get_json("bili_live_status.json")
|
||||
empty_bili_live_status = deepcopy(mock_bili_live_status)
|
||||
@@ -90,7 +90,7 @@ async def test_fetch_first_live(bili_live, dummy_only_open_user_subinfo):
|
||||
@respx.mock
|
||||
async def test_fetch_bililive_only_live_open(bili_live: "Bilibililive", dummy_only_open_user_subinfo):
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import Target, SubUnit
|
||||
from nonebot_bison.types import SubUnit, Target
|
||||
|
||||
mock_bili_live_status = get_json("bili_live_status.json")
|
||||
|
||||
@@ -141,11 +141,11 @@ def dummy_only_title_user_subinfo(app: App):
|
||||
return UserSubInfo(user=user, categories=[2], tags=[])
|
||||
|
||||
|
||||
@pytest.mark.asyncio()
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_fetch_bililive_only_title_change(bili_live, dummy_only_title_user_subinfo):
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import Target, SubUnit
|
||||
from nonebot_bison.types import SubUnit, Target
|
||||
|
||||
mock_bili_live_status = get_json("bili_live_status.json")
|
||||
target = Target("13164144")
|
||||
@@ -204,7 +204,7 @@ def dummy_only_close_user_subinfo(app: App):
|
||||
@respx.mock
|
||||
async def test_fetch_bililive_only_close(bili_live, dummy_only_close_user_subinfo):
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import Target, SubUnit
|
||||
from nonebot_bison.types import SubUnit, Target
|
||||
|
||||
mock_bili_live_status = get_json("bili_live_status.json")
|
||||
target = Target("13164144")
|
||||
@@ -264,7 +264,7 @@ def dummy_bililive_user_subinfo(app: App):
|
||||
@respx.mock
|
||||
async def test_fetch_bililive_combo(bili_live, dummy_bililive_user_subinfo):
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import Target, SubUnit
|
||||
from nonebot_bison.types import SubUnit, Target
|
||||
|
||||
mock_bili_live_status = get_json("bili_live_status.json")
|
||||
target = Target("13164144")
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import respx
|
||||
import pytest
|
||||
from httpx import Response
|
||||
from nonebug.app import App
|
||||
from nonebot.compat import type_validate_python
|
||||
from nonebug.app import App
|
||||
import pytest
|
||||
import respx
|
||||
|
||||
from .utils import get_json
|
||||
|
||||
@@ -24,9 +24,9 @@ def dummy_only_open_user_subinfo(app: App):
|
||||
|
||||
@pytest.fixture
|
||||
def ceobecanteen(app: App):
|
||||
from nonebot_bison.utils import ProcessContext
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.platform.ceobecanteen.platform import CeobeCanteenClientManager
|
||||
from nonebot_bison.utils import ProcessContext
|
||||
|
||||
return platform_manager["ceobecanteen"](ProcessContext(CeobeCanteenClientManager()))
|
||||
|
||||
@@ -71,7 +71,7 @@ def ceobecanteen_cookies_1() -> dict:
|
||||
return get_json("ceobecanteen_cookies_1.json")
|
||||
|
||||
|
||||
@pytest.mark.asyncio()
|
||||
@pytest.mark.asyncio
|
||||
async def test_parse_retweet(app: App):
|
||||
from nonebot_bison.platform.ceobecanteen.models import CookiesResponse
|
||||
|
||||
@@ -79,7 +79,7 @@ async def test_parse_retweet(app: App):
|
||||
assert cookie_with_retweet.data.cookies[0].item.retweeted
|
||||
|
||||
|
||||
@pytest.mark.render()
|
||||
@pytest.mark.render
|
||||
async def test_ceobe_snapshot(app: App, ceobecanteen: "CeobeCanteen"):
|
||||
from nonebot_bison.platform.ceobecanteen.models import CeobeCookie
|
||||
|
||||
@@ -113,7 +113,7 @@ async def test_ceobe_snapshot(app: App, ceobecanteen: "CeobeCanteen"):
|
||||
|
||||
|
||||
@pytest.mark.skip("极限测试, 不在CI中运行")
|
||||
@pytest.mark.asyncio()
|
||||
@pytest.mark.asyncio
|
||||
async def test_parse_crazy(app: App, ceobecanteen):
|
||||
from nonebot_plugin_saa import Image
|
||||
|
||||
@@ -139,7 +139,7 @@ async def test_parse_crazy(app: App, ceobecanteen):
|
||||
show(ext((await post4.generate_messages())[0][0])) # type: ignore
|
||||
|
||||
|
||||
@pytest.mark.asyncio()
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_batch_fetch_new_with_single(
|
||||
app: App,
|
||||
@@ -220,7 +220,7 @@ async def test_batch_fetch_new_with_single(
|
||||
await post3.generate_messages()
|
||||
|
||||
|
||||
@pytest.mark.asyncio()
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_parse_target_fuzzy(app: App, ceobecanteen: "CeobeCanteen", dummy_target, ceobecanteen_targets):
|
||||
from nonebot_bison.platform.ceobecanteen import CeobeCanteen
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import respx
|
||||
import pytest
|
||||
from httpx import Response
|
||||
from nonebug.app import App
|
||||
import pytest
|
||||
import respx
|
||||
|
||||
from .utils import get_json
|
||||
|
||||
@@ -9,7 +9,7 @@ from .utils import get_json
|
||||
@pytest.fixture
|
||||
def ff14(app: App):
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
from nonebot_bison.utils import DefaultClientManager, ProcessContext
|
||||
|
||||
return platform_manager["ff14"](ProcessContext(DefaultClientManager()))
|
||||
|
||||
@@ -28,7 +28,7 @@ def ff14_newdata_json_1():
|
||||
@respx.mock
|
||||
async def test_fetch_new(ff14, dummy_user_subinfo, ff14_newdata_json_0, ff14_newdata_json_1):
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import Target, SubUnit
|
||||
from nonebot_bison.types import SubUnit, Target
|
||||
|
||||
newdata = respx.get(
|
||||
"https://cqnews.web.sdo.com/api/news/newsList?gameCode=ff&CategoryCode=5309,5310,5311,5312,5313&pageIndex=0&pageSize=5"
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import time
|
||||
import typing
|
||||
|
||||
import respx
|
||||
import pytest
|
||||
from httpx import Response
|
||||
from nonebug.app import App
|
||||
import pytest
|
||||
import respx
|
||||
|
||||
from .utils import get_json
|
||||
|
||||
@@ -15,7 +15,7 @@ if typing.TYPE_CHECKING:
|
||||
@pytest.fixture
|
||||
def ncm_artist(app: App):
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
from nonebot_bison.utils import DefaultClientManager, ProcessContext
|
||||
|
||||
return platform_manager["ncm-artist"](ProcessContext(DefaultClientManager()))
|
||||
|
||||
@@ -41,7 +41,7 @@ def ncm_artist_1(ncm_artist_raw: dict):
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_fetch_new(ncm_artist, ncm_artist_0, ncm_artist_1, dummy_user_subinfo):
|
||||
from nonebot_bison.types import Target, SubUnit
|
||||
from nonebot_bison.types import SubUnit, Target
|
||||
|
||||
ncm_router = respx.get("https://music.163.com/api/artist/albums/32540734")
|
||||
ncm_router.mock(return_value=Response(200, json=ncm_artist_0))
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import time
|
||||
import typing
|
||||
|
||||
import respx
|
||||
import pytest
|
||||
from httpx import Response
|
||||
from nonebug.app import App
|
||||
import pytest
|
||||
import respx
|
||||
|
||||
from .utils import get_json
|
||||
|
||||
@@ -15,7 +15,7 @@ if typing.TYPE_CHECKING:
|
||||
@pytest.fixture
|
||||
def ncm_radio(app: App):
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
from nonebot_bison.utils import DefaultClientManager, ProcessContext
|
||||
|
||||
return platform_manager["ncm-radio"](ProcessContext(DefaultClientManager()))
|
||||
|
||||
@@ -42,7 +42,7 @@ def ncm_radio_1(ncm_radio_raw: dict):
|
||||
@respx.mock
|
||||
async def test_fetch_new(ncm_radio, ncm_radio_0, ncm_radio_1, dummy_user_subinfo):
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import Target, SubUnit
|
||||
from nonebot_bison.types import SubUnit, Target
|
||||
|
||||
ncm_router = respx.post("http://music.163.com/api/dj/program/byradio")
|
||||
ncm_router.mock(return_value=Response(200, json=ncm_radio_0))
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
from time import time
|
||||
from typing import Any
|
||||
from typing import Any, ClassVar
|
||||
|
||||
import pytest
|
||||
from nonebug.app import App
|
||||
import pytest
|
||||
|
||||
now = time()
|
||||
passed = now - 3 * 60 * 60
|
||||
|
||||
raw_post_list_1 = [{"id": 1, "text": "p1", "date": now, "tags": ["tag1"], "category": 1}]
|
||||
|
||||
raw_post_list_2 = raw_post_list_1 + [
|
||||
raw_post_list_2 = [
|
||||
*raw_post_list_1,
|
||||
{"id": 2, "text": "p2", "date": now, "tags": ["tag1"], "category": 1},
|
||||
{"id": 3, "text": "p3", "date": now, "tags": ["tag2"], "category": 2},
|
||||
{"id": 4, "text": "p4", "date": now, "tags": ["tag2"], "category": 3},
|
||||
@@ -36,9 +37,9 @@ def user_info_factory(app: App, dummy_user):
|
||||
|
||||
@pytest.fixture
|
||||
def mock_platform_without_cats_tags(app: App):
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import Target, RawPost
|
||||
from nonebot_bison.platform.platform import NewMessage
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import RawPost, Target
|
||||
|
||||
class MockPlatform(NewMessage):
|
||||
platform_name = "mock_platform"
|
||||
@@ -47,7 +48,7 @@ def mock_platform_without_cats_tags(app: App):
|
||||
is_common = True
|
||||
schedule_interval = 10
|
||||
enable_tag = False
|
||||
categories = {}
|
||||
categories: ClassVar[dict] = {}
|
||||
has_target = True
|
||||
|
||||
sub_index = 0
|
||||
@@ -83,15 +84,15 @@ def mock_platform_without_cats_tags(app: App):
|
||||
|
||||
@pytest.fixture
|
||||
def mock_platform(app: App):
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.utils import Site
|
||||
from nonebot_bison.platform.platform import NewMessage
|
||||
from nonebot_bison.types import Tag, Target, RawPost, Category
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import Category, RawPost, Tag, Target
|
||||
from nonebot_bison.utils import Site
|
||||
|
||||
class MockSite(Site):
|
||||
name = "mock_site"
|
||||
schedule_type = "interval"
|
||||
schedule_setting = {"seconds": 100}
|
||||
schedule_setting: ClassVar[dict] = {"seconds": 100}
|
||||
|
||||
class MockPlatform(NewMessage):
|
||||
platform_name = "mock_platform"
|
||||
@@ -101,7 +102,7 @@ def mock_platform(app: App):
|
||||
enable_tag = True
|
||||
has_target = True
|
||||
site = MockSite
|
||||
categories = {
|
||||
categories: ClassVar[dict] = {
|
||||
Category(1): "转发",
|
||||
Category(2): "视频",
|
||||
}
|
||||
@@ -150,16 +151,16 @@ def mock_site(app):
|
||||
class MockSite(Site):
|
||||
name = "mock_site"
|
||||
schedule_type = "interval"
|
||||
schedule_setting = {"seconds": 100}
|
||||
schedule_setting: ClassVar[dict] = {"seconds": 100}
|
||||
|
||||
return MockSite
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_platform_no_target(app: App, mock_site):
|
||||
from nonebot_bison.platform.platform import CategoryNotSupport, NewMessage
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import Tag, Target, RawPost, Category
|
||||
from nonebot_bison.platform.platform import NewMessage, CategoryNotSupport
|
||||
from nonebot_bison.types import Category, RawPost, Tag, Target
|
||||
|
||||
class MockPlatform(NewMessage):
|
||||
platform_name = "mock_platform"
|
||||
@@ -169,7 +170,7 @@ def mock_platform_no_target(app: App, mock_site):
|
||||
site = mock_site
|
||||
enable_tag = True
|
||||
has_target = False
|
||||
categories = {Category(1): "转发", Category(2): "视频", Category(3): "不支持"}
|
||||
categories: ClassVar[dict] = {Category(1): "转发", Category(2): "视频", Category(3): "不支持"}
|
||||
|
||||
sub_index = 0
|
||||
|
||||
@@ -212,9 +213,9 @@ def mock_platform_no_target(app: App, mock_site):
|
||||
|
||||
@pytest.fixture
|
||||
def mock_platform_no_target_2(app: App, mock_site):
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.platform.platform import NewMessage
|
||||
from nonebot_bison.types import Tag, Target, RawPost, Category
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import Category, RawPost, Tag, Target
|
||||
|
||||
class MockPlatform(NewMessage):
|
||||
platform_name = "mock_platform"
|
||||
@@ -224,7 +225,7 @@ def mock_platform_no_target_2(app: App, mock_site):
|
||||
is_common = True
|
||||
enable_tag = True
|
||||
has_target = False
|
||||
categories = {
|
||||
categories: ClassVar[dict] = {
|
||||
Category(4): "leixing4",
|
||||
Category(5): "leixing5",
|
||||
}
|
||||
@@ -259,7 +260,8 @@ def mock_platform_no_target_2(app: App, mock_site):
|
||||
async def get_sub_list(cls, _: "Target"):
|
||||
list_1 = [{"id": 5, "text": "p5", "date": now, "tags": ["tag1"], "category": 4}]
|
||||
|
||||
list_2 = list_1 + [
|
||||
list_2 = [
|
||||
*list_1,
|
||||
{"id": 6, "text": "p6", "date": now, "tags": ["tag1"], "category": 4},
|
||||
{"id": 7, "text": "p7", "date": now, "tags": ["tag2"], "category": 5},
|
||||
]
|
||||
@@ -274,9 +276,9 @@ def mock_platform_no_target_2(app: App, mock_site):
|
||||
|
||||
@pytest.fixture
|
||||
def mock_status_change(app: App):
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.platform.platform import StatusChange
|
||||
from nonebot_bison.types import Target, RawPost, Category
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import Category, RawPost, Target
|
||||
|
||||
class MockPlatform(StatusChange):
|
||||
platform_name = "mock_platform"
|
||||
@@ -285,9 +287,9 @@ def mock_status_change(app: App):
|
||||
is_common = True
|
||||
enable_tag = False
|
||||
schedule_type = "interval"
|
||||
schedule_kw = {"seconds": 10}
|
||||
schedule_kw: ClassVar[dict] = {"seconds": 10}
|
||||
has_target = False
|
||||
categories = {
|
||||
categories: ClassVar[dict] = {
|
||||
Category(1): "转发",
|
||||
Category(2): "视频",
|
||||
}
|
||||
@@ -323,8 +325,8 @@ def mock_status_change(app: App):
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_new_message_target_without_cats_tags(mock_platform_without_cats_tags, user_info_factory):
|
||||
from nonebot_bison.types import Target, SubUnit
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
from nonebot_bison.types import SubUnit, Target
|
||||
from nonebot_bison.utils import DefaultClientManager, ProcessContext
|
||||
|
||||
res1 = await mock_platform_without_cats_tags(ProcessContext(DefaultClientManager())).fetch_new_post(
|
||||
SubUnit(Target("dummy"), [user_info_factory([1, 2], [])])
|
||||
@@ -344,8 +346,8 @@ async def test_new_message_target_without_cats_tags(mock_platform_without_cats_t
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_new_message_target(mock_platform, user_info_factory):
|
||||
from nonebot_bison.types import Target, SubUnit
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
from nonebot_bison.types import SubUnit, Target
|
||||
from nonebot_bison.utils import DefaultClientManager, ProcessContext
|
||||
|
||||
res1 = await mock_platform(ProcessContext(DefaultClientManager())).fetch_new_post(
|
||||
SubUnit(Target("dummy"), [user_info_factory([1, 2], [])])
|
||||
@@ -379,8 +381,8 @@ async def test_new_message_target(mock_platform, user_info_factory):
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_new_message_no_target(mock_platform_no_target, user_info_factory):
|
||||
from nonebot_bison.types import Target, SubUnit
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
from nonebot_bison.types import SubUnit, Target
|
||||
from nonebot_bison.utils import DefaultClientManager, ProcessContext
|
||||
|
||||
res1 = await mock_platform_no_target(ProcessContext(DefaultClientManager())).fetch_new_post(
|
||||
SubUnit(Target("dummy"), [user_info_factory([1, 2], [])])
|
||||
@@ -418,8 +420,8 @@ async def test_new_message_no_target(mock_platform_no_target, user_info_factory)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_status_change(mock_status_change, user_info_factory):
|
||||
from nonebot_bison.types import Target, SubUnit
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
from nonebot_bison.types import SubUnit, Target
|
||||
from nonebot_bison.utils import DefaultClientManager, ProcessContext
|
||||
|
||||
res1 = await mock_status_change(ProcessContext(DefaultClientManager())).fetch_new_post(
|
||||
SubUnit(Target("dummy"), [user_info_factory([1, 2], [])])
|
||||
@@ -458,9 +460,9 @@ async def test_group(
|
||||
mock_platform_no_target_2,
|
||||
user_info_factory,
|
||||
):
|
||||
from nonebot_bison.types import Target, SubUnit
|
||||
from nonebot_bison.platform.platform import make_no_target_group
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
from nonebot_bison.types import SubUnit, Target
|
||||
from nonebot_bison.utils import DefaultClientManager, ProcessContext
|
||||
|
||||
dummy = Target("dummy")
|
||||
|
||||
@@ -482,11 +484,11 @@ async def test_group(
|
||||
async def test_batch_fetch_new_message(app: App):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.utils import DefaultClientManager
|
||||
from nonebot_bison.platform.platform import NewMessage
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import RawPost, SubUnit, Target, UserSubInfo
|
||||
from nonebot_bison.utils import DefaultClientManager
|
||||
from nonebot_bison.utils.context import ProcessContext
|
||||
from nonebot_bison.types import Target, RawPost, SubUnit, UserSubInfo
|
||||
|
||||
class BatchNewMessage(NewMessage):
|
||||
platform_name = "mock_platform"
|
||||
@@ -495,7 +497,7 @@ async def test_batch_fetch_new_message(app: App):
|
||||
is_common = True
|
||||
schedule_interval = 10
|
||||
enable_tag = False
|
||||
categories = {}
|
||||
categories: ClassVar[dict] = {}
|
||||
has_target = True
|
||||
|
||||
sub_index = 0
|
||||
@@ -569,11 +571,11 @@ async def test_batch_fetch_new_message(app: App):
|
||||
async def test_batch_fetch_compare_status(app: App):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
from nonebot_bison.platform.platform import StatusChange
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import Category, RawPost, SubUnit, Target, UserSubInfo
|
||||
from nonebot_bison.utils import DefaultClientManager
|
||||
from nonebot_bison.utils.context import ProcessContext
|
||||
from nonebot_bison.platform.platform import StatusChange
|
||||
from nonebot_bison.types import Target, RawPost, SubUnit, Category, UserSubInfo
|
||||
|
||||
class BatchStatusChange(StatusChange):
|
||||
platform_name = "mock_platform"
|
||||
@@ -582,9 +584,9 @@ async def test_batch_fetch_compare_status(app: App):
|
||||
is_common = True
|
||||
enable_tag = False
|
||||
schedule_type = "interval"
|
||||
schedule_kw = {"seconds": 10}
|
||||
schedule_kw: ClassVar[dict] = {"seconds": 10}
|
||||
has_target = True
|
||||
categories = {
|
||||
categories: ClassVar[dict] = {
|
||||
Category(1): "转发",
|
||||
Category(2): "视频",
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import pytest
|
||||
from nonebug.app import App
|
||||
import pytest
|
||||
|
||||
from .utils import get_json
|
||||
|
||||
@@ -13,7 +13,7 @@ def test_cases():
|
||||
@pytest.mark.asyncio
|
||||
async def test_filter_user_custom_tag(app: App, test_cases):
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
from nonebot_bison.utils import DefaultClientManager, ProcessContext
|
||||
|
||||
bilibili = platform_manager["bilibili"](ProcessContext(DefaultClientManager()))
|
||||
for case in test_cases:
|
||||
@@ -25,7 +25,7 @@ async def test_filter_user_custom_tag(app: App, test_cases):
|
||||
@pytest.mark.asyncio
|
||||
async def test_tag_separator(app: App):
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
from nonebot_bison.utils import DefaultClientManager, ProcessContext
|
||||
|
||||
bilibili = platform_manager["bilibili"](ProcessContext(DefaultClientManager()))
|
||||
tags = ["~111", "222", "333", "~444", "555"]
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import typing
|
||||
from datetime import datetime
|
||||
import typing
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
import pytz
|
||||
import respx
|
||||
import pytest
|
||||
from httpx import Response
|
||||
from nonebug.app import App
|
||||
import pytest
|
||||
import pytz
|
||||
import respx
|
||||
|
||||
from .utils import get_file
|
||||
|
||||
@@ -35,7 +35,7 @@ def user_info_factory(app: App, dummy_user):
|
||||
@pytest.fixture
|
||||
def rss(app: App):
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
from nonebot_bison.utils import DefaultClientManager, ProcessContext
|
||||
|
||||
return platform_manager["rss"](ProcessContext(DefaultClientManager()))
|
||||
|
||||
@@ -71,7 +71,7 @@ async def test_fetch_new_1(
|
||||
user_info_factory,
|
||||
update_time_feed_1,
|
||||
):
|
||||
from nonebot_bison.types import Target, SubUnit
|
||||
from nonebot_bison.types import SubUnit, Target
|
||||
|
||||
## 标题重复的情况
|
||||
rss_router = respx.get("https://rsshub.app/twitter/user/ArknightsStaff")
|
||||
@@ -113,7 +113,7 @@ async def test_fetch_new_2(
|
||||
user_info_factory,
|
||||
update_time_feed_2,
|
||||
):
|
||||
from nonebot_bison.types import Target, SubUnit
|
||||
from nonebot_bison.types import SubUnit, Target
|
||||
|
||||
## 标题与正文不重复的情况
|
||||
rss_router = respx.get("https://www.ruanyifeng.com/blog/atom.xml")
|
||||
@@ -148,7 +148,7 @@ async def test_fetch_new_3(
|
||||
user_info_factory,
|
||||
update_time_feed_3,
|
||||
):
|
||||
from nonebot_bison.types import Target, SubUnit
|
||||
from nonebot_bison.types import SubUnit, Target
|
||||
|
||||
## 只有<updated>没有<published>
|
||||
rss_router = respx.get("https://github.com/R3nzTheCodeGOD/R3nzSkin/releases.atom")
|
||||
@@ -172,7 +172,7 @@ async def test_fetch_new_4(
|
||||
rss,
|
||||
user_info_factory,
|
||||
):
|
||||
from nonebot_bison.types import Target, SubUnit
|
||||
from nonebot_bison.types import SubUnit, Target
|
||||
|
||||
## 没有日期信息的情况
|
||||
rss_router = respx.get("https://rsshub.app/wallhaven/hot?limit=5")
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import typing
|
||||
from datetime import datetime
|
||||
import typing
|
||||
|
||||
import respx
|
||||
import pytest
|
||||
import feedparser
|
||||
from pytz import timezone
|
||||
from httpx import AsyncClient, Response
|
||||
from nonebug.app import App
|
||||
from httpx import Response, AsyncClient
|
||||
import pytest
|
||||
from pytz import timezone
|
||||
import respx
|
||||
|
||||
from .utils import get_file, get_json
|
||||
|
||||
@@ -19,7 +19,7 @@ image_cdn_router = respx.route(host__regex=r"wx\d.sinaimg.cn", path__startswith=
|
||||
@pytest.fixture
|
||||
def weibo(app: App):
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
from nonebot_bison.utils import DefaultClientManager, ProcessContext
|
||||
|
||||
return platform_manager["weibo"](ProcessContext(DefaultClientManager()))
|
||||
|
||||
@@ -42,7 +42,7 @@ async def test_get_name(weibo):
|
||||
@respx.mock
|
||||
async def test_fetch_new(weibo, dummy_user_subinfo):
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import Target, SubUnit
|
||||
from nonebot_bison.types import SubUnit, Target
|
||||
|
||||
ak_list_router = respx.get("https://m.weibo.cn/api/container/getIndex?containerid=1076036279793937")
|
||||
detail_router = respx.get("https://m.weibo.cn/statuses/extend?id=4649031014551911")
|
||||
@@ -184,7 +184,7 @@ async def test_rsshub_compare(weibo):
|
||||
|
||||
test_post = {
|
||||
"mblog": {
|
||||
"text": ( # noqa
|
||||
"text": (
|
||||
'<a href="https://m.weibo.cn/search?containerid=231522type%3D1%26t%3D10%26q%3D%23%E5%88%9A%E5%87%BA%E7%94%9F%E7%9A%84%E5%B0%8F%E7%BE%8A%E9%A9%BC%E9%95%BF%E5%95%A5%E6%A0%B7%23&extparam=%23%E5%88%9A%E5%87%BA%E7%94%9F%E7%9A%84%E5%B0%8F%E7%BE%8A%E9%A9%BC%E9%95%BF%E5%95%A5%E6%A0%B7%23&luicode=10000011&lfid=1076036003966749"'
|
||||
' data-hide=""><span class="surl-text">#刚出生的小羊驼长啥样#</span></a> <br />小羊驼三三来也<span'
|
||||
' class="url-icon"><img alt=[好喜欢]'
|
||||
|
||||
+14
-13
@@ -1,9 +1,9 @@
|
||||
from time import time
|
||||
from typing import Any
|
||||
from inspect import cleandoc
|
||||
from time import time
|
||||
from typing import Any, ClassVar
|
||||
|
||||
import pytest
|
||||
from nonebug.app import App
|
||||
import pytest
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
now = time()
|
||||
@@ -11,7 +11,8 @@ passed = now - 3 * 60 * 60
|
||||
|
||||
raw_post_list_1 = [{"id": 1, "text": "p1", "date": now, "tags": ["tag1"], "category": 1}]
|
||||
|
||||
raw_post_list_2 = raw_post_list_1 + [
|
||||
raw_post_list_2 = [
|
||||
*raw_post_list_1,
|
||||
{"id": 2, "text": "p2", "date": now, "tags": ["tag1"], "category": 1},
|
||||
{"id": 3, "text": "p3", "date": now, "tags": ["tag2"], "category": 2},
|
||||
{"id": 4, "text": "p4", "date": now, "tags": ["tag2"], "category": 3},
|
||||
@@ -20,9 +21,9 @@ raw_post_list_2 = raw_post_list_1 + [
|
||||
|
||||
@pytest.fixture
|
||||
def mock_platform(app: App):
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import Target, RawPost
|
||||
from nonebot_bison.platform.platform import NewMessage
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import RawPost, Target
|
||||
|
||||
class MockPlatform(NewMessage):
|
||||
platform_name = "mock-platform"
|
||||
@@ -31,7 +32,7 @@ def mock_platform(app: App):
|
||||
is_common = True
|
||||
schedule_interval = 10
|
||||
enable_tag = False
|
||||
categories = {}
|
||||
categories: ClassVar[dict] = {}
|
||||
has_target = True
|
||||
|
||||
sub_index = 0
|
||||
@@ -109,7 +110,7 @@ Vero hendrerit vero diam et lorem blandit ex diam ex...
|
||||
- nickname: 'Mock'
|
||||
- description: 'Labore amet ut invidunt dolor consectetuer ipsum sadipscing sed minim diam rebum justo tincidunt.'
|
||||
"""
|
||||
) # noqa: E501
|
||||
)
|
||||
|
||||
post2_content = cleandoc(
|
||||
"Rebum delenit iusto augue in rebum sanctus diam stet clita voluptua amet tempor sea in.\n"
|
||||
@@ -176,11 +177,11 @@ Vero hendrerit vero diam et lorem blandit ex diam ex...
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_generate_msg(mock_platform, mocker: MockerFixture):
|
||||
from nonebot_plugin_saa import Text, Image
|
||||
from nonebot_plugin_saa import Image, Text
|
||||
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.plugin_config import plugin_config
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.utils import DefaultClientManager, ProcessContext
|
||||
|
||||
post: Post = await mock_platform(ProcessContext(DefaultClientManager())).parse(raw_post_list_1[0])
|
||||
assert post.platform.default_theme == "basic"
|
||||
@@ -208,9 +209,9 @@ async def test_generate_msg(mock_platform, mocker: MockerFixture):
|
||||
async def test_msg_segments_convert(mock_platform, mocker: MockerFixture):
|
||||
from nonebot_plugin_saa import Image
|
||||
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.plugin_config import plugin_config
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.utils import DefaultClientManager, ProcessContext
|
||||
|
||||
mocker.patch.object(plugin_config, "bison_use_pic", True)
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import typing
|
||||
from datetime import time
|
||||
import typing
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from nonebug import App
|
||||
@@ -28,10 +28,10 @@ async def test_scheduler_without_time(init_scheduler):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
from nonebot_bison.config import config
|
||||
from nonebot_bison.platform.ncm import NcmSite
|
||||
from nonebot_bison.types import Target as T_Target
|
||||
from nonebot_bison.config.db_config import WeightConfig
|
||||
from nonebot_bison.platform.ncm import NcmSite
|
||||
from nonebot_bison.scheduler.manager import init_scheduler
|
||||
from nonebot_bison.types import Target as T_Target
|
||||
|
||||
await config.add_subscribe(TargetQQGroup(group_id=123), T_Target("t1"), "target1", "ncm-artist", [], [])
|
||||
await config.add_subscribe(TargetQQGroup(group_id=123), T_Target("t2"), "target1", "ncm-artist", [], [])
|
||||
@@ -57,12 +57,12 @@ async def test_scheduler_batch_api(init_scheduler, mocker: MockerFixture):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
from nonebot_bison.config import config
|
||||
from nonebot_bison.types import UserSubInfo
|
||||
from nonebot_bison.scheduler import scheduler_dict
|
||||
from nonebot_bison.types import Target as T_Target
|
||||
from nonebot_bison.utils import DefaultClientManager
|
||||
from nonebot_bison.platform.bilibili import BililiveSite
|
||||
from nonebot_bison.scheduler import scheduler_dict
|
||||
from nonebot_bison.scheduler.manager import init_scheduler
|
||||
from nonebot_bison.types import Target as T_Target
|
||||
from nonebot_bison.types import UserSubInfo
|
||||
from nonebot_bison.utils import DefaultClientManager
|
||||
|
||||
await config.add_subscribe(TargetQQGroup(group_id=123), T_Target("t1"), "target1", "bilibili-live", [], [])
|
||||
await config.add_subscribe(TargetQQGroup(group_id=123), T_Target("t2"), "target2", "bilibili-live", [], [])
|
||||
@@ -96,11 +96,11 @@ async def test_scheduler_batch_api(init_scheduler, mocker: MockerFixture):
|
||||
async def test_scheduler_with_time(app: App, init_scheduler, mocker: MockerFixture):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
from nonebot_bison.platform.ncm import NcmSite
|
||||
from nonebot_bison.config import config, db_config
|
||||
from nonebot_bison.types import Target as T_Target
|
||||
from nonebot_bison.config.db_config import TimeWeightConfig, WeightConfig
|
||||
from nonebot_bison.platform.ncm import NcmSite
|
||||
from nonebot_bison.scheduler.manager import init_scheduler
|
||||
from nonebot_bison.config.db_config import WeightConfig, TimeWeightConfig
|
||||
from nonebot_bison.types import Target as T_Target
|
||||
|
||||
await config.add_subscribe(TargetQQGroup(group_id=123), T_Target("t1"), "target1", "ncm-artist", [], [])
|
||||
await config.add_subscribe(TargetQQGroup(group_id=123), T_Target("t2"), "target1", "ncm-artist", [], [])
|
||||
@@ -140,9 +140,9 @@ async def test_scheduler_add_new(init_scheduler):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
from nonebot_bison.config import config
|
||||
from nonebot_bison.types import Target as T_Target
|
||||
from nonebot_bison.platform.bilibili import BilibiliSite
|
||||
from nonebot_bison.scheduler.manager import init_scheduler
|
||||
from nonebot_bison.types import Target as T_Target
|
||||
|
||||
await config.add_subscribe(TargetQQGroup(group_id=123), T_Target("t1"), "target1", "bilibili", [], [])
|
||||
|
||||
@@ -158,9 +158,9 @@ async def test_schedule_delete(init_scheduler):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
from nonebot_bison.config import config
|
||||
from nonebot_bison.types import Target as T_Target
|
||||
from nonebot_bison.platform.bilibili import BilibiliSite
|
||||
from nonebot_bison.scheduler.manager import init_scheduler
|
||||
from nonebot_bison.types import Target as T_Target
|
||||
|
||||
await config.add_subscribe(TargetQQGroup(group_id=123), T_Target("t1"), "target1", "bilibili", [], [])
|
||||
await config.add_subscribe(TargetQQGroup(group_id=123), T_Target("t2"), "target1", "bilibili", [], [])
|
||||
@@ -177,18 +177,18 @@ async def test_schedule_delete(init_scheduler):
|
||||
|
||||
|
||||
async def test_scheduler_skip_browser(mocker: MockerFixture):
|
||||
from nonebot_bison.scheduler.scheduler import Site
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.plugin_config import plugin_config
|
||||
from nonebot_bison.platform.platform import NewMessage
|
||||
from nonebot_bison.plugin_config import plugin_config
|
||||
from nonebot_bison.scheduler import init_scheduler, scheduler_dict
|
||||
from nonebot_bison.scheduler.scheduler import Site
|
||||
|
||||
mocker.patch.object(plugin_config, "bison_use_browser", False)
|
||||
|
||||
class MockSite(Site):
|
||||
name = "mock_site"
|
||||
schedule_type = "interval"
|
||||
schedule_setting = {"seconds": 100}
|
||||
schedule_setting: typing.ClassVar[dict] = {"seconds": 100}
|
||||
require_browser = True
|
||||
|
||||
class MockPlatform(NewMessage):
|
||||
@@ -209,18 +209,18 @@ async def test_scheduler_skip_browser(mocker: MockerFixture):
|
||||
|
||||
|
||||
async def test_scheduler_no_skip_not_require_browser(mocker: MockerFixture):
|
||||
from nonebot_bison.scheduler.scheduler import Site
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.plugin_config import plugin_config
|
||||
from nonebot_bison.platform.platform import NewMessage
|
||||
from nonebot_bison.plugin_config import plugin_config
|
||||
from nonebot_bison.scheduler import init_scheduler, scheduler_dict
|
||||
from nonebot_bison.scheduler.scheduler import Site
|
||||
|
||||
mocker.patch.object(plugin_config, "bison_use_browser", False)
|
||||
|
||||
class MockSite(Site):
|
||||
name = "mock_site"
|
||||
schedule_type = "interval"
|
||||
schedule_setting = {"seconds": 100}
|
||||
schedule_setting: typing.ClassVar[dict] = {"seconds": 100}
|
||||
|
||||
class MockPlatform(NewMessage):
|
||||
platform_name = "mock_platform"
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import respx
|
||||
import pytest
|
||||
from httpx import Response
|
||||
from nonebug.app import App
|
||||
from nonebug_saa import should_send_saa
|
||||
import pytest
|
||||
import respx
|
||||
|
||||
from ..platforms.utils import get_json
|
||||
from ..utils import BotReply, fake_admin_user, fake_group_message_event
|
||||
from tests.platforms.utils import get_json
|
||||
from tests.utils import BotReply, fake_admin_user, fake_group_message_event
|
||||
|
||||
|
||||
# 选择platform阶段中止
|
||||
@@ -55,8 +55,8 @@ async def test_abort_add_on_id(app: App, init_scheduler):
|
||||
from nonebot.adapters.onebot.v11.event import Sender
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
|
||||
from nonebot_bison.platform.weibo import Weibo
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.platform.weibo import Weibo
|
||||
from nonebot_bison.sub_manager import add_sub_matcher, common_platform
|
||||
|
||||
ak_list_router = respx.get("https://m.weibo.cn/api/container/getIndex?containerid=1005056279793937")
|
||||
@@ -103,8 +103,8 @@ async def test_abort_add_on_cats(app: App, init_scheduler):
|
||||
from nonebot.adapters.onebot.v11.event import Sender
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
|
||||
from nonebot_bison.platform.weibo import Weibo
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.platform.weibo import Weibo
|
||||
from nonebot_bison.sub_manager import add_sub_matcher, common_platform
|
||||
|
||||
ak_list_router = respx.get("https://m.weibo.cn/api/container/getIndex?containerid=1005056279793937")
|
||||
@@ -163,8 +163,8 @@ async def test_abort_add_on_tag(app: App, init_scheduler):
|
||||
from nonebot.adapters.onebot.v11.event import Sender
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
|
||||
from nonebot_bison.platform.weibo import Weibo
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.platform.weibo import Weibo
|
||||
from nonebot_bison.sub_manager import add_sub_matcher, common_platform
|
||||
|
||||
ak_list_router = respx.get("https://m.weibo.cn/api/container/getIndex?containerid=1005056279793937")
|
||||
@@ -224,12 +224,12 @@ async def test_abort_add_on_tag(app: App, init_scheduler):
|
||||
async def test_abort_del_sub(app: App, init_scheduler):
|
||||
from nonebot.adapters.onebot.v11.bot import Bot
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
from nonebot_plugin_saa import TargetQQGroup, MessageFactory
|
||||
from nonebot_plugin_saa import MessageFactory, TargetQQGroup
|
||||
|
||||
from nonebot_bison.config import config
|
||||
from nonebot_bison.types import Target as T_Target
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.sub_manager import del_sub_matcher
|
||||
from nonebot_bison.types import Target as T_Target
|
||||
|
||||
await config.add_subscribe(
|
||||
TargetQQGroup(group_id=10000),
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import respx
|
||||
import pytest
|
||||
from httpx import Response
|
||||
from nonebug.app import App
|
||||
from pytest_mock import MockerFixture
|
||||
from nonebug_saa import should_send_saa
|
||||
import pytest
|
||||
from pytest_mock import MockerFixture
|
||||
import respx
|
||||
|
||||
from ..platforms.utils import get_json
|
||||
from ..utils import BotReply, fake_admin_user, fake_group_message_event, add_reply_on_id_input_search
|
||||
from tests.platforms.utils import get_json
|
||||
from tests.utils import BotReply, add_reply_on_id_input_search, fake_admin_user, fake_group_message_event
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -61,13 +61,13 @@ async def test_configurable_at_me_false(app: App, mocker: MockerFixture):
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_add_with_target(app: App, init_scheduler):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
from nonebot.adapters.onebot.v11.event import Sender
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
from nonebot_bison.config import config
|
||||
from nonebot_bison.platform.weibo import Weibo
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.platform.weibo import Weibo
|
||||
from nonebot_bison.sub_manager import add_sub_matcher, common_platform
|
||||
|
||||
ak_list_router = respx.get("https://m.weibo.cn/api/container/getIndex?containerid=1005056279793937")
|
||||
@@ -142,8 +142,9 @@ async def test_add_with_target(app: App, init_scheduler):
|
||||
sub = subs[0]
|
||||
assert sub.target.target == "6279793937"
|
||||
assert sub.tags == []
|
||||
assert sub.categories == [platform_manager["weibo"].reverse_category["图文"]] + [
|
||||
platform_manager["weibo"].reverse_category["文字"]
|
||||
assert sub.categories == [
|
||||
platform_manager["weibo"].reverse_category["图文"],
|
||||
platform_manager["weibo"].reverse_category["文字"],
|
||||
]
|
||||
assert sub.target.platform_name == "weibo"
|
||||
assert sub.target.target_name == "明日方舟Arknights"
|
||||
@@ -152,13 +153,13 @@ async def test_add_with_target(app: App, init_scheduler):
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_add_with_target_no_cat(app: App, init_scheduler):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
from nonebot.adapters.onebot.v11.event import Sender
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
from nonebot_bison.config import config
|
||||
from nonebot_bison.platform.ncm import NcmArtist
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.platform.ncm import NcmArtist
|
||||
from nonebot_bison.sub_manager import add_sub_matcher, common_platform
|
||||
|
||||
ncm_router = respx.get("https://music.163.com/api/artist/albums/32540734")
|
||||
@@ -207,9 +208,9 @@ async def test_add_with_target_no_cat(app: App, init_scheduler):
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_add_no_target(app: App, init_scheduler):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
from nonebot.adapters.onebot.v11.event import Sender
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
from nonebot_bison.config import config
|
||||
from nonebot_bison.platform import platform_manager
|
||||
@@ -290,11 +291,11 @@ async def test_platform_name_err(app: App):
|
||||
async def test_add_with_get_id(app: App):
|
||||
from nonebot.adapters.onebot.v11.event import Sender
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
from nonebot_plugin_saa import Text, TargetQQGroup, MessageFactory, SupportedAdapters
|
||||
from nonebot_plugin_saa import MessageFactory, SupportedAdapters, TargetQQGroup, Text
|
||||
|
||||
from nonebot_bison.config import config
|
||||
from nonebot_bison.platform.weibo import Weibo
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.platform.weibo import Weibo
|
||||
from nonebot_bison.sub_manager import add_sub_matcher, common_platform
|
||||
|
||||
ak_list_router = respx.get("https://m.weibo.cn/api/container/getIndex?containerid=1005056279793937")
|
||||
@@ -356,9 +357,9 @@ async def test_add_with_get_id(app: App):
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_add_with_bilibili_target_parser(app: App, init_scheduler):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
from nonebot.adapters.onebot.v11.event import Sender
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
from nonebot_bison.config import config
|
||||
from nonebot_bison.platform import platform_manager
|
||||
@@ -470,9 +471,9 @@ async def test_add_with_bilibili_target_parser(app: App, init_scheduler):
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_add_with_bilibili_live_target_parser(app: App, init_scheduler):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
from nonebot.adapters.onebot.v11.event import Sender
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
from nonebot_bison.config import config
|
||||
from nonebot_bison.platform import platform_manager
|
||||
@@ -549,9 +550,9 @@ async def test_add_with_bilibili_live_target_parser(app: App, init_scheduler):
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_add_with_bilibili_bangumi_target_parser(app: App, init_scheduler):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
from nonebot.adapters.onebot.v11.event import Sender
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
from nonebot_bison.config import config
|
||||
from nonebot_bison.platform import platform_manager
|
||||
@@ -622,9 +623,9 @@ async def test_subscribe_platform_requires_browser(app: App, mocker: MockerFixtu
|
||||
from nonebot.adapters.onebot.v11.event import Sender
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
|
||||
from nonebot_bison.platform import platform_manager, unavailable_paltforms
|
||||
from nonebot_bison.plugin_config import plugin_config
|
||||
from nonebot_bison.sub_manager import add_sub_matcher, common_platform
|
||||
from nonebot_bison.platform import platform_manager, unavailable_paltforms
|
||||
|
||||
mocker.patch.object(plugin_config, "bison_use_browser", False)
|
||||
mocker.patch.dict(unavailable_paltforms, {"bilibili": "需要启用 bison_use_browser"})
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import json
|
||||
|
||||
import pytest
|
||||
from nonebug.app import App
|
||||
import pytest
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ..utils import BotReply, fake_superuser, fake_admin_user, fake_private_message_event
|
||||
from tests.utils import BotReply, fake_admin_user, fake_private_message_event, fake_superuser
|
||||
|
||||
|
||||
async def test_add_cookie_rule(app: App, mocker: MockerFixture):
|
||||
@@ -40,8 +40,8 @@ async def test_add_cookie_target_no_cookie(app: App):
|
||||
|
||||
async with app.test_matcher(add_cookie_target_matcher) as ctx:
|
||||
bot = ctx.create_bot(base=Bot)
|
||||
from nonebot_plugin_saa import MessageFactory, TargetQQGroup
|
||||
from nonebug_saa import should_send_saa
|
||||
from nonebot_plugin_saa import TargetQQGroup, MessageFactory
|
||||
|
||||
from nonebot_bison.config import config
|
||||
from nonebot_bison.types import Target as T_Target
|
||||
@@ -89,7 +89,7 @@ async def test_add_cookie(app: App):
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.sub_manager import common_platform, add_cookie_matcher, add_cookie_target_matcher
|
||||
from nonebot_bison.sub_manager import add_cookie_matcher, add_cookie_target_matcher, common_platform
|
||||
|
||||
async with app.test_matcher(add_cookie_matcher) as ctx:
|
||||
bot = ctx.create_bot(base=Bot)
|
||||
@@ -143,8 +143,8 @@ async def test_add_cookie(app: App):
|
||||
)
|
||||
|
||||
async with app.test_matcher(add_cookie_target_matcher) as ctx:
|
||||
from nonebot_plugin_saa import MessageFactory, TargetQQGroup
|
||||
from nonebug_saa import should_send_saa
|
||||
from nonebot_plugin_saa import TargetQQGroup, MessageFactory
|
||||
|
||||
from nonebot_bison.config import config
|
||||
from nonebot_bison.types import Target as T_Target
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
from nonebug import App
|
||||
import pytest
|
||||
|
||||
from ..utils import fake_superuser, fake_group_message_event, fake_private_message_event
|
||||
from tests.utils import fake_group_message_event, fake_private_message_event, fake_superuser
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
import json
|
||||
|
||||
import pytest
|
||||
from nonebug.app import App
|
||||
import pytest
|
||||
|
||||
from ..utils import fake_superuser, fake_private_message_event
|
||||
from tests.utils import fake_private_message_event, fake_superuser
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("_clear_db")
|
||||
async def test_del_cookie(app: App):
|
||||
from nonebug_saa import should_send_saa
|
||||
from nonebot.adapters.onebot.v11.bot import Bot
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
from nonebot_plugin_saa import TargetQQGroup, MessageFactory
|
||||
from nonebot_plugin_saa import MessageFactory, TargetQQGroup
|
||||
from nonebug_saa import should_send_saa
|
||||
|
||||
from nonebot_bison.config import config
|
||||
from nonebot_bison.config.db_model import Cookie
|
||||
from nonebot_bison.types import Target as T_Target
|
||||
from nonebot_bison.sub_manager import del_cookie_matcher
|
||||
from nonebot_bison.types import Target as T_Target
|
||||
|
||||
async with app.test_matcher(del_cookie_matcher) as ctx:
|
||||
bot = ctx.create_bot(base=Bot)
|
||||
@@ -69,15 +69,15 @@ async def test_del_cookie(app: App):
|
||||
@pytest.mark.usefixtures("_clear_db")
|
||||
@pytest.mark.usefixtures("_patch_weibo_get_cookie_name")
|
||||
async def test_del_cookie_err(app: App):
|
||||
from nonebug_saa import should_send_saa
|
||||
from nonebot.adapters.onebot.v11.bot import Bot
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
from nonebot_plugin_saa import TargetQQGroup, MessageFactory
|
||||
from nonebot_plugin_saa import MessageFactory, TargetQQGroup
|
||||
from nonebug_saa import should_send_saa
|
||||
|
||||
from nonebot_bison.config import config
|
||||
from nonebot_bison.config.db_model import Cookie
|
||||
from nonebot_bison.types import Target as T_Target
|
||||
from nonebot_bison.sub_manager import del_cookie_matcher
|
||||
from nonebot_bison.types import Target as T_Target
|
||||
|
||||
async with app.test_matcher(del_cookie_matcher) as ctx:
|
||||
bot = ctx.create_bot(base=Bot)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
from nonebug import App
|
||||
import pytest
|
||||
|
||||
from ..utils import BotReply, fake_admin_user, fake_group_message_event
|
||||
from tests.utils import BotReply, fake_admin_user, fake_group_message_event
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
import pytest
|
||||
from nonebug.app import App
|
||||
from nonebug_saa import should_send_saa
|
||||
import pytest
|
||||
|
||||
from ..utils import fake_admin_user, fake_group_message_event
|
||||
from tests.utils import fake_admin_user, fake_group_message_event
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_query_sub(app: App, init_scheduler):
|
||||
from nonebot.adapters.onebot.v11 import Bot, Message
|
||||
from nonebot_plugin_saa import TargetQQGroup, MessageFactory
|
||||
from nonebot_plugin_saa import MessageFactory, TargetQQGroup
|
||||
|
||||
from nonebot_bison.types import Target
|
||||
from nonebot_bison.config import config
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.sub_manager import query_sub_matcher
|
||||
from nonebot_bison.types import Target
|
||||
|
||||
await config.add_subscribe(
|
||||
TargetQQGroup(group_id=10000),
|
||||
@@ -41,12 +41,12 @@ async def test_query_sub(app: App, init_scheduler):
|
||||
@pytest.mark.asyncio
|
||||
async def test_query_no_exsits_sub(app: App, init_scheduler):
|
||||
from nonebot.adapters.onebot.v11 import Bot, Message
|
||||
from nonebot_plugin_saa import TargetQQGroup, MessageFactory
|
||||
from nonebot_plugin_saa import MessageFactory, TargetQQGroup
|
||||
|
||||
from nonebot_bison.types import Target
|
||||
from nonebot_bison.config import config
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.sub_manager import query_sub_matcher
|
||||
from nonebot_bison.types import Target
|
||||
|
||||
platform_manager["no_exsits_platform"] = platform_manager["weibo"]
|
||||
await config.add_subscribe(
|
||||
@@ -80,12 +80,12 @@ async def test_query_no_exsits_sub(app: App, init_scheduler):
|
||||
async def test_del_sub(app: App, init_scheduler):
|
||||
from nonebot.adapters.onebot.v11.bot import Bot
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
from nonebot_plugin_saa import TargetQQGroup, MessageFactory
|
||||
from nonebot_plugin_saa import MessageFactory, TargetQQGroup
|
||||
|
||||
from nonebot_bison.types import Target
|
||||
from nonebot_bison.config import config
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.sub_manager import del_sub_matcher
|
||||
from nonebot_bison.types import Target
|
||||
|
||||
await config.add_subscribe(
|
||||
TargetQQGroup(group_id=10000),
|
||||
@@ -129,12 +129,12 @@ async def test_del_sub(app: App, init_scheduler):
|
||||
async def test_del_no_exsits_sub(app: App, init_scheduler):
|
||||
from nonebot.adapters.onebot.v11.bot import Bot
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
from nonebot_plugin_saa import TargetQQGroup, MessageFactory
|
||||
from nonebot_plugin_saa import MessageFactory, TargetQQGroup
|
||||
|
||||
from nonebot_bison.types import Target
|
||||
from nonebot_bison.config import config
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.sub_manager import del_sub_matcher
|
||||
from nonebot_bison.types import Target
|
||||
|
||||
platform_manager["no_exsits_platform"] = platform_manager["weibo"]
|
||||
await config.add_subscribe(
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
from typing import cast
|
||||
from pathlib import Path
|
||||
from typing import cast
|
||||
from unittest.mock import patch
|
||||
|
||||
from nonebug.app import App
|
||||
from click.core import BaseCommand
|
||||
from click.testing import CliRunner
|
||||
from nonebug.app import App
|
||||
|
||||
from .utils import get_file
|
||||
|
||||
@@ -40,10 +40,10 @@ def test_cli_help(app: App):
|
||||
async def test_subs_export(app: App, tmp_path: Path):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
from nonebot_bison.config.db_model import Cookie
|
||||
from nonebot_bison.config.db_config import config
|
||||
from nonebot_bison.types import Target as TTarget
|
||||
from nonebot_bison.config.db_model import Cookie
|
||||
from nonebot_bison.script.cli import cli, run_sync
|
||||
from nonebot_bison.types import Target as TTarget
|
||||
|
||||
cli = cast(BaseCommand, cli)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import pytest
|
||||
from nonebug.app import App
|
||||
from nonebot.compat import model_dump
|
||||
from nonebug.app import App
|
||||
import pytest
|
||||
|
||||
from .utils import get_json
|
||||
|
||||
@@ -10,9 +10,9 @@ async def test_subs_export(app: App, init_scheduler):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
from nonebot_bison.config.db_config import config
|
||||
from nonebot_bison.types import Target as TTarget
|
||||
from nonebot_bison.config.db_model import User, Cookie
|
||||
from nonebot_bison.config.db_model import Cookie, User
|
||||
from nonebot_bison.config.subs_io import subscribes_export
|
||||
from nonebot_bison.types import Target as TTarget
|
||||
|
||||
await config.add_subscribe(
|
||||
TargetQQGroup(group_id=1232),
|
||||
@@ -111,8 +111,8 @@ async def test_subs_import_dup_err(app: App, init_scheduler):
|
||||
|
||||
async def test_subs_import_version_disorder(app: App, init_scheduler):
|
||||
from nonebot_bison.config.subs_io import subscribes_import
|
||||
from nonebot_bison.config.subs_io.utils import NBESFParseErr
|
||||
from nonebot_bison.config.subs_io.nbesf_model import v1, v2, v3
|
||||
from nonebot_bison.config.subs_io.utils import NBESFParseErr
|
||||
|
||||
# use v1 parse v2
|
||||
with pytest.raises(NBESFParseErr):
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from nonebug import App
|
||||
import pytest
|
||||
|
||||
from .utils import fake_admin_user, fake_private_message_event
|
||||
|
||||
@@ -12,9 +12,9 @@ async def test_command(app: App):
|
||||
from nonebot.adapters.onebot.v11.bot import Bot
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
|
||||
from nonebot_bison.plugin_config import plugin_config
|
||||
from nonebot_bison.admin_page import register_get_token_handler
|
||||
from nonebot_bison.admin_page.token_manager import token_manager as tm
|
||||
from nonebot_bison.plugin_config import plugin_config
|
||||
|
||||
with patch.object(tm, "get_user_token", return_value="test_token"):
|
||||
register_get_token_handler()
|
||||
@@ -39,12 +39,12 @@ async def test_command(app: App):
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_log(app: App, tmp_path: Path):
|
||||
import io
|
||||
import contextlib
|
||||
import io
|
||||
|
||||
from nonebot import get_driver
|
||||
from nonebot.drivers.fastapi import Driver
|
||||
from nonebot.log import logger, default_format
|
||||
from nonebot.log import default_format, logger
|
||||
|
||||
from nonebot_bison.admin_page import init_fastapi
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import httpx
|
||||
import respx
|
||||
from nonebug.app import App
|
||||
import respx
|
||||
|
||||
|
||||
@respx.mock
|
||||
async def test_http_error(app: App):
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager, http_client
|
||||
from nonebot_bison.utils import DefaultClientManager, ProcessContext, http_client
|
||||
|
||||
example_route = respx.get("https://example.com")
|
||||
example_route.mock(httpx.Response(403, json={"error": "gg"}))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import pytest
|
||||
from nonebug import App
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import typing
|
||||
|
||||
import pytest
|
||||
from flaky import flaky
|
||||
from nonebug.app import App
|
||||
import pytest
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
import sys
|
||||
@@ -65,7 +65,7 @@ async def downloaded_resource_2():
|
||||
@pytest.mark.external
|
||||
@flaky
|
||||
async def test_9_merge(app: App, downloaded_resource: list[bytes]):
|
||||
from nonebot_bison.utils import pic_merge, http_client
|
||||
from nonebot_bison.utils import http_client, pic_merge
|
||||
|
||||
pics = await pic_merge(list(downloaded_resource), http_client())
|
||||
assert len(pics) == 5
|
||||
@@ -74,7 +74,7 @@ async def test_9_merge(app: App, downloaded_resource: list[bytes]):
|
||||
@pytest.mark.external
|
||||
@flaky
|
||||
async def test_9_merge_2(app: App, downloaded_resource_2: list[bytes]):
|
||||
from nonebot_bison.utils import pic_merge, http_client
|
||||
from nonebot_bison.utils import http_client, pic_merge
|
||||
|
||||
pics = await pic_merge(list(downloaded_resource_2), http_client())
|
||||
assert len(pics) == 4
|
||||
@@ -83,7 +83,7 @@ async def test_9_merge_2(app: App, downloaded_resource_2: list[bytes]):
|
||||
@pytest.mark.external
|
||||
@flaky
|
||||
async def test_6_merge(app: App, downloaded_resource: list[bytes]):
|
||||
from nonebot_bison.utils import pic_merge, http_client
|
||||
from nonebot_bison.utils import http_client, pic_merge
|
||||
|
||||
pics = await pic_merge(list(downloaded_resource[0:6] + downloaded_resource[9:]), http_client())
|
||||
assert len(pics) == 5
|
||||
@@ -92,7 +92,7 @@ async def test_6_merge(app: App, downloaded_resource: list[bytes]):
|
||||
@pytest.mark.external
|
||||
@flaky
|
||||
async def test_3_merge(app: App, downloaded_resource: list[bytes]):
|
||||
from nonebot_bison.utils import pic_merge, http_client
|
||||
from nonebot_bison.utils import http_client, pic_merge
|
||||
|
||||
pics = await pic_merge(list(downloaded_resource[0:3] + downloaded_resource[9:]), http_client())
|
||||
assert len(pics) == 5
|
||||
@@ -101,7 +101,7 @@ async def test_3_merge(app: App, downloaded_resource: list[bytes]):
|
||||
@pytest.mark.external
|
||||
@flaky
|
||||
async def test_6_merge_only(app: App, downloaded_resource: list[bytes]):
|
||||
from nonebot_bison.utils import pic_merge, http_client
|
||||
from nonebot_bison.utils import http_client, pic_merge
|
||||
|
||||
pics = await pic_merge(list(downloaded_resource[0:6]), http_client())
|
||||
assert len(pics) == 1
|
||||
@@ -110,7 +110,7 @@ async def test_6_merge_only(app: App, downloaded_resource: list[bytes]):
|
||||
@pytest.mark.external
|
||||
@flaky
|
||||
async def test_3_merge_only(app: App, downloaded_resource: list[bytes]):
|
||||
from nonebot_bison.utils import pic_merge, http_client
|
||||
from nonebot_bison.utils import http_client, pic_merge
|
||||
|
||||
pics = await pic_merge(list(downloaded_resource[0:3]), http_client())
|
||||
assert len(pics) == 1
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import pytest
|
||||
from nonebug.app import App
|
||||
import pytest
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ from pytest_mock import MockerFixture
|
||||
async def test_render(app: App, mocker: MockerFixture):
|
||||
from nonebot_plugin_saa import Image
|
||||
|
||||
from nonebot_bison.utils import parse_text
|
||||
from nonebot_bison.plugin_config import plugin_config
|
||||
from nonebot_bison.utils import parse_text
|
||||
|
||||
mocker.patch.object(plugin_config, "bison_use_pic", True)
|
||||
|
||||
@@ -26,10 +26,10 @@ async def test_render(app: App, mocker: MockerFixture):
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.render
|
||||
async def test_convert(app: App, mocker: MockerFixture):
|
||||
from nonebot_plugin_saa import Text, Image
|
||||
from nonebot_plugin_saa import Image, Text
|
||||
|
||||
from nonebot_bison.utils import text_to_image
|
||||
from nonebot_bison.plugin_config import plugin_config
|
||||
from nonebot_bison.utils import text_to_image
|
||||
|
||||
mocker.patch.object(plugin_config, "bison_use_pic", True)
|
||||
|
||||
|
||||
+8
-8
@@ -1,18 +1,18 @@
|
||||
import asyncio
|
||||
|
||||
import pytest
|
||||
from nonebug import App
|
||||
from nonebug_saa import should_send_saa
|
||||
import pytest
|
||||
from pytest_mock.plugin import MockerFixture
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_no_queue(app: App, mocker: MockerFixture):
|
||||
from nonebot.adapters.onebot.v11.bot import Bot
|
||||
from nonebot_plugin_saa import TargetQQGroup, MessageFactory, TargetQQPrivate
|
||||
from nonebot_plugin_saa import MessageFactory, TargetQQGroup, TargetQQPrivate
|
||||
|
||||
from nonebot_bison.send import send_msgs
|
||||
from nonebot_bison.plugin_config import plugin_config
|
||||
from nonebot_bison.send import send_msgs
|
||||
|
||||
mocker.patch.object(plugin_config, "bison_use_queue", False)
|
||||
|
||||
@@ -34,8 +34,8 @@ async def test_send_no_queue(app: App, mocker: MockerFixture):
|
||||
async def test_send_queue(app: App, mocker: MockerFixture):
|
||||
import nonebot
|
||||
from nonebot.adapters.onebot.v11.bot import Bot
|
||||
from nonebot_plugin_saa import MessageFactory, TargetQQGroup
|
||||
from nonebot_plugin_saa.auto_select_bot import refresh_bots
|
||||
from nonebot_plugin_saa import TargetQQGroup, MessageFactory
|
||||
|
||||
from nonebot_bison.plugin_config import plugin_config
|
||||
from nonebot_bison.send import MESSGE_SEND_INTERVAL, send_msgs
|
||||
@@ -63,11 +63,11 @@ async def test_send_queue(app: App, mocker: MockerFixture):
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_merge_no_queue(app: App, mocker: MockerFixture):
|
||||
from nonebot.adapters.onebot.v11.bot import Bot
|
||||
from nonebot_plugin_saa import AggregatedMessageFactory, Image, MessageFactory, TargetQQGroup, Text
|
||||
from nonebot_plugin_saa.auto_select_bot import refresh_bots
|
||||
from nonebot_plugin_saa import Text, Image, TargetQQGroup, MessageFactory, AggregatedMessageFactory
|
||||
|
||||
from nonebot_bison.send import send_msgs
|
||||
from nonebot_bison.plugin_config import plugin_config
|
||||
from nonebot_bison.send import send_msgs
|
||||
|
||||
mocker.patch.object(plugin_config, "bison_use_pic_merge", 1)
|
||||
mocker.patch.object(plugin_config, "bison_use_queue", False)
|
||||
@@ -108,11 +108,11 @@ async def test_send_merge_no_queue(app: App, mocker: MockerFixture):
|
||||
|
||||
async def test_send_merge2_no_queue(app: App, mocker: MockerFixture):
|
||||
from nonebot.adapters.onebot.v11.bot import Bot
|
||||
from nonebot_plugin_saa import AggregatedMessageFactory, Image, MessageFactory, TargetQQGroup, Text
|
||||
from nonebot_plugin_saa.auto_select_bot import refresh_bots
|
||||
from nonebot_plugin_saa import Text, Image, TargetQQGroup, MessageFactory, AggregatedMessageFactory
|
||||
|
||||
from nonebot_bison.send import send_msgs
|
||||
from nonebot_bison.plugin_config import plugin_config
|
||||
from nonebot_bison.send import send_msgs
|
||||
|
||||
mocker.patch.object(plugin_config, "bison_use_pic_merge", 2)
|
||||
mocker.patch.object(plugin_config, "bison_use_queue", False)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from typing import Literal
|
||||
|
||||
import pytest
|
||||
from nonebug import App
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
+14
-13
@@ -1,11 +1,11 @@
|
||||
from time import time
|
||||
from copy import deepcopy
|
||||
from inspect import cleandoc
|
||||
from typing import TYPE_CHECKING, Any
|
||||
from time import time
|
||||
from typing import TYPE_CHECKING, Any, ClassVar
|
||||
|
||||
import pytest
|
||||
from flaky import flaky
|
||||
from nonebug import App
|
||||
import pytest
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -15,7 +15,8 @@ now = time()
|
||||
passed = now - 3 * 60 * 60
|
||||
raw_post_list_1 = [{"id": 1, "text": "p1", "date": now, "tags": ["tag1"], "category": 1}]
|
||||
|
||||
raw_post_list_2 = raw_post_list_1 + [
|
||||
raw_post_list_2 = [
|
||||
*raw_post_list_1,
|
||||
{"id": 2, "text": "p2", "date": now, "tags": ["tag1"], "category": 1},
|
||||
{"id": 3, "text": "p3", "date": now, "tags": ["tag2"], "category": 2},
|
||||
{"id": 4, "text": "p4", "date": now, "tags": ["tag2"], "category": 3},
|
||||
@@ -36,9 +37,9 @@ def SIMPLE_PNG_DATA() -> bytes:
|
||||
|
||||
@pytest.fixture
|
||||
def mock_platform(app: App):
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import Target, RawPost
|
||||
from nonebot_bison.platform.platform import NewMessage
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import RawPost, Target
|
||||
|
||||
class MockPlatform(NewMessage):
|
||||
platform_name = "mock_platform"
|
||||
@@ -47,7 +48,7 @@ def mock_platform(app: App):
|
||||
is_common = True
|
||||
schedule_interval = 10
|
||||
enable_tag = False
|
||||
categories = {}
|
||||
categories: ClassVar[dict] = {}
|
||||
has_target = True
|
||||
|
||||
sub_index = 0
|
||||
@@ -84,7 +85,7 @@ def mock_platform(app: App):
|
||||
@pytest.fixture
|
||||
def mock_post(app: App, mock_platform):
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
from nonebot_bison.utils import DefaultClientManager, ProcessContext
|
||||
|
||||
return Post(
|
||||
m := mock_platform(ProcessContext(DefaultClientManager())),
|
||||
@@ -161,7 +162,7 @@ async def test_theme_no_enable_use_browser(app: App, mock_post, mocker: MockerFi
|
||||
@pytest.mark.asyncio
|
||||
@flaky(max_runs=3, min_passes=1)
|
||||
async def test_arknights_theme(app: App, mock_post):
|
||||
from nonebot_plugin_saa import Text, Image
|
||||
from nonebot_plugin_saa import Image, Text
|
||||
|
||||
from nonebot_bison.theme import theme_manager
|
||||
from nonebot_bison.theme.themes.arknights import ArknightsTheme
|
||||
@@ -178,7 +179,7 @@ async def test_arknights_theme(app: App, mock_post):
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_basic_theme(app: App, mock_post: "Post", MERGEABLE_PNG_DATA, SIMPLE_PNG_DATA):
|
||||
from nonebot_plugin_saa import Text, Image
|
||||
from nonebot_plugin_saa import Image, Text
|
||||
|
||||
from nonebot_bison.theme import theme_manager
|
||||
from nonebot_bison.theme.themes.basic import BasicTheme
|
||||
@@ -233,7 +234,7 @@ async def test_basic_theme(app: App, mock_post: "Post", MERGEABLE_PNG_DATA, SIMP
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_brief_theme(app: App, mock_post):
|
||||
from nonebot_plugin_saa import Text, Image
|
||||
from nonebot_plugin_saa import Image, Text
|
||||
|
||||
from nonebot_bison.theme import theme_manager
|
||||
from nonebot_bison.theme.themes.brief import BriefTheme
|
||||
@@ -275,7 +276,7 @@ async def test_brief_theme(app: App, mock_post):
|
||||
@pytest.mark.asyncio
|
||||
@flaky(max_runs=3, min_passes=1)
|
||||
async def test_ceobecanteen_theme(app: App, mock_post: "Post", MERGEABLE_PNG_DATA, SIMPLE_PNG_DATA):
|
||||
from nonebot_plugin_saa import Text, Image
|
||||
from nonebot_plugin_saa import Image, Text
|
||||
|
||||
from nonebot_bison.theme import theme_manager
|
||||
from nonebot_bison.theme.themes.ceobe_canteen import CeobeCanteenTheme
|
||||
@@ -301,7 +302,7 @@ async def test_ceobecanteen_theme(app: App, mock_post: "Post", MERGEABLE_PNG_DAT
|
||||
@pytest.mark.asyncio
|
||||
@flaky(max_runs=3, min_passes=1)
|
||||
async def test_ht2i_theme(app: App, mock_post: "Post", MERGEABLE_PNG_DATA, SIMPLE_PNG_DATA):
|
||||
from nonebot_plugin_saa import Text, Image
|
||||
from nonebot_plugin_saa import Image, Text
|
||||
|
||||
from nonebot_bison.theme import theme_manager
|
||||
from nonebot_bison.theme.themes.ht2i import Ht2iTheme
|
||||
|
||||
+4
-5
@@ -12,9 +12,9 @@ class AppReq(TypedDict, total=False):
|
||||
|
||||
|
||||
def fake_group_message_event(**field) -> "GroupMessageEvent":
|
||||
from pydantic import create_model
|
||||
from nonebot.adapters.onebot.v11 import GroupMessageEvent, Message
|
||||
from nonebot.adapters.onebot.v11.event import Sender
|
||||
from nonebot.adapters.onebot.v11 import Message, GroupMessageEvent
|
||||
from pydantic import create_model
|
||||
|
||||
_Fake = create_model("_Fake", __base__=GroupMessageEvent)
|
||||
|
||||
@@ -48,9 +48,9 @@ def fake_group_message_event(**field) -> "GroupMessageEvent":
|
||||
|
||||
|
||||
def fake_private_message_event(**field) -> "PrivateMessageEvent":
|
||||
from pydantic import create_model
|
||||
from nonebot.adapters.onebot.v11.event import Sender
|
||||
from nonebot.adapters.onebot.v11 import Message, PrivateMessageEvent
|
||||
from nonebot.adapters.onebot.v11.event import Sender
|
||||
from pydantic import create_model
|
||||
|
||||
_Fake = create_model("_Fake", __base__=PrivateMessageEvent)
|
||||
|
||||
@@ -89,7 +89,6 @@ add_reply_on_id_input_search = (
|
||||
|
||||
|
||||
class BotReply:
|
||||
|
||||
@staticmethod
|
||||
def add_reply_on_platform(platform_manager, common_platform):
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user