Some checks are pending
Test and SonarQube / quality (push) Waiting to run
- Quality run: per-page missed-text recovery, guarded OCR re-read and a pixel audit (uncovered ink, overlapping boxes, clipped box edges); report saved as quality_report.json - Thumbnail grid: quality-stage colours, flag badge, live per-page indicator for every batch step (OCR, detection, figure fixing, quality run, audio) - Pages can be approved as advertisements (not narrated, skipped by quality run) - Driving mode: +/-15 s, seek bar, playback speed, text and image toggles - Plus the previously uncommitted 1.53.5 magazine/OCR work in the same tree Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
60 lines
2.5 KiB
Python
60 lines
2.5 KiB
Python
import unittest
|
|
|
|
from core.pronunciations import (
|
|
expand_abbreviations,
|
|
normalize_ocr_text,
|
|
prepare_text_for_tts,
|
|
remove_linebreak_hyphens,
|
|
suspect_ocr_tokens,
|
|
)
|
|
|
|
|
|
class PronunciationTests(unittest.TestCase):
|
|
def test_fuses_printed_line_break_but_keeps_real_compound(self):
|
|
self.assertEqual(remove_linebreak_hyphens("program-\nmieren mit einem KI-Modell"),
|
|
"programmieren mit einem KI-Modell")
|
|
self.assertEqual(remove_linebreak_hyphens("Hardware- und Software"),
|
|
"Hardware- und Software")
|
|
self.assertEqual(remove_linebreak_hyphens("einge\u00adtrichtert"), "eingetrichtert")
|
|
|
|
def test_existing_flattened_ocr_layouts_are_repaired_too(self):
|
|
self.assertEqual(remove_linebreak_hyphens("eingetrich- tert"), "eingetrichtert")
|
|
|
|
def test_german_umlaut_and_acronyms_are_prepared_for_speech(self):
|
|
spoken = prepare_text_for_tts(
|
|
"KI wird jahrlich wichtiger und APIs sind naturlich verfügbar.", "de")
|
|
self.assertIn("Künstliche Intelligenz", spoken)
|
|
self.assertIn("jährlich", spoken)
|
|
self.assertIn("Programmierschnittstellen", spoken)
|
|
self.assertIn("natürlich", spoken)
|
|
|
|
def test_ki_expansion_is_token_bounded(self):
|
|
self.assertEqual(prepare_text_for_tts("KI hilft der KI-Branche.", "de"),
|
|
"Künstliche Intelligenz hilft der Künstliche Intelligenz-Branche.")
|
|
self.assertEqual(prepare_text_for_tts("Kiel bleibt Kiel.", "de"),
|
|
"Kiel bleibt Kiel.")
|
|
|
|
def test_english_acronyms_use_english_expansions(self):
|
|
self.assertEqual(expand_abbreviations("AI uses an API.", "en"),
|
|
"artificial intelligence uses an application programming interface.")
|
|
|
|
def test_unknown_technical_words_and_names_stay_unchanged(self):
|
|
text = "OpenAI und PyMuPDF bleiben unverändert."
|
|
self.assertEqual(normalize_ocr_text(text, "de"), text)
|
|
|
|
def test_spellcheck_only_flags_suspects_and_never_rewrites_text(self):
|
|
class Checker:
|
|
def __contains__(self, word):
|
|
return word != 'softwarentwicklng'
|
|
|
|
from unittest import mock
|
|
with mock.patch('core.pronunciations._german_spellchecker', return_value=Checker()):
|
|
self.assertEqual(
|
|
suspect_ocr_tokens('Die Softwarentwicklng hilft OpenAI.', 'de'),
|
|
['Softwarentwicklng'],
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|