Spaces:
Running on T4
Running on T4
Download AI-coach-agent/tests/test_response_examples.py from modventures/baseball-engine: direct link, hf CLI and curl.
- Browser
- Download file 1.93 kB
-
https://huggingface.co/spaces/modventures/baseball-engine/resolve/main/AI-coach-agent/tests/test_response_examples.py
- Command line
-
hf download hf://spaces/modventures/baseball-engine/AI-coach-agent/tests/test_response_examples.py
-
curl -L -o test_response_examples.py https://huggingface.co/spaces/modventures/baseball-engine/resolve/main/AI-coach-agent/tests/test_response_examples.py
1.93 kB
| """The response examples the frontend engineer builds against: current, and valid against the real response model.""" | |
| import json | |
| import sys | |
| from pathlib import Path | |
| import pytest | |
| from ai_coach.response import CoachResponse | |
| ROOT = Path(__file__).resolve().parents[1] | |
| sys.path.insert(0, str(ROOT / "tools")) | |
| import build_response_examples as gen # noqa: E402 | |
| OUT = ROOT / "docs" / "examples" / "responses" | |
| def test_the_published_examples_match_the_generator(): | |
| """If this fails run: python tools/build_response_examples.py (the frontend reads these files).""" | |
| built = gen.build() | |
| assert sorted(p.name for p in OUT.glob("*.json")) == sorted(built) | |
| for name, text in built.items(): | |
| assert (OUT / name).read_text(encoding="utf-8") == text, name | |
| def test_every_example_is_a_valid_v2_response(path): | |
| response = CoachResponse.model_validate(json.loads(path.read_text(encoding="utf-8"))) | |
| assert response.response_version == "2.0" and response.summary | |
| assert (response.score.value is None) == (response.score.reason_code is not None) | |
| def test_the_examples_cover_the_states_the_screen_must_handle(): | |
| by_name = {p.stem: CoachResponse.model_validate_json(p.read_text(encoding="utf-8")) for p in OUT.glob("*.json")} | |
| assert by_name["hitting_with_timing"].timing.consistency and by_name["hitting_with_timing"].focus | |
| assert by_name["pitching_arm_care"].arm_care.lines | |
| assert by_name["record_again"].score.reason_code == "capture_not_ok" and not by_name["record_again"].focus | |
| assert by_name["score_withheld_low_fps"].score.value is None and by_name["score_withheld_low_fps"].strengths is not None | |
| assert by_name["timing_only"].meta.fallback_reason == "timing_only" and by_name["timing_only"].timing | |
| assert by_name["hitting_clean"].score.value == 100 and not by_name["hitting_clean"].focus | |