From 90dfe1c7bd7b2e0f664cba7994e1fcb1f23c37de Mon Sep 17 00:00:00 2001 From: imSp4rky Date: Sun, 29 Nov 2026 12:20:56 -0700 Subject: [PATCH] test(music): skip an FFmpeg test when the FFmpeg build has no encoder for its input --- tests/core/test_music_container.py | 7 +++---- tests/core/test_music_tagger_roundtrip.py | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/tests/core/test_music_container.py b/tests/core/test_music_container.py index 188d576c..8e154a54 100644 --- a/tests/core/test_music_container.py +++ b/tests/core/test_music_container.py @@ -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 diff --git a/tests/core/test_music_tagger_roundtrip.py b/tests/core/test_music_tagger_roundtrip.py index eb2cc288..db417754 100644 --- a/tests/core/test_music_tagger_roundtrip.py +++ b/tests/core/test_music_tagger_roundtrip.py @@ -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)],