Spaces:
Running on T4
Running on T4
Download AI-coach-agent/tests/test_schema_docs.py from modventures/baseball-engine: direct link, hf CLI and curl.
- Browser
- Download file 1.57 kB
-
https://huggingface.co/spaces/modventures/baseball-engine/resolve/main/AI-coach-agent/tests/test_schema_docs.py
- Command line
-
hf download hf://spaces/modventures/baseball-engine/AI-coach-agent/tests/test_schema_docs.py
-
curl -L -o test_schema_docs.py https://huggingface.co/spaces/modventures/baseball-engine/resolve/main/AI-coach-agent/tests/test_schema_docs.py
1.57 kB
| import json | |
| import sys | |
| from pathlib import Path | |
| import jsonschema | |
| import pytest | |
| sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "tools")) | |
| from export_schema import DOCS, render | |
| from ai_coach.input_builder import build_coach_input | |
| from ai_coach.schemas import CoachInput, CoachNote | |
| from .helpers import example_names, good_note, load_example, make_input | |
| def test_exported_schemas_are_up_to_date(): | |
| """If this fails run: python tools/export_schema.py (the ML engineer reads these files).""" | |
| assert (DOCS / "coach_input.schema.json").read_text(encoding="utf-8") == render(CoachInput) | |
| assert (DOCS / "coach_note.schema.json").read_text(encoding="utf-8") == render(CoachNote) | |
| def test_compact_inputs_validate_against_the_published_schema(name): | |
| schema = json.loads((DOCS / "coach_input.schema.json").read_text(encoding="utf-8")) | |
| data = json.loads(build_coach_input(load_example(name)).model_dump_json()) | |
| jsonschema.validate(data, schema) | |
| def test_schema_rejects_unknown_fields(): | |
| schema = json.loads((DOCS / "coach_input.schema.json").read_text(encoding="utf-8")) | |
| data = json.loads(make_input().model_dump_json()) | |
| data["video_url"] = "https://example.com/x.mp4" | |
| with pytest.raises(jsonschema.ValidationError): | |
| jsonschema.validate(data, schema) | |
| def test_note_schema_accepts_a_good_note(): | |
| schema = json.loads((DOCS / "coach_note.schema.json").read_text(encoding="utf-8")) | |
| jsonschema.validate(json.loads(good_note().model_dump_json()), schema) | |