tests: little fixes

This commit is contained in:
James R. Barlow
2026-01-20 23:23:43 -08:00
parent bd29269c00
commit ec595a395b
4 changed files with 38 additions and 12 deletions
-1
View File
@@ -194,7 +194,6 @@ jobs:
choco install --yes --no-progress tesseract
choco install --yes --no-progress --ignore-checksums ghostscript --version 9.56.1
choco install --yes --no-progress poppler --version=25.11.0
choco install --yes --no-progress noto
- name: Install Python packages
run: |
+11
View File
@@ -49,6 +49,17 @@ def check_platform() -> None:
def check_options_languages(
options: OcrOptions, ocr_engine_languages: list[str]
) -> None:
# Check for blocked languages first, before checking if they're installed
DENIED_LANGUAGES = {'equ', 'osd'}
blocked = DENIED_LANGUAGES & set(options.languages)
if blocked:
raise BadArgsError(
"The following languages are for Tesseract's internal use and "
"should not be issued explicitly: "
f"{', '.join(blocked)}\n"
"Remove them from the -l/--language argument."
)
if not ocr_engine_languages:
return
+3 -11
View File
@@ -72,17 +72,9 @@ class ValidationCoordinator:
"--tesseract-downsample-large-images is also given."
)
# Check for blocked languages
from ocrmypdf.exceptions import BadArgsError
DENIED_LANGUAGES = {'equ', 'osd'}
if DENIED_LANGUAGES & set(options.languages):
raise BadArgsError(
"The following languages are for Tesseract's internal use and "
"should not be issued explicitly: "
f"{', '.join(DENIED_LANGUAGES & set(options.languages))}\n"
"Remove them from the -l/--language argument."
)
# Note: blocked languages (equ, osd) are checked earlier in
# check_options_languages() to ensure the check runs before
# the missing language check.
def _validate_optimize_options(self, options: OcrOptions) -> None:
"""Validate optimization options."""
+24
View File
@@ -208,6 +208,21 @@ class TestArabicScript:
# =============================================================================
def _latin_font_works(multi_font_manager) -> bool:
"""Check if Latin font is available."""
return multi_font_manager.has_all_glyphs('NotoSans-Regular', 'A')
def _arabic_font_works(multi_font_manager) -> bool:
"""Check if Arabic font is available."""
return multi_font_manager.has_all_glyphs('NotoSansArabic-Regular', 'م')
def _devanagari_font_works(multi_font_manager) -> bool:
"""Check if Devanagari font is available."""
return multi_font_manager.has_all_glyphs('NotoSansDevanagari-Regular', 'न')
def _cjk_font_works(multi_font_manager) -> bool:
"""Check if CJK font is working (not corrupted)."""
return multi_font_manager.has_all_glyphs('NotoSansCJK-Regular', '你')
@@ -515,6 +530,9 @@ class TestFontCoverage:
def test_noto_sans_latin_coverage(self, multi_font_manager):
"""Test NotoSans covers common Latin characters and diacritics."""
if not _latin_font_works(multi_font_manager):
pytest.skip("NotoSans font not available")
latin_samples = [
"Hello World",
"Café résumé naïve",
@@ -530,6 +548,9 @@ class TestFontCoverage:
def test_noto_sans_arabic_coverage(self, multi_font_manager):
"""Test NotoSansArabic covers Arabic characters."""
if not _arabic_font_works(multi_font_manager):
pytest.skip("NotoSansArabic font not available")
arabic_samples = [
"مرحبا", # Hello
"بالعالم", # World
@@ -543,6 +564,9 @@ class TestFontCoverage:
def test_noto_sans_devanagari_coverage(self, multi_font_manager):
"""Test NotoSansDevanagari covers Devanagari characters."""
if not _devanagari_font_works(multi_font_manager):
pytest.skip("NotoSansDevanagari font not available")
devanagari_samples = [
"नमस्ते", # Hello
"हिंदी", # Hindi