File size: 2,378 Bytes
9da4e9c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7d5bb88
 
 
 
 
 
 
 
9da4e9c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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"