From 279913da580e9a112e1807a22236fce9c5a57a2a Mon Sep 17 00:00:00 2001 From: uy_sun Date: Tue, 22 Oct 2024 13:47:38 +0800 Subject: [PATCH] =?UTF-8?q?style:=20=E4=BD=BF=E7=94=A8=20ruff=200.7.0=20?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-config.yaml | 6 +++--- docker/plugin_test.py | 6 +++--- tests/conftest.py | 4 ++-- tests/github/conftest.py | 2 +- ...est_publish_resolve_conflict_pull_requests.py | 16 +++++++--------- tests/utils/store_test/test_store_test.py | 2 +- 6 files changed, 17 insertions(+), 19 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2078476..09c56bf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,11 +6,11 @@ ci: autoupdate_commit_msg: "chore: auto update by pre-commit hooks" repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.5.2 + rev: v0.7.0 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] - stages: [commit] + stages: [pre-commit] - id: ruff-format - repo: https://github.com/pre-commit/mirrors-prettier @@ -18,4 +18,4 @@ repos: hooks: - id: prettier types_or: [javascript, jsx, ts, tsx, markdown, yaml, json] - stages: [commit] + stages: [pre-commit] diff --git a/docker/plugin_test.py b/docker/plugin_test.py index c0eb525..0faaa4c 100644 --- a/docker/plugin_test.py +++ b/docker/plugin_test.py @@ -8,12 +8,12 @@ 经测试可以直接在 Python 3.10+ 环境下运行,无需额外依赖。 """ -# ruff: noqa: T201, ASYNC101 +# ruff: noqa: T201 import asyncio import json -import re import os +import re from asyncio import create_subprocess_shell, subprocess from pathlib import Path from urllib.request import urlopen @@ -276,7 +276,7 @@ async def run(self): return self._run, self._lines_output - async def command(self, cmd: str, timeout: int = 300) -> tuple[bool, str, str]: + async def command(self, cmd: str, timeout: int = 300) -> tuple[bool, str, str]: # noqa: ASYNC109 """执行命令 Args: diff --git a/tests/conftest.py b/tests/conftest.py index 83ef6cf..880526d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -42,7 +42,7 @@ def load_plugin(nonebug_init: None) -> set["Plugin"]: ) -@pytest.fixture() +@pytest.fixture async def app(app: App, tmp_path: Path, mocker: MockerFixture): from src.plugins.github import plugin_config @@ -117,7 +117,7 @@ def _clear_cache(app: App): check_url.cache_clear() -@pytest.fixture() +@pytest.fixture def mocked_api(respx_mock: MockRouter): respx_mock.get("exception", name="exception").mock(side_effect=httpx.ConnectError) respx_mock.get( diff --git a/tests/github/conftest.py b/tests/github/conftest.py index 0e52ebd..3fce27c 100644 --- a/tests/github/conftest.py +++ b/tests/github/conftest.py @@ -2,7 +2,7 @@ from pytest_mock import MockerFixture -@pytest.fixture() +@pytest.fixture def mock_installation(mocker: MockerFixture): mock_installation = mocker.MagicMock() mock_installation.id = 123 diff --git a/tests/github/publish/utils/test_publish_resolve_conflict_pull_requests.py b/tests/github/publish/utils/test_publish_resolve_conflict_pull_requests.py index fae03a7..df3ee87 100644 --- a/tests/github/publish/utils/test_publish_resolve_conflict_pull_requests.py +++ b/tests/github/publish/utils/test_publish_resolve_conflict_pull_requests.py @@ -1,12 +1,10 @@ -# ruff: noqa: ASYNC101 import json from pathlib import Path from typing import Any - +import pytest from inline_snapshot import snapshot from nonebug import App -import pytest from pytest_mock import MockerFixture from respx import MockRouter @@ -18,7 +16,7 @@ def check_json_data(file: Path, data: Any) -> None: assert json.load(f) == data -@pytest.fixture() +@pytest.fixture def mock_pull(mocker: MockerFixture): mock_pull = mocker.MagicMock() mock_pull.head.ref = "publish/issue1" @@ -31,8 +29,8 @@ async def test_resolve_conflict_pull_requests_adapter( app: App, mocker: MockerFixture, mocked_api: MockRouter, tmp_path: Path, mock_pull ) -> None: from src.plugins.github import plugin_config + from src.plugins.github.models import GithubHandler, RepoInfo from src.plugins.github.plugins.publish.utils import resolve_conflict_pull_requests - from src.plugins.github.models import RepoInfo, GithubHandler mock_subprocess_run = mocker.patch("subprocess.run") mock_result = mocker.MagicMock() @@ -162,8 +160,8 @@ async def test_resolve_conflict_pull_requests_bot( app: App, mocker: MockerFixture, mocked_api: MockRouter, tmp_path: Path, mock_pull ) -> None: from src.plugins.github import plugin_config + from src.plugins.github.models import GithubHandler, RepoInfo from src.plugins.github.plugins.publish.utils import resolve_conflict_pull_requests - from src.plugins.github.models import RepoInfo, GithubHandler mock_subprocess_run = mocker.patch("subprocess.run") mock_result = mocker.MagicMock() @@ -288,8 +286,8 @@ async def test_resolve_conflict_pull_requests_plugin( app: App, mocker: MockerFixture, mocked_api: MockRouter, tmp_path: Path, mock_pull ) -> None: from src.plugins.github import plugin_config + from src.plugins.github.models import GithubHandler, RepoInfo from src.plugins.github.plugins.publish.utils import resolve_conflict_pull_requests - from src.plugins.github.models import RepoInfo, GithubHandler mock_subprocess_run = mocker.patch("subprocess.run") mock_result = mocker.MagicMock() @@ -413,8 +411,8 @@ async def test_resolve_conflict_pull_requests_draft( app: App, mocker: MockerFixture, mocked_api: MockRouter, tmp_path: Path ) -> None: from src.plugins.github import plugin_config + from src.plugins.github.models import GithubHandler, RepoInfo from src.plugins.github.plugins.publish.utils import resolve_conflict_pull_requests - from src.plugins.github.models import RepoInfo, GithubHandler mock_subprocess_run = mocker.patch("subprocess.run") mock_result = mocker.MagicMock() @@ -476,8 +474,8 @@ async def test_resolve_conflict_pull_requests_ref( app: App, mocker: MockerFixture, mocked_api: MockRouter, tmp_path: Path ) -> None: from src.plugins.github import plugin_config + from src.plugins.github.models import GithubHandler, RepoInfo from src.plugins.github.plugins.publish.utils import resolve_conflict_pull_requests - from src.plugins.github.models import RepoInfo, GithubHandler mock_subprocess_run = mocker.patch("subprocess.run") mock_result = mocker.MagicMock() diff --git a/tests/utils/store_test/test_store_test.py b/tests/utils/store_test/test_store_test.py index 7a2d384..8f8c4b2 100644 --- a/tests/utils/store_test/test_store_test.py +++ b/tests/utils/store_test/test_store_test.py @@ -23,7 +23,7 @@ def load_json(name: str) -> dict: return json.load(f) -@pytest.fixture() +@pytest.fixture def mocked_store_data( tmp_path: Path, mocker: MockerFixture,