mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-08-14 02:05:13 +08:00
fix tests
This commit is contained in:
@@ -14,7 +14,9 @@ def test_scrape_uses_explicit_media_source_and_id() -> None:
|
||||
chain = Mock()
|
||||
chain.recognize_media.return_value = media_info
|
||||
|
||||
with patch("app.api.endpoints.media.MediaChain", return_value=chain):
|
||||
with patch("app.api.endpoints.media.MediaChain", return_value=chain) as mock_chain:
|
||||
# mkv 非音频文件,需显式关闭 Mock 的 is_audio_path 避免误入音乐分支
|
||||
mock_chain.is_audio_path.return_value = False
|
||||
result = scrape(
|
||||
fileitem=fileitem,
|
||||
storage="alist",
|
||||
@@ -46,7 +48,9 @@ def test_scrape_keeps_automatic_recognition_compatible() -> None:
|
||||
chain = Mock()
|
||||
chain.recognize_by_path.return_value = Context(meta_info=meta_info, media_info=media_info)
|
||||
|
||||
with patch("app.api.endpoints.media.MediaChain", return_value=chain):
|
||||
with patch("app.api.endpoints.media.MediaChain", return_value=chain) as mock_chain:
|
||||
# mkv 非音频文件,需显式关闭 Mock 的 is_audio_path 避免误入音乐分支
|
||||
mock_chain.is_audio_path.return_value = False
|
||||
result = scrape(
|
||||
fileitem=fileitem,
|
||||
storage="alist",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import pytest
|
||||
|
||||
from app.chain.media import MediaChain
|
||||
from app.chain.music import MusicChain
|
||||
from app.core.context import MusicAlbumInfo, MusicInfo
|
||||
from app.core.meta import MetaMusic
|
||||
@@ -177,7 +178,7 @@ def test_recognize_album_directory_skips_single_file(tmp_path, music_chain, monk
|
||||
assert music_chain.recognize_album_directory(album_dir) == {}
|
||||
|
||||
|
||||
def test_recognize_music_by_path_falls_back_to_album_match(tmp_path, music_chain, monkeypatch):
|
||||
def test_recognize_music_by_path_falls_back_to_album_match(tmp_path, monkeypatch):
|
||||
"""单曲识别无远端身份时应用目录级匹配结果兜底。"""
|
||||
album_dir = tmp_path / "周杰伦 - 七里香 (2004)"
|
||||
album_dir.mkdir()
|
||||
@@ -192,16 +193,16 @@ def test_recognize_music_by_path_falls_back_to_album_match(tmp_path, music_chain
|
||||
album="七里香",
|
||||
track_number=1,
|
||||
)
|
||||
# recognize_music_by_path 已下沉至 MediaChain 统一识别入口
|
||||
chain = MediaChain()
|
||||
monkeypatch.setattr(chain, "recognize_media", lambda **kwargs: None)
|
||||
monkeypatch.setattr(
|
||||
music_chain, "recognize_media", lambda **kwargs: None
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
music_chain,
|
||||
"recognize_album_directory",
|
||||
lambda path: {str(file.resolve()): matched_info},
|
||||
chain,
|
||||
"_music_album_dir_fallback",
|
||||
lambda path: matched_info,
|
||||
)
|
||||
|
||||
meta, info = music_chain.recognize_music_by_path(file)
|
||||
meta, info = chain.recognize_music_by_path(file)
|
||||
|
||||
assert info.media_id == "rec-1"
|
||||
assert info.title == "我的地盘"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from app.chain.media import MediaChain
|
||||
from app.chain.music import MusicChain
|
||||
from app.core.context import MusicAlbumInfo, MusicArtistInfo, MusicInfo
|
||||
from app.core.meta import MetaMusic
|
||||
@@ -307,7 +308,7 @@ def test_async_recognize_by_path_reads_local_audio_tags(tmp_path, monkeypatch):
|
||||
album="完美的一天",
|
||||
cover_url="https://coverartarchive.org/release-group/album-1/front-500",
|
||||
)
|
||||
chain = MusicChain()
|
||||
chain = MediaChain()
|
||||
recognize = AsyncMock(return_value=info)
|
||||
monkeypatch.setattr(AudioMetadataHelper, "read", lambda path: meta)
|
||||
monkeypatch.setattr(chain, "async_recognize_media", recognize)
|
||||
|
||||
Reference in New Issue
Block a user