feat: Zeitraum-Auswahl (-s/-e) in vtt2txt.py
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
3d9a5037c2
commit
1668a8dcad
1 changed files with 159 additions and 15 deletions
|
|
@ -162,3 +162,66 @@ def test_cli_errors(sample_copy, monkeypatch, capsys, args, message):
|
|||
run_main(monkeypatch, *args)
|
||||
assert exc.value.code == 2
|
||||
assert message in capsys.readouterr().err
|
||||
|
||||
|
||||
@pytest.mark.parametrize("text, seconds", [
|
||||
("00:03:17", 197), ("3:17", 197), ("197", 197), ("00:03:17.5", 197.5),
|
||||
("00:03:17,5", 197.5), ("1:02:03", 3723),
|
||||
])
|
||||
def test_parse_time(text, seconds):
|
||||
assert vtt2txt.parse_time(text) == seconds
|
||||
|
||||
|
||||
@pytest.mark.parametrize("text", ["", "abc", "1:2:3:4", "-5"])
|
||||
def test_parse_time_rejects_invalid(text):
|
||||
with pytest.raises(ValueError):
|
||||
vtt2txt.parse_time(text)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("start, end, suffix", [
|
||||
(None, None, ""),
|
||||
(197, 325, "_00-03-17_bis_00-05-25"),
|
||||
(197, None, "_ab_00-03-17"),
|
||||
(None, 325, "_bis_00-05-25"),
|
||||
])
|
||||
def test_time_suffix(start, end, suffix):
|
||||
assert vtt2txt.time_suffix(start, end) == suffix
|
||||
|
||||
|
||||
def test_vtt_to_lines_time_range():
|
||||
vtt = "WEBVTT\n\n" + cue(1, "A") + cue(2, "A", "B") + cue(3, "B", "C") + cue(4, "C", "D")
|
||||
assert vtt2txt.vtt_to_lines(vtt, start=2, end=4) == ["B", "C"]
|
||||
assert vtt2txt.vtt_to_lines(vtt, start=3) == ["C", "D"]
|
||||
assert vtt2txt.vtt_to_lines(vtt, end=2) == ["A"]
|
||||
|
||||
|
||||
def test_vtt_to_lines_time_range_skips_window_from_before_start():
|
||||
# "B" was said before the range; its repetition in the first cue must not count
|
||||
vtt = "WEBVTT\n\n" + cue(1, "A", "B") + cue(2, "B", "C")
|
||||
assert vtt2txt.vtt_to_lines(vtt, start=2) == ["C"]
|
||||
|
||||
|
||||
def test_main_time_range_default_name(sample_copy, monkeypatch):
|
||||
run_main(monkeypatch, "-i", sample_copy, "-s", "0:30", "-e", "1:00")
|
||||
target = sample_copy.with_name("ramstein.de_00-00-30_bis_00-01-00.txt")
|
||||
full = SAMPLE_TXT.read_text(encoding="utf-8").splitlines()
|
||||
part = target.read_text(encoding="utf-8").splitlines()
|
||||
assert 0 < len(part) < len(full)
|
||||
|
||||
|
||||
def test_main_time_range_without_captions(sample_copy, monkeypatch, capsys):
|
||||
with pytest.raises(SystemExit) as exc:
|
||||
run_main(monkeypatch, "-i", sample_copy, "-s", "99:00:00")
|
||||
assert exc.value.code == 1
|
||||
assert "im gewählten Zeitraum" in capsys.readouterr().err
|
||||
|
||||
|
||||
@pytest.mark.parametrize("args, message", [
|
||||
(["-s", "abc"], "ungültige Zeit"),
|
||||
(["-s", "1:00", "-e", "0:30"], "muss vor -e/--ende liegen"),
|
||||
])
|
||||
def test_cli_time_errors(sample_copy, monkeypatch, capsys, args, message):
|
||||
with pytest.raises(SystemExit) as exc:
|
||||
run_main(monkeypatch, "-i", sample_copy, *args)
|
||||
assert exc.value.code == 2
|
||||
assert message in capsys.readouterr().err
|
||||
|
|
|
|||
Loading…
Reference in a new issue