Datasets:
Download tests/test_schema.py from ulamai/UnsolvedMedical: direct link, hf CLI and curl.
- Browser
- Download file 2.41 kB
-
https://huggingface.co/datasets/ulamai/UnsolvedMedical/resolve/main/tests/test_schema.py
- Command line
-
hf download hf://datasets/ulamai/UnsolvedMedical/tests/test_schema.py
-
curl -L -o test_schema.py https://huggingface.co/datasets/ulamai/UnsolvedMedical/resolve/main/tests/test_schema.py
2.41 kB
| #!/usr/bin/env python3 | |
| """Unit tests for UnsolvedMed JSON Schemas (Section 7 & Section 13.4).""" | |
| import json | |
| import unittest | |
| from pathlib import Path | |
| from jsonschema import Draft202012Validator | |
| ROOT = Path(__file__).resolve().parent.parent | |
| class TestSchemas(unittest.TestCase): | |
| def test_all_schemas_valid_and_records_conform(self): | |
| prob_schema = json.loads((ROOT / "schemas" / "problem.schema.json").read_text(encoding="utf-8")) | |
| src_schema = json.loads((ROOT / "schemas" / "source.schema.json").read_text(encoding="utf-8")) | |
| stat_schema = json.loads((ROOT / "schemas" / "status_event.schema.json").read_text(encoding="utf-8")) | |
| rel_schema = json.loads((ROOT / "schemas" / "relation.schema.json").read_text(encoding="utf-8")) | |
| prob_v = Draft202012Validator(prob_schema) | |
| src_v = Draft202012Validator(src_schema) | |
| stat_v = Draft202012Validator(stat_schema) | |
| rel_v = Draft202012Validator(rel_schema) | |
| published_records = json.loads((ROOT / "problems.json").read_text(encoding="utf-8")) | |
| archived_records = [ | |
| json.loads(line) | |
| for line in (ROOT / "data" / "archived" / "problems.jsonl").read_text(encoding="utf-8").splitlines() | |
| if line.strip() | |
| ] | |
| all_records = published_records + archived_records | |
| for i, rec in enumerate(all_records): | |
| if i % 250 == 0 or i >= len(all_records) - 100: | |
| errs = list(prob_v.iter_errors(rec)) | |
| self.assertEqual(errs, [], f"Schema errors in {rec.get('id')}: {errs}") | |
| sources = json.loads((ROOT / "source_registry.json").read_text(encoding="utf-8")) | |
| for i, rec in enumerate(sources): | |
| if i % 250 == 0: | |
| self.assertEqual(list(src_v.iter_errors(rec)), []) | |
| with (ROOT / "history" / "status_events.jsonl").open("r", encoding="utf-8") as f: | |
| for i, line in enumerate(f): | |
| if i % 250 == 0: | |
| rec = json.loads(line) | |
| self.assertEqual(list(stat_v.iter_errors(rec)), []) | |
| with (ROOT / "relations" / "relations.jsonl").open("r", encoding="utf-8") as f: | |
| for i, line in enumerate(f): | |
| if i % 100 == 0: | |
| rec = json.loads(line) | |
| self.assertEqual(list(rel_v.iter_errors(rec)), []) | |
| if __name__ == "__main__": | |
| unittest.main() | |