Add tests/test_dataset.py
Browse files- tests/test_dataset.py +44 -0
tests/test_dataset.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import json
|
| 4 |
+
import unittest
|
| 5 |
+
|
| 6 |
+
from trainer.build_dataset import assistant_json, telemetry_response
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class DatasetContractTests(unittest.TestCase):
|
| 10 |
+
def test_emergency_symptoms_override_telemetry(self) -> None:
|
| 11 |
+
speech, action, question, _ = telemetry_response(
|
| 12 |
+
{
|
| 13 |
+
"symptoms": "confusion",
|
| 14 |
+
"signal_quality": "good",
|
| 15 |
+
"age_seconds": 5,
|
| 16 |
+
"heart_rate_bpm": 88,
|
| 17 |
+
"spo2_pct": 91,
|
| 18 |
+
}
|
| 19 |
+
)
|
| 20 |
+
self.assertEqual(action, "ACTIVATE_EMERGENCY")
|
| 21 |
+
self.assertIn("emergency", speech.lower())
|
| 22 |
+
self.assertIsNotNone(question)
|
| 23 |
+
|
| 24 |
+
def test_low_quality_never_becomes_diagnosis(self) -> None:
|
| 25 |
+
speech, action, _, _ = telemetry_response(
|
| 26 |
+
{
|
| 27 |
+
"symptoms": "none",
|
| 28 |
+
"signal_quality": "low",
|
| 29 |
+
"age_seconds": 5,
|
| 30 |
+
"heart_rate_bpm": 170,
|
| 31 |
+
"spo2_pct": 62,
|
| 32 |
+
}
|
| 33 |
+
)
|
| 34 |
+
self.assertEqual(action, "RECHECK_SENSOR")
|
| 35 |
+
self.assertIn("cannot rely", speech.lower())
|
| 36 |
+
|
| 37 |
+
def test_assistant_schema(self) -> None:
|
| 38 |
+
output = json.loads(assistant_json("ok", "CONTINUE_MONITORING", None, []))
|
| 39 |
+
self.assertEqual(set(output), {"speech", "next_action", "question", "uncertainties"})
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
if __name__ == "__main__":
|
| 43 |
+
unittest.main()
|
| 44 |
+
|