Ruff Format

This commit is contained in:
DrSmoothl
2026-02-21 16:24:24 +08:00
parent 2cb512120b
commit eaef7f0e98
82 changed files with 1881 additions and 1900 deletions

View File

@@ -46,6 +46,7 @@ def patch_attrdoc_post_init():
config_base_module.logger = logging.getLogger("config_base_test_logger")
class SimpleClass(ConfigBase):
a: int = 1
b: str = "test"
@@ -282,7 +283,7 @@ class TestConfigBase:
True,
"ConfigBase is not Hashable",
id="listset-validation-set-configbase-element_reject",
)
),
],
)
def test_validate_list_set_type(self, annotation, expect_error, error_fragment):
@@ -340,7 +341,7 @@ class TestConfigBase:
False,
None,
id="dict-validation-happy-configbase-value",
)
),
],
)
def test_validate_dict_type(self, annotation, expect_error, error_fragment):
@@ -353,13 +354,11 @@ class TestConfigBase:
field_name = "mapping"
if expect_error:
# Act / Assert
with pytest.raises(TypeError) as exc_info:
dummy._validate_dict_type(annotation, field_name)
assert error_fragment in str(exc_info.value)
else:
# Act
dummy._validate_dict_type(annotation, field_name)
@@ -392,7 +391,7 @@ class TestConfigBase:
# Assert
assert "字段'field_y'中使用了 Any 类型注解" in caplog.text
def test_discourage_any_usage_suppressed_warning(self, caplog):
class Sample(ConfigBase):
_validate_any: bool = False

View File

@@ -4,7 +4,6 @@ import importlib
import pytest
from pathlib import Path
import importlib.util
import asyncio
class DummyLogger:
@@ -71,6 +70,7 @@ class DummyLLMRequest:
async def generate_response_for_image(self, prompt, image_base64, image_format, temp):
return ("dummy description", {})
class DummySelect:
def __init__(self, *a, **k):
pass
@@ -81,6 +81,7 @@ class DummySelect:
def limit(self, n):
return self
@pytest.fixture(autouse=True)
def patch_external_dependencies(monkeypatch):
# Provide dummy implementations as modules so that importing image_manager is safe
@@ -103,11 +104,11 @@ def patch_external_dependencies(monkeypatch):
# Patch MaiImage data model
data_model_mod = types.SimpleNamespace(MaiImage=DummyMaiImage)
monkeypatch.setitem(sys.modules, "src.common.data_models.image_data_model", data_model_mod)
# Patch SQLModel select function
sql_mod = types.SimpleNamespace(select=lambda *a, **k: DummySelect())
monkeypatch.setitem(sys.modules, "sqlmodel", sql_mod)
# Patch config values used at import-time
cfg = types.SimpleNamespace(personality=types.SimpleNamespace(visual_style="test-style"))
model_cfg = types.SimpleNamespace(model_task_config=types.SimpleNamespace(vlm="test-vlm"))
@@ -134,7 +135,7 @@ def _load_image_manager_module(tmp_path=None):
if tmp_path is not None:
tmpdir = Path(tmp_path)
tmpdir.mkdir(parents=True, exist_ok=True)
setattr(mod, "IMAGE_DIR", tmpdir)
mod.IMAGE_DIR = tmpdir
except Exception:
pass
return mod
@@ -197,4 +198,3 @@ async def test_save_image_and_process_and_cleanup(tmp_path):
# cleanup should run without error
mgr.cleanup_invalid_descriptions_in_db()

View File

@@ -1,5 +1,3 @@
import pytest
from src.config.official_configs import ChatConfig
from src.config.config import Config
from src.webui.config_schema import ConfigSchemaGenerator

View File

@@ -1,6 +1,5 @@
"""Expression routes pytest tests"""
from datetime import datetime
from typing import Generator
from unittest.mock import MagicMock
@@ -12,7 +11,6 @@ from sqlalchemy import text
from sqlmodel import Session, SQLModel, create_engine, select
from src.common.database.database_model import Expression
from src.common.database.database import get_db_session
def create_test_app() -> FastAPI: