fix(subprocess): log handled tool failures at debug and drop an empty ccextractor output

This commit is contained in:
imSp4rky
2026-12-02 15:57:11 -07:00
parent eeab646272
commit ce0babb4f2
7 changed files with 192 additions and 39 deletions
+19 -5
View File
@@ -13,7 +13,22 @@ from unshackle.core.tracks import Video
from unshackle.core.tracks import video as video_module
def test_retry_runs_on_the_repackaged_file(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
def no_captions_exit(args: list[Any]) -> subprocess.CompletedProcess:
"""ccextractor exits 2 when the input file is missing and 10 when it finds no captions."""
if not Path(args[-1]).exists():
raise subprocess.CalledProcessError(2, args)
raise subprocess.CalledProcessError(10, args)
def empty_output(args: list[Any]) -> subprocess.CompletedProcess:
Path(args[-2]).write_bytes(b"")
return subprocess.CompletedProcess(args, 0, b"", b"")
@pytest.mark.parametrize("ccextractor", [no_captions_exit, empty_output])
def test_no_captions_retries_on_the_repackaged_file(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, ccextractor: Any
) -> None:
original = tmp_path / "v.mp4"
original.write_bytes(b"x")
repacked = tmp_path / "v_repack.mp4"
@@ -27,11 +42,9 @@ def test_retry_runs_on_the_repackaged_file(tmp_path: Path, monkeypatch: pytest.M
inputs: list[Path] = []
def fake_run(args: list[Any], **_: Any) -> None:
def fake_run(args: list[Any], **_: Any) -> subprocess.CompletedProcess:
inputs.append(Path(args[-1]))
if not Path(args[-1]).exists():
raise subprocess.CalledProcessError(2, args) # ccextractor: no input file
raise subprocess.CalledProcessError(10, args) # ccextractor: no captions found
return ccextractor(args)
monkeypatch.setattr(video_module.binaries, "CCExtractor", Path("/usr/bin/ccextractor"))
monkeypatch.setattr(video_module.subprocess, "run", fake_run)
@@ -39,3 +52,4 @@ def test_retry_runs_on_the_repackaged_file(tmp_path: Path, monkeypatch: pytest.M
assert track.ccextractor("cc", tmp_path / "cc.srt", Language.get("en")) is None
assert inputs == [original, repacked]
assert not (tmp_path / "cc.srt").exists()