fix: Fehlerzaehlung, Upload-Fehler und ocr.timeout scharf (v0.4.0)
- [ocr].timeout wird als tesseract_timeout (pro Seite) an ocrmypdf durchgereicht; Default 1800 -> 300, 0 = ocrmypdf-Default - Exceptions nach dem OCR zaehlen als Fehler, Datei wird nach error/ gerettet - Fehlgeschlagene Uploads zaehlen als Fehler und loesen Fehler-Mail aus - name_mode wird im Preflight geprueft, nicht erst pro Datei - Fehlende [paths]-Sektion -> ConfigError mit klarer Meldung statt KeyError - Stabilitaets-Timeout zaehlt als Fehler (--once liefert Exit 1) - upload_folder nutzt shutil.copyfile statt read_bytes/write_bytes - OcrConfig.pdfa_level Default "2" -> "" (Ghostscript-Bug, Issue #3) - 35 neue Tests (92 gesamt), pytest.ini - AI_AGENT_BRIEFING.md auf Stand 0.4.0 gebracht Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -60,6 +60,62 @@ def test_check_output_config_invalid_mode() -> None:
|
||||
check_output_config("trash", "")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("name_mode", ["prefix", "suffix", "none"])
|
||||
def test_check_output_config_accepts_valid_name_modes(name_mode) -> None:
|
||||
check_output_config("delete", "", name_mode) # ok
|
||||
|
||||
|
||||
@pytest.mark.parametrize("name_mode", ["prefixx", "Prefix", "", "postfix"])
|
||||
def test_check_output_config_invalid_name_mode(name_mode) -> None:
|
||||
"""Tippfehler in name_mode muss schon im Preflight auffallen."""
|
||||
with pytest.raises(PreflightError, match="name_mode"):
|
||||
check_output_config("delete", "", name_mode)
|
||||
|
||||
|
||||
def test_run_once_aborts_on_invalid_name_mode(tmp_config) -> None:
|
||||
"""Der Dienst bricht beim Start ab, bevor eine Datei angefasst wird."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from pdf_ocr_hotfolder.service import HotfolderService
|
||||
|
||||
tmp_config.output.name_mode = "bogus"
|
||||
(tmp_config.paths.incoming / "a.pdf").write_bytes(b"%PDF-1.4\n")
|
||||
|
||||
service = HotfolderService(tmp_config)
|
||||
try:
|
||||
with patch("pdf_ocr_hotfolder.service.check_preflight", return_value=None):
|
||||
with pytest.raises(PreflightError, match="name_mode"):
|
||||
service.run_once()
|
||||
finally:
|
||||
service._executor.shutdown(wait=False)
|
||||
|
||||
# Datei wurde nicht angefasst
|
||||
assert (tmp_config.paths.incoming / "a.pdf").exists()
|
||||
|
||||
|
||||
def test_main_returns_2_on_invalid_name_mode(tmp_path: Path, monkeypatch) -> None:
|
||||
"""CLI liefert Exit-Code 2 — gleicher Mechanismus wie die übrigen Preflights."""
|
||||
import sys
|
||||
from unittest.mock import patch as _patch
|
||||
|
||||
cfg_file = tmp_path / "cfg.toml"
|
||||
cfg_file.write_text(f"""
|
||||
[paths]
|
||||
incoming = "{tmp_path / 'in'}"
|
||||
outgoing = "{tmp_path / 'out'}"
|
||||
working = "{tmp_path / 'work'}"
|
||||
error = "{tmp_path / 'err'}"
|
||||
|
||||
[output]
|
||||
name_mode = "bogus"
|
||||
""")
|
||||
monkeypatch.setattr(sys, "argv",
|
||||
["pdf-ocr-hotfolder", "--config", str(cfg_file), "--once"])
|
||||
with _patch("pdf_ocr_hotfolder.service.check_preflight", return_value=None):
|
||||
from pdf_ocr_hotfolder.__main__ import main
|
||||
assert main() == 2
|
||||
|
||||
|
||||
# ---------------- process_pdf mit Original-Behandlung ----------------
|
||||
|
||||
def _fake_ocr(src: Path, dst: Path, cfg: OcrConfig) -> None:
|
||||
|
||||
Reference in New Issue
Block a user