Spaces:
Running
Running
Download tests/test_output_validation.py from basyx/MediaRouter: direct link, hf CLI and curl.
- Browser
- Download file 2.39 kB
-
https://huggingface.co/spaces/basyx/MediaRouter/resolve/main/tests/test_output_validation.py
- Command line
-
hf download hf://spaces/basyx/MediaRouter/tests/test_output_validation.py
-
curl -L -o test_output_validation.py https://huggingface.co/spaces/basyx/MediaRouter/resolve/main/tests/test_output_validation.py
2.39 kB
| 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 | |
| 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 | |
| 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") | |
| ) | |
| 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") | |
| ) | |