from __future__ import annotations from pathlib import Path from racing_reports.reports import block_zscore from racing_reports.reports.bundle import ReportBundle from racing_reports.reports.catalogs import BLOCK_ZSCORE_FIGURES def test_block_zscore_runs_with_phase_label_fallback(sample_store, tmp_path: Path): """El preprocessed base de Azure sólo trae phaseLabel; build() tiene que derivar w_high/medium/low + label_after_rules a partir de ahí.""" pre = sample_store.preprocessed_path("Spanish Segunda Division", "25-26") out = tmp_path / "block.html" bundle = block_zscore.generate( out_path=out, labeled_csv=pre, team_a="Racing de Santander", team_b="Huesca", ) assert isinstance(bundle, ReportBundle) assert bundle.report_type == "block_zscore" assert out.exists() html = out.read_text(encoding="utf-8") assert "Z-score" in html assert "Racing de Santander" in html assert "Huesca" in html def test_block_zscore_bundle_has_canonical_figures(sample_store, tmp_path: Path): pre = sample_store.preprocessed_path("Spanish Segunda Division", "25-26") out = tmp_path / "block.html" bundle = block_zscore.generate( out_path=out, labeled_csv=pre, team_a="Racing de Santander", team_b="Huesca", ) assert [f.name for f in bundle.figures] == [s.name for s in BLOCK_ZSCORE_FIGURES] for fig in bundle.figures: assert fig.png_path.exists() assert fig.svg_path is not None and fig.svg_path.exists() def test_block_zscore_with_date_filter(sample_store, tmp_path: Path): pre = sample_store.preprocessed_path("Spanish Segunda Division", "25-26") out = tmp_path / "block_filtered.html" block_zscore.generate( out_path=out, labeled_csv=pre, team_a="Racing de Santander", team_b="Huesca", date_from="2026-04-15", ) assert out.exists() assert "desde 15/04/2026" in out.read_text(encoding="utf-8") def test_require_labeled_falls_back_to_base(sample_store): """Si Azure no tiene el labeled, require_labeled devuelve el base.""" path = sample_store.require_labeled("Spanish Segunda Division", "25-26") assert path == sample_store.preprocessed_path("Spanish Segunda Division", "25-26")