|
2 | 2 |
|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
| 5 | +import subprocess |
5 | 6 | from pathlib import Path |
6 | 7 |
|
7 | 8 | import pytest |
@@ -71,3 +72,45 @@ def test_concat_builder_rejects_integer_segment_id() -> None: |
71 | 72 | ) |
72 | 73 | with pytest.raises(ConcatError, match="quoted string segment id"): |
73 | 74 | ConcatBuilder(cfg).build() # type: ignore[arg-type] |
| 75 | + |
| 76 | + |
| 77 | +def _seed_recordings(tmp_path: Path) -> None: |
| 78 | + rec = tmp_path / "recordings" |
| 79 | + rec.mkdir() |
| 80 | + (rec / "01-a.mp4").write_bytes(b"seg-a") |
| 81 | + (rec / "02-b.mp4").write_bytes(b"seg-b") |
| 82 | + |
| 83 | + |
| 84 | +def test_concat_ffmpeg_timeout_removes_incomplete_output( |
| 85 | + tmp_path: Path, monkeypatch: pytest.MonkeyPatch |
| 86 | +) -> None: |
| 87 | + cfg = _cfg(tmp_path, {"full": ["01", "02"]}) |
| 88 | + _seed_recordings(tmp_path) |
| 89 | + out = tmp_path / "recordings" / "full.mp4" |
| 90 | + out.write_bytes(b"partial-concat") |
| 91 | + |
| 92 | + def fake_run(cmd, **_kwargs): |
| 93 | + raise subprocess.TimeoutExpired(cmd=cmd, timeout=300) |
| 94 | + |
| 95 | + monkeypatch.setattr(subprocess, "run", fake_run) |
| 96 | + with pytest.raises(ConcatError, match="removed incomplete full.mp4"): |
| 97 | + ConcatBuilder(cfg).build(name="full") |
| 98 | + assert not out.exists() |
| 99 | + assert not list((tmp_path / "recordings").glob(".concat-*.txt")) |
| 100 | + |
| 101 | + |
| 102 | +def test_concat_ffmpeg_failure_removes_incomplete_output( |
| 103 | + tmp_path: Path, monkeypatch: pytest.MonkeyPatch |
| 104 | +) -> None: |
| 105 | + cfg = _cfg(tmp_path, {"full": ["01", "02"]}) |
| 106 | + _seed_recordings(tmp_path) |
| 107 | + out = tmp_path / "recordings" / "full.mp4" |
| 108 | + out.write_bytes(b"partial-concat") |
| 109 | + |
| 110 | + def fake_run(cmd, **_kwargs): |
| 111 | + raise subprocess.CalledProcessError(1, cmd, stderr="mux error") |
| 112 | + |
| 113 | + monkeypatch.setattr(subprocess, "run", fake_run) |
| 114 | + with pytest.raises(ConcatError, match="ffmpeg failed"): |
| 115 | + ConcatBuilder(cfg).build(name="full") |
| 116 | + assert not out.exists() |
0 commit comments