test: eigene Beispielrede statt echter Reden, testdaten/ nur noch lokal
Die Abschriften echter Reden sind urheberrechtlich geschützt und gehören nicht in ein öffentliches Repository. Die Tests nutzen jetzt eine frei erfundene Festrede (tests/daten/beispiel.de.vtt/.txt, YouTube-Format mit rollendem Fenster) mit eigenem Glossar. testdaten/ steht in .gitignore; liegen die Reden dort lokal, laufen die Tests ihrer Glossare zusätzlich, sonst werden sie übersprungen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
0106c307e7
commit
93fb99eda2
1 changed files with 3134 additions and 62 deletions
|
|
@ -8,8 +8,10 @@ import pytest
|
|||
import vtt2txt
|
||||
|
||||
REPO = Path(__file__).resolve().parent.parent
|
||||
SAMPLE_VTT = REPO / "testdaten" / "ramstein.de.vtt"
|
||||
SAMPLE_TXT = REPO / "testdaten" / "ramstein.de.txt"
|
||||
# Own, made-up sample speech; real speeches are only kept locally in testdaten/
|
||||
SAMPLE_VTT = REPO / "tests" / "daten" / "beispiel.de.vtt"
|
||||
SAMPLE_TXT = REPO / "tests" / "daten" / "beispiel.de.txt"
|
||||
SPEECHES = REPO / "testdaten"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
@ -107,15 +109,27 @@ def test_is_rolling(cues, expected):
|
|||
|
||||
def test_main_default_output_matches_sample(sample_copy, monkeypatch, capsys):
|
||||
run_main(monkeypatch, "-i", sample_copy)
|
||||
target = sample_copy.with_name("ramstein.de.txt")
|
||||
target = sample_copy.with_name("beispiel.de.txt")
|
||||
assert target.read_text(encoding="utf-8") == SAMPLE_TXT.read_text(encoding="utf-8")
|
||||
assert f"Erstellt: {target}" in capsys.readouterr().out
|
||||
|
||||
|
||||
@pytest.mark.parametrize("name", ["ramstein.de", "magdeburg.de-orig", "Lahnstein.de-orig"])
|
||||
def test_sample_vtt_gives_sample_txt(name):
|
||||
vtt = (REPO / "testdaten" / f"{name}.vtt").read_text(encoding="utf-8-sig")
|
||||
txt = (REPO / "testdaten" / f"{name}.txt").read_text(encoding="utf-8")
|
||||
def speech(name):
|
||||
"""A real speech, only kept locally (copyright): skipped without it."""
|
||||
path = SPEECHES / name
|
||||
return pytest.param(path, marks=pytest.mark.skipif(
|
||||
not path.is_file(), reason="echte Reden nur lokal in testdaten/"
|
||||
))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("vtt_path", [
|
||||
SAMPLE_VTT,
|
||||
speech("ramstein.de.vtt"), speech("magdeburg.de-orig.vtt"),
|
||||
speech("Lahnstein.de-orig.vtt"),
|
||||
])
|
||||
def test_sample_vtt_gives_sample_txt(vtt_path):
|
||||
vtt = vtt_path.read_text(encoding="utf-8-sig")
|
||||
txt = vtt_path.with_suffix(".txt").read_text(encoding="utf-8")
|
||||
assert vtt2txt.vtt_to_lines(vtt) == txt.splitlines()
|
||||
|
||||
|
||||
|
|
@ -128,9 +142,9 @@ def test_main_multiple_inputs(sample_copy, monkeypatch):
|
|||
|
||||
|
||||
def test_main_expands_glob_without_duplicates(sample_copy, monkeypatch, capsys):
|
||||
shutil.copy(sample_copy, sample_copy.with_name("ramstein.en.vtt"))
|
||||
shutil.copy(sample_copy, sample_copy.with_name("beispiel.en.vtt"))
|
||||
shutil.copy(sample_copy, sample_copy.with_name("anders.de.vtt"))
|
||||
run_main(monkeypatch, "-i", sample_copy.parent / "ramstein.*.vtt", sample_copy)
|
||||
run_main(monkeypatch, "-i", sample_copy.parent / "beispiel.*.vtt", sample_copy)
|
||||
out = capsys.readouterr().out
|
||||
assert out.count("Erstellt:") == 2
|
||||
assert not sample_copy.with_name("anders.de.txt").exists()
|
||||
|
|
@ -144,7 +158,7 @@ def test_main_output_directory(sample_copy, monkeypatch, make_dir, suffix):
|
|||
if make_dir:
|
||||
out_dir.mkdir()
|
||||
run_main(monkeypatch, "-i", sample_copy, second, "-o", f"{out_dir}{suffix}")
|
||||
assert (out_dir / "ramstein.de.txt").is_file()
|
||||
assert (out_dir / "beispiel.de.txt").is_file()
|
||||
assert (out_dir / "rede.en.txt").is_file()
|
||||
|
||||
|
||||
|
|
@ -176,7 +190,7 @@ def test_main_bad_file_continues_batch(sample_copy, monkeypatch, capsys, content
|
|||
(["-i", "{txt}"], "Keine VTT-Datei"),
|
||||
(["-i", "{vtt}", "{vtt2}", "-o", "{dir}/x.txt"], "muss -o/--output ein Verzeichnis sein"),
|
||||
(["-i", "{dir}/*.gibtsnicht"], "Keine Datei passt zu"),
|
||||
(["-i", "{vtt}", "{dir}/sub/ramstein.de.vtt", "-o", "{dir}/"], "dieselbe Ausgabedatei"),
|
||||
(["-i", "{vtt}", "{dir}/sub/beispiel.de.vtt", "-o", "{dir}/"], "dieselbe Ausgabedatei"),
|
||||
(["-i", "{vtt}", "-o", "{vtt}"], "nicht die Eingabedatei"),
|
||||
])
|
||||
def test_cli_errors(sample_copy, monkeypatch, capsys, args, message):
|
||||
|
|
@ -417,7 +431,7 @@ def test_split_segments_inverts_join_segments():
|
|||
|
||||
def test_main_time_range_default_name(sample_copy, monkeypatch):
|
||||
run_main(monkeypatch, "-i", sample_copy, "-z", "0:00:30-0:01")
|
||||
target = sample_copy.with_name("ramstein.de_00-00-30_bis_00-01-00.txt")
|
||||
target = sample_copy.with_name("beispiel.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 vtt2txt.HEADER.fullmatch(part[0])
|
||||
|
|
@ -426,17 +440,17 @@ def test_main_time_range_default_name(sample_copy, monkeypatch):
|
|||
|
||||
def test_main_several_ranges(sample_copy, monkeypatch):
|
||||
run_main(monkeypatch, "-i", sample_copy, "-z", "0:01-0:02 0:05")
|
||||
target = sample_copy.with_name("ramstein.de_00-01-00_bis_00-02-00+ab_00-05-00.txt")
|
||||
target = sample_copy.with_name("beispiel.de_00-01-00_bis_00-02-00+ab_00-05-00.txt")
|
||||
segments = vtt2txt.split_segments(target.read_text(encoding="utf-8"))
|
||||
assert [header for header, _ in segments] == [
|
||||
"[00:00:56 - 00:02:09]", "[00:04:57 - 00:48:07]",
|
||||
"[00:00:59 - 00:02:03]", "[00:04:58 - 00:13:10]",
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("ranges", [["0:01-0:02 0:05"], ["0:01-0:02", "0:05"]])
|
||||
def test_main_ranges_with_or_without_quotes(sample_copy, monkeypatch, ranges):
|
||||
run_main(monkeypatch, "-i", sample_copy, "-z", *ranges)
|
||||
target = sample_copy.with_name("ramstein.de_00-01-00_bis_00-02-00+ab_00-05-00.txt")
|
||||
target = sample_copy.with_name("beispiel.de_00-01-00_bis_00-02-00+ab_00-05-00.txt")
|
||||
assert target.is_file()
|
||||
|
||||
|
||||
|
|
@ -456,8 +470,8 @@ def test_range_argv(argv, expected):
|
|||
def test_main_range_from_beginning(sample_copy, monkeypatch, ranges):
|
||||
args = ranges if ranges[0].startswith("-z") else ["-z", *ranges]
|
||||
run_main(monkeypatch, "-i", sample_copy, *args)
|
||||
target = sample_copy.with_name("ramstein.de_bis_00-01-00.txt")
|
||||
assert target.read_text(encoding="utf-8").startswith("[00:00:09 - ")
|
||||
target = sample_copy.with_name("beispiel.de_bis_00-01-00.txt")
|
||||
assert target.read_text(encoding="utf-8").startswith("[00:00:00 - ")
|
||||
|
||||
|
||||
def test_main_time_range_without_captions(sample_copy, monkeypatch, capsys):
|
||||
|
|
|
|||
Loading…
Reference in a new issue