mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-06 20:06:12 +08:00
* 🐛 插入新的Schedulable时应传入use_batch参数 * ✨ 适配ceobecanteen平台 Co-authored-by: phidiaLam <2957035701@qq.com> * ✨ ✨ 明日方舟公告与官网采用截图分享 (#480) * ✨ 明日方舟公告与官网采用截图分享 * 💄 auto fix by pre-commit hooks * 🐛 修复缺少的导入,优化逻辑 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Azide <rukuy@qq.com> * 🐛 优化截图图片效果 * 🐛 修复错误将转发内图片视作头图的问题 * 🍱 使用正式 Bison Logo * 💄 auto fix by pre-commit hooks * 🐛 请求小刻API时不在headers里添加过多字段 * 🐛 get_comb_id方法删除无用的targets参数 * 💡 get_comb_id方法更新注释 * 🔥 移除发送部分的更改 * ✨ 在命名中明确表示cond_func意图 * ♻️ 拆分get_comb_id功能 * ♻️ 调整缓存逻辑 * ✨ 使用uri在theme中调用platform截图 * ♻️ 重构截图逻辑 * ✨ 添加模糊匹配提示 * ✨ 适配新版Site * 💄 auto fix by pre-commit hooks * 🐛 去掉不必要的排序 * 🐛 修正不应出现的驼峰变量名 * ♻️ 按review意见修改 * ♻️ 调整截图函数逻辑 * 🔊 调低日志等级 * ✏️ 修复一些拼写和格式 --------- Co-authored-by: phidiaLam <2957035701@qq.com> Co-authored-by: 洛梧藤 <67498817+phidiaLam@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
116 lines
3.4 KiB
Python
116 lines
3.4 KiB
Python
import sys
|
|
from pathlib import Path
|
|
from shutil import rmtree
|
|
|
|
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 .utils import AppReq
|
|
|
|
|
|
def pytest_configure(config: pytest.Config) -> None:
|
|
config.stash[NONEBOT_INIT_KWARGS] = {
|
|
"datastore_database_url": "sqlite+aiosqlite:///:memory:",
|
|
"superusers": {"10001"},
|
|
"command_start": {""},
|
|
"log_level": "TRACE",
|
|
}
|
|
|
|
|
|
@pytest.fixture(scope="session", autouse=True)
|
|
def load_adapters(nonebug_init: None):
|
|
driver = nonebot.get_driver()
|
|
driver.register_adapter(OnebotV11Adapter)
|
|
return driver
|
|
|
|
|
|
@pytest.fixture()
|
|
async def app(tmp_path: Path, request: pytest.FixtureRequest, mocker: MockerFixture):
|
|
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_bison import plugin_config
|
|
from nonebot_bison.config.db_model import User, Target, Subscribe, ScheduleTimeWeight
|
|
|
|
plugin_config.bison_config_path = str(tmp_path / "legacy_config")
|
|
plugin_config.bison_filter_log = False
|
|
plugin_config.bison_use_browser = True
|
|
|
|
datastore_config.datastore_config_dir = tmp_path / "config"
|
|
datastore_config.datastore_cache_dir = tmp_path / "cache"
|
|
datastore_config.datastore_data_dir = tmp_path / "data"
|
|
|
|
param: AppReq = getattr(request, "param", AppReq())
|
|
|
|
if not param.get("no_init_db"):
|
|
await init_db()
|
|
# if not param.get("refresh_bot"):
|
|
# import nonebot_bison.utils.get_bot
|
|
#
|
|
# mocker.patch.object(nonebot_bison.utils.get_bot, "refresh_bots")
|
|
|
|
yield App()
|
|
|
|
# cleanup
|
|
async with create_session() as session, session.begin():
|
|
await session.execute(delete(User))
|
|
await session.execute(delete(Subscribe))
|
|
await session.execute(delete(Target))
|
|
await session.execute(delete(ScheduleTimeWeight))
|
|
|
|
# 关闭渲染图片时打开的浏览器
|
|
await shutdown_browser()
|
|
# 清除缓存文件
|
|
cache_dir = Path.cwd() / ".cache" / "hishel"
|
|
if cache_dir.exists():
|
|
rmtree(cache_dir)
|
|
cache_dir.mkdir()
|
|
|
|
|
|
@pytest.fixture()
|
|
def dummy_user_subinfo(app: App):
|
|
from nonebot_plugin_saa import TargetQQGroup
|
|
|
|
from nonebot_bison.types import UserSubInfo
|
|
|
|
user = TargetQQGroup(group_id=123)
|
|
return UserSubInfo(user=user, categories=[], tags=[])
|
|
|
|
|
|
@pytest.fixture()
|
|
async def init_scheduler(app: App):
|
|
from nonebot_bison.scheduler.manager import init_scheduler
|
|
|
|
return await init_scheduler()
|
|
|
|
|
|
@pytest.fixture()
|
|
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
|
|
|
|
# 默认不创建配置所在的文件夹
|
|
# 如果需要测试需要手动创建相关文件夹
|
|
path = Path(get_config_path()[0])
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
async with aiofiles.open(path, "w") as f:
|
|
await f.write("{}")
|
|
|
|
Config()._do_init()
|
|
|
|
yield None
|
|
|
|
# 清除单例的缓存
|
|
Singleton._instances.clear()
|