feat(music-lab): pipeline 영상·썸네일 생성
This commit is contained in:
66
music-lab/tests/test_video_thumb.py
Normal file
66
music-lab/tests/test_video_thumb.py
Normal file
@@ -0,0 +1,66 @@
|
||||
import os
|
||||
import pytest
|
||||
from unittest.mock import patch, MagicMock
|
||||
from app.pipeline import video, thumb, storage
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def tmp_storage(monkeypatch, tmp_path):
|
||||
monkeypatch.setattr(storage, "VIDEO_DATA_DIR", str(tmp_path))
|
||||
# 더미 입력 파일들
|
||||
audio = tmp_path / "audio.mp3"
|
||||
audio.write_bytes(b"\x00" * 100)
|
||||
cover_dir = tmp_path / "50"
|
||||
cover_dir.mkdir()
|
||||
cover = cover_dir / "cover.jpg"
|
||||
cover.write_bytes(b"\x00" * 100)
|
||||
return tmp_path
|
||||
|
||||
|
||||
@patch("subprocess.run")
|
||||
def test_generate_video_calls_ffmpeg(mock_run, tmp_storage):
|
||||
mock_run.return_value = MagicMock(returncode=0, stderr="")
|
||||
out = video.generate(pipeline_id=50, audio_path=str(tmp_storage / "audio.mp3"),
|
||||
cover_path=str(tmp_storage / "50" / "cover.jpg"),
|
||||
genre="lo-fi", duration_sec=120, resolution="1920x1080",
|
||||
style="visualizer")
|
||||
assert out["url"].endswith("/50/video.mp4")
|
||||
assert out["used_fallback"] is False
|
||||
args = mock_run.call_args[0][0]
|
||||
assert args[0] == "ffmpeg"
|
||||
assert "-i" in args
|
||||
assert "showwaves" in " ".join(args)
|
||||
|
||||
|
||||
@patch("subprocess.run")
|
||||
def test_generate_video_failure_marks_failed(mock_run, tmp_storage):
|
||||
mock_run.return_value = MagicMock(returncode=1, stderr="bad codec")
|
||||
with pytest.raises(video.VideoGenerationError):
|
||||
video.generate(pipeline_id=51, audio_path=str(tmp_storage / "audio.mp3"),
|
||||
cover_path=str(tmp_storage / "50" / "cover.jpg"),
|
||||
genre="lo-fi", duration_sec=120, resolution="1920x1080",
|
||||
style="visualizer")
|
||||
|
||||
|
||||
@patch("subprocess.run")
|
||||
def test_thumb_extracts_frame(mock_run, tmp_storage):
|
||||
mock_run.return_value = MagicMock(returncode=0, stderr="")
|
||||
video_path = tmp_storage / "60" / "video.mp4"
|
||||
video_path.parent.mkdir()
|
||||
video_path.write_bytes(b"\x00" * 100)
|
||||
out = thumb.generate(pipeline_id=60, video_path=str(video_path),
|
||||
track_title="Midnight Drive", overlay_text=False)
|
||||
assert out["url"].endswith("/60/thumbnail.jpg")
|
||||
args = mock_run.call_args[0][0]
|
||||
assert args[0] == "ffmpeg"
|
||||
|
||||
|
||||
@patch("subprocess.run")
|
||||
def test_thumb_failure_raises(mock_run, tmp_storage):
|
||||
mock_run.return_value = MagicMock(returncode=1, stderr="bad input")
|
||||
video_path = tmp_storage / "61" / "video.mp4"
|
||||
video_path.parent.mkdir()
|
||||
video_path.write_bytes(b"\x00" * 100)
|
||||
with pytest.raises(thumb.ThumbGenerationError):
|
||||
thumb.generate(pipeline_id=61, video_path=str(video_path),
|
||||
track_title="X", overlay_text=False)
|
||||
Reference in New Issue
Block a user