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:
@@ -0,0 +1,66 @@
|
||||
"""Tests für upload_folder() — Kopie per shutil.copyfile statt read_bytes()."""
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
from pdf_ocr_hotfolder.config import FolderUpload
|
||||
from pdf_ocr_hotfolder.uploaders import upload_folder
|
||||
|
||||
|
||||
def test_upload_folder_copies_file(tmp_path: Path) -> None:
|
||||
src = tmp_path / "out" / "OCR_scan.pdf"
|
||||
src.parent.mkdir()
|
||||
src.write_bytes(b"%PDF-1.4 inhalt\n")
|
||||
target = tmp_path / "ziel"
|
||||
|
||||
assert upload_folder(src, FolderUpload(enabled=True, target=str(target)),
|
||||
tmp_path / "out") is True
|
||||
assert (target / "OCR_scan.pdf").read_bytes() == b"%PDF-1.4 inhalt\n"
|
||||
# Quelle bleibt liegen (Kopie, kein Move)
|
||||
assert src.exists()
|
||||
|
||||
|
||||
def test_upload_folder_uses_copyfile_not_read_bytes(tmp_path: Path) -> None:
|
||||
"""Große PDFs dürfen nicht komplett in den Speicher gelesen werden."""
|
||||
src = tmp_path / "out" / "OCR_scan.pdf"
|
||||
src.parent.mkdir()
|
||||
src.write_bytes(b"%PDF-1.4\n")
|
||||
target = tmp_path / "ziel"
|
||||
|
||||
with patch("pdf_ocr_hotfolder.uploaders.shutil.copyfile") as copyfile:
|
||||
upload_folder(src, FolderUpload(enabled=True, target=str(target)),
|
||||
tmp_path / "out")
|
||||
copyfile.assert_called_once()
|
||||
|
||||
|
||||
def test_upload_folder_skips_self_target(tmp_path: Path) -> None:
|
||||
"""Ist das Ziel = outgoing, wird nicht auf sich selbst kopiert."""
|
||||
out = tmp_path / "out"
|
||||
out.mkdir()
|
||||
src = out / "OCR_scan.pdf"
|
||||
src.write_bytes(b"%PDF-1.4\n")
|
||||
|
||||
with patch("pdf_ocr_hotfolder.uploaders.shutil.copyfile") as copyfile:
|
||||
assert upload_folder(src, FolderUpload(enabled=True, target=""), out) is True
|
||||
copyfile.assert_not_called()
|
||||
assert src.read_bytes() == b"%PDF-1.4\n"
|
||||
|
||||
|
||||
def test_upload_folder_disabled_returns_true(tmp_path: Path) -> None:
|
||||
src = tmp_path / "OCR_scan.pdf"
|
||||
src.write_bytes(b"%PDF-1.4\n")
|
||||
assert upload_folder(src, FolderUpload(enabled=False), tmp_path) is True
|
||||
|
||||
|
||||
def test_upload_folder_reports_failure(tmp_path: Path) -> None:
|
||||
"""OSError beim Kopieren → False (wird vom Service als Fehler gezählt)."""
|
||||
src = tmp_path / "out" / "OCR_scan.pdf"
|
||||
src.parent.mkdir()
|
||||
src.write_bytes(b"%PDF-1.4\n")
|
||||
|
||||
with patch("pdf_ocr_hotfolder.uploaders.shutil.copyfile",
|
||||
side_effect=OSError("disk full")):
|
||||
assert upload_folder(src, FolderUpload(enabled=True,
|
||||
target=str(tmp_path / "ziel")),
|
||||
tmp_path / "out") is False
|
||||
Reference in New Issue
Block a user