from __future__ import annotations
import os
from pathlib import Path
import pytest
Matra = pytest.importorskip("matra", reason="matra wheel not built").Matra
MAX_INPUT_BYTES = 8 * 1024 * 1024
def _model_dir() -> str:
return os.environ.get("MATRA_MODEL_DIR") or str(Path.home() / ".matra" / "models")
@pytest.fixture(scope="module")
def engine() -> Matra:
try:
return Matra.english(_model_dir())
except Exception as exc:
pytest.skip(f"UDPipe model unavailable: {exc}")
@pytest.fixture(scope="module")
def oversized() -> str:
return "a" * (MAX_INPUT_BYTES + 1)
@pytest.mark.parametrize(
"call",
[
pytest.param(lambda m, t: m.analyze(t), id="analyze"),
pytest.param(lambda m, t: m.analyze_markdown(t), id="analyze_markdown"),
pytest.param(lambda m, t: m.tfidf_summarize(t, 3), id="tfidf_summarize"),
pytest.param(lambda m, t: m.textrank_summarize(t, 3), id="textrank_summarize"),
pytest.param(lambda m, t: m.rake_keyphrases(t, 10), id="rake_keyphrases"),
pytest.param(lambda m, t: m.yake_keyphrases(t, 10), id="yake_keyphrases"),
],
)
def test_every_text_method_enforces_the_cap(engine, oversized, call) -> None:
with pytest.raises(ValueError):
call(engine, oversized)