mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2026-05-09 18:27:56 +08:00
🐛 修正项目的代码警告 (#614)
* 🐛 调整ruff的pytest警告 * 🐛 调整导入关系警告 * 🐛 删除奇怪无用的赋值和取值逻辑 * ✅ 不同测试部分所用变量应加以区分 * 🐛 subs_io model添加默认值 * 🐛 修完所有的 ruff PT001 警告 * 🔧 按ruff建议修改ruff配置 warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in `pyproject.toml`: - 'ignore' -> 'lint.ignore' - 'select' -> 'lint.select' --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -10,7 +10,7 @@ if typing.TYPE_CHECKING:
|
||||
from nonebot_bison.config.config_legacy import Config
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def config_legacy(app: App, use_legacy_config):
|
||||
from nonebot_bison.config import config_legacy as config
|
||||
|
||||
|
||||
@@ -52,18 +52,18 @@ async def test_add_subscribe(app: App, init_scheduler):
|
||||
)
|
||||
confs = await config.list_subscribe(TargetQQGroup(group_id=123))
|
||||
assert len(confs) == 1
|
||||
conf: Subscribe = confs[0]
|
||||
conf2: Subscribe = confs[0]
|
||||
async with AsyncSession(get_engine()) as sess:
|
||||
related_user_obj = await sess.scalar(select(User).where(User.id == conf.user_id))
|
||||
related_target_obj = await sess.scalar(select(Target).where(Target.id == conf.target_id))
|
||||
related_user_obj = await sess.scalar(select(User).where(User.id == conf2.user_id))
|
||||
related_target_obj = await sess.scalar(select(Target).where(Target.id == conf2.target_id))
|
||||
assert related_user_obj
|
||||
assert related_target_obj
|
||||
assert related_user_obj.user_target["group_id"] == 123
|
||||
assert related_target_obj.target_name == "weibo_name2"
|
||||
assert related_target_obj.target == "weibo_id"
|
||||
assert conf.target.target == "weibo_id"
|
||||
assert conf.categories == [1]
|
||||
assert conf.tags == ["tag"]
|
||||
assert conf2.target.target == "weibo_id"
|
||||
assert conf2.categories == [1]
|
||||
assert conf2.tags == ["tag"]
|
||||
|
||||
|
||||
async def test_add_dup_sub(init_scheduler):
|
||||
|
||||
+4
-4
@@ -28,7 +28,7 @@ def load_adapters(nonebug_init: None):
|
||||
return driver
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
async def app(tmp_path: Path, request: pytest.FixtureRequest, mocker: MockerFixture):
|
||||
sys.path.append(str(Path(__file__).parent.parent / "src" / "plugins"))
|
||||
|
||||
@@ -75,7 +75,7 @@ async def app(tmp_path: Path, request: pytest.FixtureRequest, mocker: MockerFixt
|
||||
cache_dir.mkdir()
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def dummy_user_subinfo(app: App):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
@@ -85,14 +85,14 @@ def dummy_user_subinfo(app: App):
|
||||
return UserSubInfo(user=user, categories=[], tags=[])
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
async def init_scheduler(app: App):
|
||||
from nonebot_bison.scheduler.manager import init_scheduler
|
||||
|
||||
return await init_scheduler()
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
async def use_legacy_config(app: App):
|
||||
import aiofiles
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ from nonebot.compat import model_dump, type_validate_python
|
||||
from .utils import get_file, get_json
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def arknights(app: App):
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
|
||||
@@ -15,7 +15,7 @@ from nonebot.compat import model_dump, type_validate_python
|
||||
from .utils import get_json
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def bing_dy_list(app: App):
|
||||
from nonebot_bison.platform.bilibili.models import PostAPI
|
||||
|
||||
@@ -26,7 +26,7 @@ if TYPE_CHECKING:
|
||||
from nonebot_bison.platform.bilibili import Bilibili
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def bilibili(app: App) -> "Bilibili":
|
||||
from nonebot_bison.utils import ProcessContext
|
||||
from nonebot_bison.platform import platform_manager
|
||||
@@ -35,7 +35,7 @@ def bilibili(app: App) -> "Bilibili":
|
||||
return platform_manager["bilibili"](ProcessContext(BilibiliClientManager())) # type: ignore
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def without_dynamic(app: App):
|
||||
from nonebot_bison.platform.bilibili.models import PostAPI
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ if typing.TYPE_CHECKING:
|
||||
from nonebot_bison.platform.bilibili import BilibiliBangumi
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def bili_bangumi(app: App):
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
|
||||
@@ -12,7 +12,7 @@ if TYPE_CHECKING:
|
||||
from nonebot_bison.platform.bilibili import Bilibililive
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def bili_live(app: App):
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
@@ -20,7 +20,7 @@ def bili_live(app: App):
|
||||
return platform_manager["bilibili-live"](ProcessContext(DefaultClientManager()))
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def dummy_only_open_user_subinfo(app: App):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
@@ -131,7 +131,7 @@ async def test_fetch_bililive_only_live_open(bili_live: "Bilibililive", dummy_on
|
||||
assert len(res4[0][1]) == 0
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def dummy_only_title_user_subinfo(app: App):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
@@ -190,7 +190,7 @@ async def test_fetch_bililive_only_title_change(bili_live, dummy_only_title_user
|
||||
assert len(res4[0][1]) == 0
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def dummy_only_close_user_subinfo(app: App):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
@@ -250,7 +250,7 @@ async def test_fetch_bililive_only_close(bili_live, dummy_only_close_user_subinf
|
||||
assert post4.compress is True
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def dummy_bililive_user_subinfo(app: App):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ if TYPE_CHECKING:
|
||||
from nonebot_bison.platform.ceobecanteen import CeobeCanteen
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def dummy_only_open_user_subinfo(app: App):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
@@ -22,7 +22,7 @@ def dummy_only_open_user_subinfo(app: App):
|
||||
return UserSubInfo(user=user, categories=[1], tags=[])
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def ceobecanteen(app: App):
|
||||
from nonebot_bison.utils import ProcessContext
|
||||
from nonebot_bison.platform import platform_manager
|
||||
|
||||
@@ -6,7 +6,7 @@ from nonebug.app import App
|
||||
from .utils import get_json
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def ff14(app: App):
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
|
||||
@@ -12,7 +12,7 @@ if typing.TYPE_CHECKING:
|
||||
from nonebot_bison.platform.ncm import NcmArtist
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def ncm_artist(app: App):
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
|
||||
@@ -12,7 +12,7 @@ if typing.TYPE_CHECKING:
|
||||
from nonebot_bison.platform.ncm import NcmRadio
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def ncm_radio(app: App):
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
|
||||
@@ -16,7 +16,7 @@ raw_post_list_2 = raw_post_list_1 + [
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def dummy_user(app: App):
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
@@ -24,7 +24,7 @@ def dummy_user(app: App):
|
||||
return user
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def user_info_factory(app: App, dummy_user):
|
||||
from nonebot_bison.types import UserSubInfo
|
||||
|
||||
@@ -34,7 +34,7 @@ def user_info_factory(app: App, dummy_user):
|
||||
return _user_info
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def mock_platform_without_cats_tags(app: App):
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import Target, RawPost
|
||||
@@ -81,7 +81,7 @@ def mock_platform_without_cats_tags(app: App):
|
||||
return MockPlatform
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def mock_platform(app: App):
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.utils import Site
|
||||
@@ -143,7 +143,7 @@ def mock_platform(app: App):
|
||||
return MockPlatform
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def mock_site(app):
|
||||
from nonebot_bison.utils import Site
|
||||
|
||||
@@ -155,7 +155,7 @@ def mock_site(app):
|
||||
return MockSite
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def mock_platform_no_target(app: App, mock_site):
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import Tag, Target, RawPost, Category
|
||||
@@ -210,7 +210,7 @@ def mock_platform_no_target(app: App, mock_site):
|
||||
return MockPlatform
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@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
|
||||
@@ -272,7 +272,7 @@ def mock_platform_no_target_2(app: App, mock_site):
|
||||
return MockPlatform
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def mock_status_change(app: App):
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.platform.platform import StatusChange
|
||||
|
||||
@@ -14,7 +14,7 @@ if typing.TYPE_CHECKING:
|
||||
pass
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def dummy_user(app: App):
|
||||
from nonebot_bison.types import User
|
||||
|
||||
@@ -22,7 +22,7 @@ def dummy_user(app: App):
|
||||
return user
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def user_info_factory(app: App, dummy_user):
|
||||
from nonebot_bison.types import UserSubInfo
|
||||
|
||||
@@ -32,7 +32,7 @@ def user_info_factory(app: App, dummy_user):
|
||||
return _user_info
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def rss(app: App):
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
@@ -40,7 +40,7 @@ def rss(app: App):
|
||||
return platform_manager["rss"](ProcessContext(DefaultClientManager()))
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def update_time_feed_1():
|
||||
file = get_file("rss-twitter-ArknightsStaff.xml")
|
||||
root = ET.fromstring(file)
|
||||
@@ -53,7 +53,7 @@ def update_time_feed_1():
|
||||
return ET.tostring(root, encoding="unicode")
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def update_time_feed_2():
|
||||
file = get_file("rss-ruanyifeng.xml")
|
||||
root = ET.fromstring(file)
|
||||
@@ -119,7 +119,7 @@ async def test_fetch_new_2(
|
||||
assert post1.content == "这里记录每周值得分享的科技内容,周五发布。..."
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def update_time_feed_3():
|
||||
file = get_file("rss-github-atom.xml")
|
||||
root = ET.fromstring(file)
|
||||
|
||||
@@ -16,7 +16,7 @@ if typing.TYPE_CHECKING:
|
||||
image_cdn_router = respx.route(host__regex=r"wx\d.sinaimg.cn", path__startswith="/large/")
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def weibo(app: App):
|
||||
from nonebot_bison.platform import platform_manager
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
|
||||
@@ -18,7 +18,7 @@ raw_post_list_2 = raw_post_list_1 + [
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def mock_platform(app: App):
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import Target, RawPost
|
||||
|
||||
@@ -138,10 +138,10 @@ async def test_subs_import_v1(app: App, tmp_path):
|
||||
assert result.exit_code == 0
|
||||
assert len(await config.list_subs_with_all_info()) == 3
|
||||
|
||||
mock_file: Path = tmp_path / "2.yaml"
|
||||
mock_file.write_text(get_file("v1/subs_export.yaml"))
|
||||
mock_file2: Path = tmp_path / "2.yaml"
|
||||
mock_file2.write_text(get_file("v1/subs_export.yaml"))
|
||||
|
||||
result = await run_sync(runner.invoke)(cli, ["import", "-p", str(mock_file), "--format=yml"])
|
||||
result = await run_sync(runner.invoke)(cli, ["import", "-p", str(mock_file2), "--format=yml"])
|
||||
assert result.exit_code == 0
|
||||
assert len(await config.list_subs_with_all_info()) == 6
|
||||
|
||||
@@ -169,9 +169,9 @@ async def test_sub_import_v2(app: App, tmp_path):
|
||||
assert result.exit_code == 0
|
||||
assert len(await config.list_subs_with_all_info()) == 3
|
||||
|
||||
mock_file: Path = tmp_path / "2.yaml"
|
||||
mock_file.write_text(get_file("v2/subs_export.yaml"))
|
||||
mock_file2: Path = tmp_path / "2.yaml"
|
||||
mock_file2.write_text(get_file("v2/subs_export.yaml"))
|
||||
|
||||
result = await run_sync(runner.invoke)(cli, ["import", "-p", str(mock_file), "--format=yml"])
|
||||
result = await run_sync(runner.invoke)(cli, ["import", "-p", str(mock_file2), "--format=yml"])
|
||||
assert result.exit_code == 0
|
||||
assert len(await config.list_subs_with_all_info()) == 6
|
||||
|
||||
@@ -52,12 +52,12 @@ async def download_imgs(url_list: list[str]) -> list[bytes]:
|
||||
return img_contents
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
async def downloaded_resource():
|
||||
return await download_imgs(merge_source_9)
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
async def downloaded_resource_2():
|
||||
return await download_imgs(merge_source_9_2)
|
||||
|
||||
|
||||
@@ -22,19 +22,19 @@ raw_post_list_2 = raw_post_list_1 + [
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def MERGEABLE_PNG_DATA() -> bytes:
|
||||
from tests.platforms.utils import get_bytes
|
||||
|
||||
return get_bytes("mergeable-pic.jpg")
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def SIMPLE_PNG_DATA() -> bytes:
|
||||
return b"\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08\x06\x00\x00\x00\x1f\x15\xc4\x89"
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def mock_platform(app: App):
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import Target, RawPost
|
||||
@@ -81,7 +81,7 @@ def mock_platform(app: App):
|
||||
return MockPlatform
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def mock_post(app: App, mock_platform):
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
||||
|
||||
Reference in New Issue
Block a user