test(music): skip an FFmpeg test when the FFmpeg build has no encoder for its input

This commit is contained in:
imSp4rky
2026-11-29 12:20:56 -07:00
parent 59586e60d4
commit 90dfe1c7bd
2 changed files with 15 additions and 11 deletions
+3 -4
View File
@@ -17,7 +17,7 @@ from pathlib import Path
import mutagen
import pytest
from tests.core.test_music_tagger_roundtrip import make_song
from tests.core.test_music_tagger_roundtrip import ffmpeg, make_song
from unshackle.core import binaries
from unshackle.core.music.tagger import write_music_metadata
from unshackle.core.tracks import Audio
@@ -26,7 +26,7 @@ pytestmark = pytest.mark.skipif(shutil.which("ffmpeg") is None, reason="requires
def encode(path: Path, encoder: str, *extra_args: str) -> Path:
subprocess.run(
ffmpeg(
[
"ffmpeg",
"-nostdin",
@@ -46,8 +46,7 @@ def encode(path: Path, encoder: str, *extra_args: str) -> Path:
"-2", # flac and opus in mp4 are flagged experimental by the muxer
*extra_args,
str(path),
],
check=True,
]
)
return path
+12 -7
View File
@@ -25,6 +25,15 @@ from unshackle.core.tracks import Attachment
pytestmark = pytest.mark.skipif(shutil.which("ffmpeg") is None, reason="requires ffmpeg")
def ffmpeg(args: list[str]) -> None:
"""Run FFmpeg to build a test input, or skip the test when this FFmpeg build has no encoder for it."""
run = subprocess.run(args, capture_output=True, text=True, encoding="utf-8", errors="replace")
if run.returncode and "Encoder not found" in run.stderr:
pytest.skip(f"ffmpeg has no encoder for {args[-1].rsplit('.', 1)[-1]}")
run.check_returncode()
PNG_STUB = b"\x89PNG\r\n\x1a\n" + b"\x00" * 16 # magic only; Pillow dimension probing soft-fails
@@ -123,7 +132,7 @@ def test_lyrics_land_in_the_container_field_players_read(tmp_path: Path) -> None
for suffix, encoder in ((".flac", "flac"), (".ogg", "libvorbis"), (".mp3", "libmp3lame"), (".m4a", "aac")):
path = tmp_path / f"track{suffix}"
subprocess.run(
ffmpeg(
[
"ffmpeg",
"-nostdin",
@@ -138,8 +147,7 @@ def test_lyrics_land_in_the_container_field_players_read(tmp_path: Path) -> None
"-c:a",
encoder,
str(path),
],
check=True,
]
)
assert write_music_metadata(path, song).written
@@ -213,10 +221,7 @@ def test_an_image_attachment_is_the_cover_when_the_song_gives_no_artwork_url(fla
def test_a_webp_cover_is_embedded_as_jpeg(tmp_path: Path) -> None:
webp = tmp_path / "cover.webp"
subprocess.run(
["ffmpeg", "-nostdin", "-v", "error", "-f", "lavfi", "-i", "color=red:s=16x16", "-frames:v", "1", str(webp)],
check=True,
)
ffmpeg(["ffmpeg", "-nostdin", "-v", "error", "-f", "lavfi", "-i", "color=red:s=16x16", "-frames:v", "1", str(webp)])
m4a = tmp_path / "track.m4a"
subprocess.run(
["ffmpeg", "-nostdin", "-v", "error", "-f", "lavfi", "-i", "anullsrc", "-t", "0.2", "-c:a", "aac", str(m4a)],