Files
MoviePilot/tests/test_subtitle_rename.py
freeman f3ad81b39e style: apply safe ruff auto-fixes and exempt startup late imports
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>
2026-10-09 13:29:09 +08:00

51 lines
1.8 KiB
Python

from pathlib import Path
from unittest import TestCase
from app.modules.filemanager.transhandler import TransHandler
from app.runtime.config import settings
from app.schemas.file import FileItem
class SubtitleRenameTest(TestCase):
def setUp(self) -> None:
self._default_sub = settings.DEFAULT_SUB
def tearDown(self) -> None:
settings.DEFAULT_SUB = self._default_sub
@staticmethod
def _rename_subtitle(sub_name: str, default_sub: str) -> Path:
"""
直接调用字幕重命名逻辑,覆盖语言标签识别与默认字幕标记。
"""
settings.DEFAULT_SUB = default_sub
sub_item = FileItem(
storage="local",
type="file",
path=f"/source/{sub_name}.srt",
name=sub_name,
extension="srt",
)
target_file = Path("/target/24 Hours.2001.S02E01.[tmdbid=14064].srt")
return TransHandler._TransHandler__rename_subtitles(sub_item, target_file)
def test_traditional_chinese_subtitle_is_not_misclassified_as_simplified(self):
"""
issue #5703: “繁体中文” 不应命中简中兜底规则,也不应被打上默认简中标签。
"""
renamed = self._rename_subtitle("24.Hours.S02E01.繁体中文", default_sub="zh-cn")
self.assertEqual(
renamed.name,
"24 Hours.2001.S02E01.[tmdbid=14064].zh-tw.srt",
)
def test_traditional_chinese_subtitle_can_be_marked_as_default(self):
"""
当默认字幕设置为繁中时,仍应保留正确的繁中语言后缀并追加 default 标记。
"""
renamed = self._rename_subtitle("24.Hours.S02E01.繁体中文", default_sub="zh-tw")
self.assertEqual(
renamed.name,
"24 Hours.2001.S02E01.[tmdbid=14064].default.zh-tw.srt",
)