tests/test_runner_probe.py (1027 bytes)
1 """probe_chapters must never fail a job: the chapter count only scales a progress bar.""" 2 3 from __future__ import annotations 4 5 import subprocess 6 from pathlib import Path 7 8 from backend import runner 9 10 11 def test_no_output_from_ffprobe_counts_as_one_chapter(monkeypatch): 12 # On a Windows machine with a non-UTF-8 code page, the reader thread of 13 # subprocess fails to decode ffprobe's output and leaves stdout as None. 14 # json.loads(None) raises TypeError, which failed the whole job: 15 # "the JSON object must be str, bytes or bytearray, not NoneType". 16 monkeypatch.setattr( 17 subprocess, "run", 18 lambda *a, **k: subprocess.CompletedProcess(a, 0, stdout=None, stderr=None), 19 ) 20 assert runner.probe_chapters(Path("book.mp3")) == 1 21 22 23 def test_chapters_are_counted(monkeypatch): 24 monkeypatch.setattr( 25 subprocess, "run", 26 lambda *a, **k: subprocess.CompletedProcess(a, 0, stdout='{"chapters": [{}, {}, {}]}', stderr=""), 27 ) 28 assert runner.probe_chapters(Path("book.m4b")) == 3