"""Shared pytest fixtures.""" from __future__ import annotations import json import sys from pathlib import Path import pytest ROOT = Path(__file__).resolve().parent.parent sys.path.insert(0, str(ROOT / "src")) CORPUS = ROOT / "corpus" @pytest.fixture(scope="session") def corpus_dir() -> Path: if not (CORPUS / "ground_truth.json").exists(): pytest.skip("corpus not generated; run: python tests/corpus.py corpus 12") return CORPUS @pytest.fixture(scope="session") def ground_truth(corpus_dir: Path) -> list[dict]: return json.loads((corpus_dir / "ground_truth.json").read_text()) @pytest.fixture(scope="session") def settings(): from docxextract.config import Settings return Settings(torch_threads=4, parse_cache_size=32) @pytest.fixture(scope="session") def sample_pdf(ground_truth) -> bytes: return Path(ground_truth[0]["path"]).read_bytes() @pytest.fixture(scope="session") def engine(settings): """Session-scoped warmed engine. Loading a model per test is too slow.""" from docxextract.engine import Engine, reset_engine eng = Engine(settings) eng.warmup() yield eng reset_engine()