forked from kenzuya/unshackle
test(music): skip an FFmpeg test when the FFmpeg build has no encoder for its input
This commit is contained in:
@@ -17,7 +17,7 @@ from pathlib import Path
|
|||||||
import mutagen
|
import mutagen
|
||||||
import pytest
|
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 import binaries
|
||||||
from unshackle.core.music.tagger import write_music_metadata
|
from unshackle.core.music.tagger import write_music_metadata
|
||||||
from unshackle.core.tracks import Audio
|
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:
|
def encode(path: Path, encoder: str, *extra_args: str) -> Path:
|
||||||
subprocess.run(
|
ffmpeg(
|
||||||
[
|
[
|
||||||
"ffmpeg",
|
"ffmpeg",
|
||||||
"-nostdin",
|
"-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
|
"-2", # flac and opus in mp4 are flagged experimental by the muxer
|
||||||
*extra_args,
|
*extra_args,
|
||||||
str(path),
|
str(path),
|
||||||
],
|
]
|
||||||
check=True,
|
|
||||||
)
|
)
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,15 @@ from unshackle.core.tracks import Attachment
|
|||||||
|
|
||||||
pytestmark = pytest.mark.skipif(shutil.which("ffmpeg") is None, reason="requires ffmpeg")
|
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
|
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")):
|
for suffix, encoder in ((".flac", "flac"), (".ogg", "libvorbis"), (".mp3", "libmp3lame"), (".m4a", "aac")):
|
||||||
path = tmp_path / f"track{suffix}"
|
path = tmp_path / f"track{suffix}"
|
||||||
subprocess.run(
|
ffmpeg(
|
||||||
[
|
[
|
||||||
"ffmpeg",
|
"ffmpeg",
|
||||||
"-nostdin",
|
"-nostdin",
|
||||||
@@ -138,8 +147,7 @@ def test_lyrics_land_in_the_container_field_players_read(tmp_path: Path) -> None
|
|||||||
"-c:a",
|
"-c:a",
|
||||||
encoder,
|
encoder,
|
||||||
str(path),
|
str(path),
|
||||||
],
|
]
|
||||||
check=True,
|
|
||||||
)
|
)
|
||||||
assert write_music_metadata(path, song).written
|
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:
|
def test_a_webp_cover_is_embedded_as_jpeg(tmp_path: Path) -> None:
|
||||||
webp = tmp_path / "cover.webp"
|
webp = tmp_path / "cover.webp"
|
||||||
subprocess.run(
|
ffmpeg(["ffmpeg", "-nostdin", "-v", "error", "-f", "lavfi", "-i", "color=red:s=16x16", "-frames:v", "1", str(webp)])
|
||||||
["ffmpeg", "-nostdin", "-v", "error", "-f", "lavfi", "-i", "color=red:s=16x16", "-frames:v", "1", str(webp)],
|
|
||||||
check=True,
|
|
||||||
)
|
|
||||||
m4a = tmp_path / "track.m4a"
|
m4a = tmp_path / "track.m4a"
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
["ffmpeg", "-nostdin", "-v", "error", "-f", "lavfi", "-i", "anullsrc", "-t", "0.2", "-c:a", "aac", str(m4a)],
|
["ffmpeg", "-nostdin", "-v", "error", "-f", "lavfi", "-i", "anullsrc", "-t", "0.2", "-c:a", "aac", str(m4a)],
|
||||||
|
|||||||
Reference in New Issue
Block a user