Skip to content

Commit

Permalink
🐛 调整测试代码部分
Browse files Browse the repository at this point in the history
  • Loading branch information
AzideCupric committed Dec 11, 2024
1 parent d3fe063 commit e38032e
Show file tree
Hide file tree
Showing 39 changed files with 306 additions and 302 deletions.
4 changes: 2 additions & 2 deletions extra_plugins/auto_agree.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from nonebot import on_request
from nonebot.log import logger
from nonebot.adapters.onebot.v11 import Bot
from nonebot.adapters.onebot.v11.event import GroupRequestEvent, FriendRequestEvent
from nonebot.adapters.onebot.v11.event import FriendRequestEvent, GroupRequestEvent
from nonebot.log import logger

friend_req = on_request(priority=5)

Expand Down
2 changes: 1 addition & 1 deletion tests/config/test_config_legacy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import typing

import pytest
from nonebug.app import App
import pytest

if typing.TYPE_CHECKING:
import sys
Expand Down
18 changes: 9 additions & 9 deletions tests/config/test_config_operation.py
Original file line number Diff line number Diff line change
@@ -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),
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand Down
6 changes: 3 additions & 3 deletions tests/config/test_cookie.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
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")
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")
Expand Down
8 changes: 4 additions & 4 deletions tests/config/test_data_migration.py
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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(
Expand Down
12 changes: 6 additions & 6 deletions tests/config/test_scheduler_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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),
Expand Down
18 changes: 9 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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 nonebot.adapters.onebot.v11 import Adapter as OnebotV11Adapter
from nonebug import NONEBOT_INIT_KWARGS, App
import pytest
from pytest_mock.plugin import MockerFixture
from nonebot.adapters.onebot.v11 import Adapter as OnebotV11Adapter
from sqlalchemy import delete

from .utils import AppReq

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

# 默认不创建配置所在的文件夹
# 如果需要测试需要手动创建相关文件夹
Expand All @@ -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())
Expand Down
34 changes: 17 additions & 17 deletions tests/platforms/test_arknights.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
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


@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()))

Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -110,10 +110,10 @@ def make_response(b: BulletinData):
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 (
Expand All @@ -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"] = ""
Expand All @@ -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,
Expand All @@ -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")
Expand Down Expand Up @@ -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,
Expand All @@ -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")
Expand Down Expand Up @@ -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")

Expand Down
Loading

0 comments on commit e38032e

Please sign in to comment.