9cdc9ae443
- config.example.toml: pdfa_level="" als sicherer Default - check_preflight(pdfa_level) erkennt betroffene GS-Versionen und bricht ab - install.sh warnt bei betroffenen GS-Versionen - 19 neue Tests (parametrisiert über Versions-Matrix) Closes #3 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
73 lines
2.5 KiB
Python
73 lines
2.5 KiB
Python
"""Tests für Issue #3: Ghostscript 10.0.0–10.02.0 PDF/A-Bug-Erkennung."""
|
||
from __future__ import annotations
|
||
|
||
from unittest.mock import patch
|
||
|
||
import pytest
|
||
|
||
from pdf_ocr_hotfolder.service import (
|
||
PreflightError,
|
||
check_preflight,
|
||
is_ghostscript_broken,
|
||
)
|
||
|
||
|
||
@pytest.mark.parametrize("version,expected", [
|
||
# Betroffene Versionen
|
||
("10.0.0", True),
|
||
("10.00.0", True),
|
||
("10.01.0", True),
|
||
("10.01.1", True),
|
||
("10.01.2", True),
|
||
("10.02.0", True),
|
||
# Sichere Versionen
|
||
("10.02.1", False),
|
||
("10.03.0", False),
|
||
("10.04.0", False),
|
||
("11.0.0", False),
|
||
("9.56.1", False), # Debian 11 / Ubuntu 22.04
|
||
("9.55.0", False),
|
||
# Edge cases
|
||
("", False),
|
||
(None, False),
|
||
("garbage", False),
|
||
])
|
||
def test_is_ghostscript_broken(version, expected) -> None:
|
||
assert is_ghostscript_broken(version) is expected
|
||
|
||
|
||
def test_check_preflight_without_pdfa_passes_with_broken_gs() -> None:
|
||
"""Ohne pdfa_level darf der betroffene GS verwendet werden."""
|
||
with patch("pdf_ocr_hotfolder.service.shutil.which", return_value="/usr/bin/fake"), \
|
||
patch("pdf_ocr_hotfolder.service.detect_ghostscript_version",
|
||
return_value="10.0.0"):
|
||
check_preflight(pdfa_level="") # darf nicht werfen
|
||
|
||
|
||
def test_check_preflight_with_pdfa_fails_on_broken_gs() -> None:
|
||
"""Mit pdfa_level + kaputtem GS → PreflightError mit hilfreicher Meldung."""
|
||
with patch("pdf_ocr_hotfolder.service.shutil.which", return_value="/usr/bin/fake"), \
|
||
patch("pdf_ocr_hotfolder.service.detect_ghostscript_version",
|
||
return_value="10.0.0"):
|
||
with pytest.raises(PreflightError, match="Ghostscript 10.0.0"):
|
||
check_preflight(pdfa_level="2")
|
||
|
||
|
||
def test_check_preflight_with_pdfa_passes_on_fixed_gs() -> None:
|
||
"""Mit pdfa_level + gefixtem GS → ok."""
|
||
with patch("pdf_ocr_hotfolder.service.shutil.which", return_value="/usr/bin/fake"), \
|
||
patch("pdf_ocr_hotfolder.service.detect_ghostscript_version",
|
||
return_value="10.02.1"):
|
||
check_preflight(pdfa_level="2") # darf nicht werfen
|
||
|
||
|
||
def test_default_config_pdfa_level_is_empty() -> None:
|
||
"""Default-Config der Beispiel-Datei soll pdfa_level='' enthalten (Issue #3)."""
|
||
from pathlib import Path
|
||
import tomllib
|
||
cfg_path = Path(__file__).parent.parent / "config.example.toml"
|
||
with cfg_path.open("rb") as f:
|
||
data = tomllib.load(f)
|
||
assert data["ocr"]["pdfa_level"] == "", \
|
||
"config.example.toml muss pdfa_level='' als sicheren Default haben"
|