Spaces:
Running
Running
File size: 1,159 Bytes
efff1ff | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | """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()
|