Skip to content

Commit

Permalink
Add Tests for Schema Functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Alrobbertz committed Jul 11, 2023
1 parent f8ab8cc commit 0811468
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
7 changes: 6 additions & 1 deletion hermes_core/util/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self):
)

# Load Default Global Attributes
self.default_global_attributes = HERMESDataSchema._load_default_attributes()
self._default_global_attributes = HERMESDataSchema._load_default_attributes()

@property
def global_attribute_schema(self):
Expand All @@ -46,6 +46,11 @@ def variable_attribute_schema(self):
"""Schema for variable attributes of the file."""
return self._variable_attr_schema

@property
def default_global_attributes(self):
"""Default Global Attributes applied for all HERMES Data Files"""
return self._default_global_attributes

@staticmethod
def _load_default_global_attr_schema() -> dict:
# The Default Schema file is contained in the `hermes_core/data` directory
Expand Down
44 changes: 44 additions & 0 deletions hermes_core/util/tests/test_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import pytest
from collections import OrderedDict
from astropy.table import Table
from hermes_core.util.schema import HERMESDataSchema


def test_hermes_data_schema():
schema = HERMESDataSchema()

# Global Attribute Schema
assert schema.global_attribute_schema is not None
assert isinstance(schema.global_attribute_schema, dict)

# Variable Attribute Schema
assert schema.variable_attribute_schema is not None
assert isinstance(schema.variable_attribute_schema, dict)

# Default Globla Attributes
assert schema.default_global_attributes is not None
assert isinstance(schema.default_global_attributes, dict)

# Global Attribute Template
assert schema.global_attribute_template() is not None
assert isinstance(schema.global_attribute_template(), OrderedDict)

# Measurement Attribute Template
assert schema.measurement_attribute_template() is not None
assert isinstance(schema.measurement_attribute_template(), OrderedDict)

# Global Attribute Info
assert schema.global_attribute_info() is not None
assert isinstance(schema.global_attribute_info(), Table)
assert isinstance(schema.global_attribute_info(attribute_name="Descriptor"), Table)
with pytest.raises(KeyError):
_ = schema.global_attribute_info(attribute_name="NotAnAttribute")

# Measurement Attribute Info
assert schema.measurement_attribute_info() is not None
assert isinstance(schema.measurement_attribute_info(), Table)
assert isinstance(
schema.measurement_attribute_info(attribute_name="CATDESC"), Table
)
with pytest.raises(KeyError):
_ = schema.measurement_attribute_info(attribute_name="NotAnAttribute")

0 comments on commit 0811468

Please sign in to comment.