-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Medical-Event-Data-Standard/tp/add_tests
Add tests for the three schema (patient_schema, label, dataset_metadata)
- Loading branch information
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import datetime | ||
|
||
import jsonschema | ||
import pyarrow as pa | ||
import pytest | ||
|
||
from meds import patient_schema, label, dataset_metadata | ||
|
||
|
||
def test_patient_schema(): | ||
""" | ||
Test that mock patient data follows the patient_schema schema. | ||
""" | ||
# Each element in the list is a row in the table | ||
patient_data = [ | ||
{ | ||
"patient_id": 123, | ||
"events": [{ # Nested list for events | ||
"time": datetime.datetime(2020, 1, 1, 12, 0, 0), | ||
"measurements": [{ # Nested list for measurements | ||
"code": "some_code", | ||
"text_value": "Example", | ||
"numeric_value": 10.0, | ||
"datetime_value": datetime.datetime(2020, 1, 1, 12, 0, 0), | ||
"metadata": None | ||
}] | ||
}] | ||
} | ||
] | ||
|
||
patient_table = pa.Table.from_pylist(patient_data, schema=patient_schema()) | ||
assert patient_table.schema.equals(patient_schema()), "Patient schema does not match" | ||
|
||
def test_label_schema(): | ||
""" | ||
Test that mock label data follows the label schema. | ||
""" | ||
# Each element in the list is a row in the table | ||
label_data = [ | ||
{ | ||
"patient_id": 123, | ||
"prediction_time": datetime.datetime(2020, 1, 1, 12, 0, 0), | ||
"boolean_value": True | ||
} | ||
] | ||
|
||
label_table = pa.Table.from_pylist(label_data, schema=label) | ||
assert label_table.schema.equals(label), "Label schema does not match" | ||
|
||
def test_dataset_metadata_schema(): | ||
""" | ||
Test that mock metadata follows dataset_metadata schema. | ||
""" | ||
metadata = { | ||
"dataset_name": "Test Dataset", | ||
"dataset_version": "1.0", | ||
"etl_name": "Test ETL", | ||
"etl_version": "1.0", | ||
"code_metadata": { | ||
"test_code": { | ||
"description": "A test code", | ||
"standard_ontology_codes": ["12345"], | ||
} | ||
}, | ||
} | ||
|
||
jsonschema.validate(instance=metadata, schema=dataset_metadata) | ||
assert True, "Dataset metadata schema validation failed" |