test_sentences.py
Language Python1.3 KB36 lines
"""split_sentences: known cases, offsets, and the golden file.tests/fixtures/sentences-golden.json holds what the original JavaScriptsplitter returned for each input, generated once from that code. The Pythonport must reproduce it exactly."""import jsonfrom pathlib import Pathfrom transcription_pipeline.sentences import split_sentencesGOLDEN = Path(__file__).resolve().parent / "fixtures" / "sentences-golden.json"def test_known_cases():assert [s["text"] for s in split_sentences("Hello there. How are you? I'm fine!")] == \["Hello there.", "How are you?", "I'm fine!"]assert len(split_sentences("Um... yeah I think so.")) == 1assert len(split_sentences("Growth was 3.5 percent.")) == 1assert [s["text"] for s in split_sentences('He said "stop." Then he left.')] == \['He said "stop."', "Then he left."]def test_offsets_point_into_the_text():text = "Dr. Smith arrived. He sat down. Then... nothing."for s in split_sentences(text):assert text[s["offset"]:s["offset"] + len(s["text"])] == s["text"]def test_matches_the_golden_file():cases = json.loads(GOLDEN.read_text(encoding="utf-8"))assert casesfor case in cases:got = split_sentences(case["input"])assert got == case["sentences"], f"mismatch on {case['input']!r}"