Spaces:
Running
Running
File size: 2,392 Bytes
8939f6f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | from __future__ import annotations
from pathlib import Path
import pytest
from app.container import build_container
from app.core.exceptions import ProcessingError
from app.models.media import OperationResult
@pytest.mark.asyncio
async def test_output_validation_probes_audio_artifact(settings, tmp_path: Path, monkeypatch) -> None:
container = build_container(settings)
output = tmp_path / "final.mp3"
output.write_bytes(b"audio-placeholder")
async def fake_probe(path: Path):
assert path == output
return {
"duration": 12.5,
"container": "mp3",
"video_streams": [],
"audio_streams": [{"codec": "mp3"}],
"resolution": None,
}
monkeypatch.setattr(container.processor.ffprobe, "probe", fake_probe)
report = await container.processor.validate_output_result(
OperationResult(path=output, filename=output.name, mime_type="audio/mpeg")
)
assert report["valid"] is True
assert report["probed"] is True
assert report["size_bytes"] == output.stat().st_size
assert report["audio_stream_count"] == 1
assert report["duration_seconds"] == 12.5
@pytest.mark.asyncio
async def test_output_validation_rejects_audio_without_audio_stream(settings, tmp_path: Path, monkeypatch) -> None:
container = build_container(settings)
output = tmp_path / "broken.mp3"
output.write_bytes(b"not-real-audio")
async def fake_probe(path: Path):
return {
"duration": 1.0,
"container": "mp3",
"video_streams": [],
"audio_streams": [],
"resolution": None,
}
monkeypatch.setattr(container.processor.ffprobe, "probe", fake_probe)
with pytest.raises(ProcessingError, match="no audio stream"):
await container.processor.validate_output_result(
OperationResult(path=output, filename=output.name, mime_type="audio/mpeg")
)
@pytest.mark.asyncio
async def test_output_validation_rejects_empty_artifact(settings, tmp_path: Path) -> None:
container = build_container(settings)
output = tmp_path / "empty.mp4"
output.write_bytes(b"")
with pytest.raises(ProcessingError, match="empty"):
await container.processor.validate_output_result(
OperationResult(path=output, filename=output.name, mime_type="video/mp4")
)
|