Spaces:
Running on T4
Running on T4
Download AI-coach-agent/tests/test_validate.py from modventures/baseball-engine: direct link, hf CLI and curl.
- Browser
- Download file 4.25 kB
-
https://huggingface.co/spaces/modventures/baseball-engine/resolve/main/AI-coach-agent/tests/test_validate.py
- Command line
-
hf download hf://spaces/modventures/baseball-engine/AI-coach-agent/tests/test_validate.py
-
curl -L -o test_validate.py https://huggingface.co/spaces/modventures/baseball-engine/resolve/main/AI-coach-agent/tests/test_validate.py
4.25 kB
| import copy | |
| import pytest | |
| from ai_coach.validate import main, validate_session | |
| from .helpers import EXAMPLES, example_names, load_example | |
| def codes(session, level=None): | |
| return {i.code for i in validate_session(session) if level is None or i.level == level} | |
| def test_all_examples_have_no_errors(name): | |
| assert codes(load_example(name), "error") == set() | |
| def test_real_low_fps_clip_gets_the_expected_warnings(): | |
| assert codes(load_example("real_hitting_30fps_low_confidence"), "warning") == {"low_fps", "few_reps"} | |
| def test_a_clean_240fps_session_has_no_issues_at_all(): | |
| assert validate_session(load_example("hitting_ok_240fps")) == [] | |
| def test_missing_level_is_a_warning_not_an_error(): | |
| session = load_example("hitting_ok_240fps") | |
| session.pop("level") | |
| assert "level_missing" in codes(session, "warning") and not codes(session, "error") | |
| session["level"] = "pro" | |
| assert "level" in codes(session, "error") | |
| def test_out_of_bounds_values_are_errors(): | |
| session = load_example("hitting_ok_240fps") | |
| session["reps"][0]["metrics"][0]["value"] = 400.0 # a 400%-of-height stride is a pipeline bug | |
| assert "out_of_bounds" in codes(session, "error") | |
| def test_non_finite_and_bad_enums_are_errors(): | |
| session = load_example("pitching_ok_240fps") | |
| session["reps"][0]["metrics"][0]["value"] = float("nan") | |
| session["reps"][1]["metrics"][0]["confidence"] = "certain" | |
| assert {"value", "confidence"} <= codes(session, "error") | |
| def test_events_out_of_order_are_errors(): | |
| session = load_example("hitting_ok_240fps") | |
| session["reps"][0]["events_ms"] = {"foot_plant": 900, "contact": 100} | |
| assert "event_order" in codes(session, "error") | |
| def test_the_pipeline_must_not_decide_problems_or_ranges_and_is_told_so(): | |
| session = load_example("hitting_ok_240fps") | |
| session.update(faults=[{"key": "over_stride"}], focus={"fault_key": "over_stride"}, drill={"name": "x"}) | |
| session["reps"][0]["metrics"][0].update(ref=[1, 2], zone="outside") | |
| result = [i for i in validate_session(session) if i.code == "ignored_fields"] | |
| assert result and all(i.level == "warning" for i in result) | |
| assert any("faults" in i.detail for i in result) and any("agent owns the typical ranges" in i.detail for i in result) | |
| assert not codes(session, "error") | |
| def test_old_v1_wrapping_is_accepted_with_a_warning(): | |
| v2 = load_example("hitting_ok_240fps") | |
| v1 = { | |
| "discipline": v2["discipline"], | |
| "fps": v2["fps"], | |
| "level": v2["level"], | |
| "reps": v2["reps"], | |
| "session": {"capture": v2["capture"], "focus": {"fault_key": "over_stride"}}, | |
| } | |
| assert {"old_format", "ignored_fields"} <= codes(v1, "warning") and not codes(v1, "error") | |
| def test_structural_problems_return_early(): | |
| assert "discipline" in codes({"discipline": "golf"}) | |
| assert "missing_field" in codes({"discipline": "hitting"}) | |
| def test_null_without_note_unknown_metric_and_unknown_capture_reason(): | |
| session = copy.deepcopy(load_example("hitting_ok_240fps")) | |
| session["reps"][0]["metrics"][0].update(value=None) | |
| session["reps"][0]["metrics"][0].pop("note", None) | |
| session["reps"][0]["metrics"][1]["key"] = "mystery_metric" | |
| session["capture"] = {"ok": False, "reasons": ["hat_on_backwards"]} | |
| result = codes(session, "warning") | |
| assert {"null_without_note", "unknown_metric", "unknown_capture_reason"} <= result | |
| def test_capture_failure_without_a_reason_is_flagged(): | |
| session = load_example("hitting_ok_240fps") | |
| session["capture"] = {"ok": False, "reasons": []} | |
| assert "capture_without_reason" in codes(session, "warning") | |
| def test_invalid_measurement_that_cannot_be_built_is_an_error(): | |
| session = load_example("hitting_ok_240fps") | |
| session["reps"][0]["metrics"][0]["value"] = "fast" | |
| assert {"value", "cannot_build_input"} <= codes(session, "error") | |
| def test_cli_exit_codes(capsys): | |
| assert main([str(EXAMPLES / "hitting_ok_240fps.json")]) == 0 | |
| assert main([str(EXAMPLES / "real_hitting_30fps_low_confidence.json")]) == 0 | |
| assert main([str(EXAMPLES / "real_hitting_30fps_low_confidence.json"), "--strict"]) == 1 | |
| assert "warning" in capsys.readouterr().out | |