feat: Zeitraum-Auswahl (-s/-e) auch in rede_korrigieren.py und extract_text.py
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
1668a8dcad
commit
82489ee83c
2 changed files with 111 additions and 17 deletions
|
|
@ -125,3 +125,25 @@ def test_cli_errors(tmp_path, monkeypatch, capsys, args, message):
|
|||
run_main(monkeypatch, *args)
|
||||
assert exc.value.code == 2
|
||||
assert message in capsys.readouterr().err
|
||||
|
||||
|
||||
def test_time_range_default_name(fake_yt_dlp, tmp_path, monkeypatch):
|
||||
monkeypatch.setattr(yt.subprocess, "run", fake_yt_dlp(GERMAN_VIDEO, vtt=VTT))
|
||||
monkeypatch.chdir(tmp_path)
|
||||
run_main(monkeypatch, "-u", URL, "-s", "2", "-e", "0:03")
|
||||
|
||||
name = "Kanal_Eine_Rede_2026-03-28_00-00-02_bis_00-00-03.txt"
|
||||
assert (tmp_path / name).read_text(encoding="utf-8") == "Schön, dass Sie da sind.\n"
|
||||
|
||||
|
||||
def test_time_range_without_text(fake_yt_dlp, tmp_path, monkeypatch):
|
||||
monkeypatch.setattr(yt.subprocess, "run", fake_yt_dlp(GERMAN_VIDEO, vtt=VTT))
|
||||
with pytest.raises(SystemExit, match="im gewählten Zeitraum keinen Text"):
|
||||
run_main(monkeypatch, "-u", URL, "-s", "1:00", "-o", tmp_path / "out.txt")
|
||||
|
||||
|
||||
def test_time_range_order_error(monkeypatch, capsys):
|
||||
with pytest.raises(SystemExit) as exc:
|
||||
run_main(monkeypatch, "-u", URL, "-s", "2:00", "-e", "1:00")
|
||||
assert exc.value.code == 2
|
||||
assert "muss vor -e/--ende liegen" in capsys.readouterr().err
|
||||
|
|
|
|||
|
|
@ -517,3 +517,52 @@ 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
|
||||
|
||||
|
||||
# === Time range (-s/-e) ===
|
||||
|
||||
def test_main_url_time_range_default_names(from_url, tmp_path, monkeypatch):
|
||||
monkeypatch.chdir(tmp_path)
|
||||
run_main(monkeypatch, "-u", URL, "-s", "0:02")
|
||||
|
||||
name = "Kanal_Rede_2026-03-28_ab_00-00-02"
|
||||
raw = (tmp_path / f"{name}.txt").read_text(encoding="utf-8")
|
||||
assert raw == "Das ist bekannt.\n"
|
||||
assert (tmp_path / f"{name}.korrigiert.txt").is_file()
|
||||
|
||||
|
||||
def test_main_url_time_range_without_text(from_url, tmp_path, monkeypatch):
|
||||
with pytest.raises(SystemExit, match="im gewählten Zeitraum keinen Text"):
|
||||
run_main(monkeypatch, "-u", URL, "-s", "1:00", "-o", tmp_path / "x.korrigiert.txt")
|
||||
|
||||
|
||||
def test_main_vtt_time_range(tmp_path, monkeypatch):
|
||||
vtt = tmp_path / "rede.de.vtt"
|
||||
vtt.write_text(VTT, encoding="utf-8")
|
||||
monkeypatch.setattr(rk, "correct_chunk", identity_correct)
|
||||
monkeypatch.setattr(rk, "find_paragraph_starts", every_nth_start(5))
|
||||
run_main(monkeypatch, "-i", vtt, "-e", "2")
|
||||
|
||||
result = tmp_path / "rede.de_bis_00-00-02.korrigiert.txt"
|
||||
assert result.read_text(encoding="utf-8") == "Der Kremmel ist in Moskau.\n"
|
||||
|
||||
|
||||
def test_main_vtt_time_range_without_text(tmp_path, monkeypatch):
|
||||
vtt = tmp_path / "rede.de.vtt"
|
||||
vtt.write_text(VTT, encoding="utf-8")
|
||||
monkeypatch.setattr(rk, "correct_chunk", no_model_calls)
|
||||
with pytest.raises(SystemExit, match="im gewählten Zeitraum keinen Text"):
|
||||
run_main(monkeypatch, "-i", vtt, "-s", "1:00")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("args, message", [
|
||||
(["-i", "{sample}", "-s", "1:00"], "nur mit .vtt-Eingabe oder -u"),
|
||||
(["-i", "{sample}", "-s", "x"], "ungültige Zeit"),
|
||||
(["-i", "{sample}", "-s", "2:00", "-e", "1:00"], "muss vor -e/--ende liegen"),
|
||||
])
|
||||
def test_cli_time_errors(sample_copy, monkeypatch, capsys, args, message):
|
||||
args = [a.format(sample=sample_copy) for a in args]
|
||||
with pytest.raises(SystemExit) as exc:
|
||||
run_main(monkeypatch, *args)
|
||||
assert exc.value.code == 2
|
||||
assert message in capsys.readouterr().err
|
||||
|
|
|
|||
Loading…
Reference in a new issue