Spaces:
Runtime error
Runtime error
Test final template output validation
Browse files- tests/test_templates.py +45 -1
tests/test_templates.py
CHANGED
|
@@ -9,7 +9,7 @@ from fastapi.testclient import TestClient
|
|
| 9 |
from app.container import build_container
|
| 10 |
from app.core.exceptions import TemplateValidationError
|
| 11 |
from app.models.media import InputMedia, MediaSource, ResolvedRequest
|
| 12 |
-
from app.templates.executor import OPERATION_BINDINGS
|
| 13 |
from app.templates.loader import TemplateLoader
|
| 14 |
from app.templates.registry import TemplateRegistry
|
| 15 |
from app.templates.validator import TemplateValidator
|
|
@@ -289,3 +289,47 @@ def test_voiceover_music_ducking_template_uses_two_original_inputs(settings) ->
|
|
| 289 |
assert prepared.pipeline[0].inputs == ["original", "original:1"]
|
| 290 |
assert prepared.pipeline[0].parameters["music_volume"] == 0.22
|
| 291 |
assert prepared.output.format == "mp4"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
from app.container import build_container
|
| 10 |
from app.core.exceptions import TemplateValidationError
|
| 11 |
from app.models.media import InputMedia, MediaSource, ResolvedRequest
|
| 12 |
+
from app.templates.executor import OPERATION_BINDINGS, TemplateExecutor
|
| 13 |
from app.templates.loader import TemplateLoader
|
| 14 |
from app.templates.registry import TemplateRegistry
|
| 15 |
from app.templates.validator import TemplateValidator
|
|
|
|
| 289 |
assert prepared.pipeline[0].inputs == ["original", "original:1"]
|
| 290 |
assert prepared.pipeline[0].parameters["music_volume"] == 0.22
|
| 291 |
assert prepared.output.format == "mp4"
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
def test_final_output_validation_reports_media_metadata(settings, tmp_path: Path) -> None:
|
| 295 |
+
output = tmp_path / "final.mp3"
|
| 296 |
+
output.write_bytes(b"non-empty-output")
|
| 297 |
+
media = InputMedia(
|
| 298 |
+
source=MediaSource.LOCAL_PATH,
|
| 299 |
+
filename=output.name,
|
| 300 |
+
mime_type="audio/mpeg",
|
| 301 |
+
temp_path=output,
|
| 302 |
+
size=output.stat().st_size,
|
| 303 |
+
duration=12.5,
|
| 304 |
+
metadata={
|
| 305 |
+
"duration": 12.5,
|
| 306 |
+
"container": "mp3",
|
| 307 |
+
"audio_streams": [{"codec": "mp3"}],
|
| 308 |
+
"video_streams": [],
|
| 309 |
+
"resolution": None,
|
| 310 |
+
},
|
| 311 |
+
)
|
| 312 |
+
|
| 313 |
+
report = TemplateExecutor._output_validation(media)
|
| 314 |
+
|
| 315 |
+
assert report["valid"] is True
|
| 316 |
+
assert report["size_bytes"] == output.stat().st_size
|
| 317 |
+
assert report["duration_seconds"] == 12.5
|
| 318 |
+
assert report["audio_stream_count"] == 1
|
| 319 |
+
assert report["video_stream_count"] == 0
|
| 320 |
+
|
| 321 |
+
|
| 322 |
+
def test_final_output_validation_rejects_empty_artifact(settings, tmp_path: Path) -> None:
|
| 323 |
+
output = tmp_path / "empty.mp3"
|
| 324 |
+
output.write_bytes(b"")
|
| 325 |
+
media = InputMedia(
|
| 326 |
+
source=MediaSource.LOCAL_PATH,
|
| 327 |
+
filename=output.name,
|
| 328 |
+
mime_type="audio/mpeg",
|
| 329 |
+
temp_path=output,
|
| 330 |
+
size=0,
|
| 331 |
+
)
|
| 332 |
+
prepared = build_container(settings).template_registry.prepare("mp3@1", {})
|
| 333 |
+
|
| 334 |
+
with pytest.raises(Exception, match="empty"):
|
| 335 |
+
TemplateExecutor._validate_output(prepared, media)
|