Skip to content

Commit

Permalink
Merge pull request #5 from Medical-Event-Data-Standard/tp/add_tests
Browse files Browse the repository at this point in the history
Add tests for the three schema (patient_schema, label, dataset_metadata)
  • Loading branch information
tompollard authored Jan 9, 2024
2 parents 4c651e3 + 016e2f9 commit 8dbd181
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions tests/test_schema.py
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"

0 comments on commit 8dbd181

Please sign in to comment.