mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-10-29 03:18:14 +08:00
Run `ruff check app tests scripts --fix` with the configured rule set (E4/E7/E9/F/I): import sorting (I001), f-strings without placeholders (F541), lambda/variable/unused-import cleanups that ruff marks safe. Nine files whose only ruff debt sits next to pre-existing pylint import-resolution errors (lazy exports, sys.path script imports) or whose "unused" imports are reached through attribute access by tests are left untouched so the changed-file pylint gate and the benchmark tests stay green; their diagnostics remain in the baseline. app/startup/lifecycle/__init__.py and app/main.py import business modules after cache composition, import-path and stdio setup on purpose (the source comments document the contract), so declare E402 per-file-ignores for them instead of adding per-line noqa. Ruff ratchet watermark drops from 498 to 100; sync the baseline fixture and the optimization checklist figure. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
"""验证插件仓测试引导复现生产运行时的插件导入命名空间。"""
|
|
|
|
import sys
|
|
from importlib import import_module
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from app.testing import bootstrap
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("prepare_name", "source_dir"),
|
|
(
|
|
("prepare_v1_backend", "plugins"),
|
|
("prepare_v2_backend", "plugins.v2"),
|
|
("prepare_v3_backend", "plugins.v3"),
|
|
),
|
|
)
|
|
def test_prepare_plugin_backend_exposes_runtime_namespace(
|
|
tmp_path: Path,
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
prepare_name: str,
|
|
source_dir: str,
|
|
) -> None:
|
|
"""市场仓源码只通过 ``app.plugins.<id>`` 规范身份导入。"""
|
|
plugin_id = f"namespace_probe_{source_dir.replace('.', '_')}"
|
|
plugin_dir = tmp_path / source_dir / plugin_id
|
|
plugin_dir.mkdir(parents=True)
|
|
(plugin_dir / "__init__.py").write_text(
|
|
f"PLUGIN_ID = {plugin_id!r}\n",
|
|
encoding="utf-8",
|
|
)
|
|
|
|
plugins_package = import_module("app.plugins")
|
|
monkeypatch.setattr(plugins_package, "__path__", list(plugins_package.__path__))
|
|
monkeypatch.setattr(bootstrap, "prepare_backend", lambda: None)
|
|
|
|
runtime_name = f"app.plugins.{plugin_id}"
|
|
try:
|
|
getattr(bootstrap, prepare_name)(tmp_path)
|
|
|
|
runtime = import_module(runtime_name)
|
|
|
|
assert Path(runtime.__file__).resolve() == plugin_dir / "__init__.py"
|
|
with pytest.raises(ModuleNotFoundError):
|
|
import_module(plugin_id)
|
|
finally:
|
|
sys.modules.pop(runtime_name, None)
|