Spaces:
Running
Running
| from __future__ import annotations | |
| import json | |
| from racing_reports import runner as runner_mod | |
| from racing_reports.models import ReportRequest | |
| from racing_reports.runner import ReportRunner | |
| def _stub_adapters(monkeypatch): | |
| """Evita correr los scripts pesados reales (torch); sólo orquestación.""" | |
| calls: list[str] = [] | |
| def fake_pre(*, out_path, **_): | |
| out_path.write_text("pre", encoding="utf-8") | |
| calls.append("pre_match") | |
| return out_path | |
| def fake_post(*, out_path, **_): | |
| out_path.write_text("post", encoding="utf-8") | |
| calls.append("post_match") | |
| return out_path | |
| def fake_block(*, out_path, **_): | |
| out_path.write_text("block", encoding="utf-8") | |
| calls.append("block_zscore") | |
| return out_path | |
| monkeypatch.setattr(runner_mod.pre_match, "generate", fake_pre) | |
| monkeypatch.setattr(runner_mod.post_match, "generate", fake_post) | |
| monkeypatch.setattr(runner_mod.block_zscore, "generate", fake_block) | |
| return calls | |
| def test_post_match_runs_pre_first_and_writes_manifest(monkeypatch, sample_store): | |
| calls = _stub_adapters(monkeypatch) | |
| from racing_reports import web_meta | |
| monkeypatch.setattr( | |
| web_meta, "find_match", | |
| lambda league, season, match_id: { | |
| "match_id": match_id, "home_team": "Racing de Santander", | |
| "away_team": "Almería", "date": "2026-04-12", "status": "played", | |
| }, | |
| ) | |
| monkeypatch.setattr( | |
| sample_store, "prepare_vendor", lambda *a, **k: {"matches_csv": "x"} | |
| ) | |
| monkeypatch.setattr( | |
| sample_store, | |
| "require_labeled", | |
| lambda *a, **k: sample_store.preprocessed_path( | |
| "Spanish Segunda Division", "25-26" | |
| ), | |
| ) | |
| request = ReportRequest( | |
| league="Spanish Segunda Division", | |
| season="25-26", | |
| home_team="", | |
| away_team="", | |
| report_types=["post_match"], | |
| match_id="m1", | |
| ) | |
| result = ReportRunner(sample_store, settings=sample_store.settings).run(request) | |
| assert calls == ["pre_match", "post_match"] # pre se antepone solo | |
| assert set(result.html_paths) == {"pre_match", "post_match"} | |
| manifest = json.loads(result.manifest_path.read_text(encoding="utf-8")) | |
| assert manifest["report_types_run"] == ["pre_match", "post_match"] | |
| assert manifest["request"]["match_id"] == "m1" | |