Ruff: declare adapter re-exports via __all__ in docling_extractor (F401) and sort the engine import block in the adapter test (I001). Pytest: engine-dependent tests now importorskip the pinned engine — CI installs light deps only and the engine repo is private, so they skip visibly there and run in Docker/dev envs with the engine. Verified: ruff clean; pytest 74 passed + 2 skipped without engine, 80 passed with the pinned engine v0.1.0 installed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
72 lines
2.4 KiB
Python
72 lines
2.4 KiB
Python
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
# Skip cleanly where the pinned engine is not installed (e.g. light-deps CI);
|
|
# see app/ingestion/ENGINE_SOURCE.md for the focused verification command.
|
|
pytest.importorskip("teamhub_document_recognition_engine")
|
|
|
|
|
|
def test_legacy_ocr_adapter_reexports_engine_model_and_settings(monkeypatch, tmp_path: Path) -> None:
|
|
from teamhub_document_recognition_engine import OcrResult as EngineOcrResult
|
|
|
|
import app.ingestion.ocr as legacy_ocr
|
|
|
|
calls = {}
|
|
|
|
def fake_run_ocr(input_pdf, output_pdf, **kwargs):
|
|
calls.update(kwargs)
|
|
return EngineOcrResult(output_path=output_pdf, skipped=True, reason="fake", languages=kwargs["languages"])
|
|
|
|
monkeypatch.setattr(legacy_ocr, "_engine_run_ocr", fake_run_ocr)
|
|
monkeypatch.setattr(legacy_ocr.settings, "ocr_enabled", False)
|
|
monkeypatch.setattr(legacy_ocr.settings, "ocr_deskew", False)
|
|
monkeypatch.setattr(legacy_ocr.settings, "ocr_clean", False)
|
|
monkeypatch.setattr(legacy_ocr.settings, "ocr_optimize", 0)
|
|
|
|
result = legacy_ocr.run_ocr(tmp_path / "in.pdf", tmp_path / "out.pdf", languages="eng")
|
|
|
|
assert legacy_ocr.OcrResult is EngineOcrResult
|
|
assert isinstance(result, EngineOcrResult)
|
|
assert calls == {
|
|
"languages": "eng",
|
|
"enabled": False,
|
|
"deskew": False,
|
|
"clean": False,
|
|
"optimize": 0,
|
|
}
|
|
|
|
|
|
def test_legacy_docling_adapter_reexports_engine_models_and_settings(monkeypatch, tmp_path: Path) -> None:
|
|
from teamhub_document_recognition_engine import (
|
|
ExtractedBlock as EngineExtractedBlock,
|
|
)
|
|
from teamhub_document_recognition_engine import (
|
|
ExtractionResult as EngineExtractionResult,
|
|
)
|
|
|
|
import app.ingestion.docling_extractor as legacy_docling
|
|
|
|
calls = {}
|
|
|
|
def fake_extract(pdf_path, **kwargs):
|
|
calls.update(kwargs)
|
|
return EngineExtractionResult(
|
|
markdown="",
|
|
json_payload={},
|
|
blocks=[],
|
|
tables=[],
|
|
figures=[],
|
|
pages=[],
|
|
)
|
|
|
|
monkeypatch.setattr(legacy_docling, "_engine_extract", fake_extract)
|
|
monkeypatch.setattr(legacy_docling.settings, "docling_ocr_enabled", True)
|
|
|
|
result = legacy_docling.extract(tmp_path / "ocr.pdf")
|
|
|
|
assert legacy_docling.ExtractedBlock is EngineExtractedBlock
|
|
assert legacy_docling.ExtractionResult is EngineExtractionResult
|
|
assert isinstance(result, EngineExtractionResult)
|
|
assert calls == {"docling_ocr_enabled": True}
|