Skip to content

Commit

Permalink
Pass tests
Browse files Browse the repository at this point in the history
  • Loading branch information
znichollscr committed Dec 16, 2024
1 parent 37fada4 commit 06b4aee
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
24 changes: 24 additions & 0 deletions src/input4mips_validation/validation/comment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
Validation of the `comment` attribute
"""

from __future__ import annotations


def validate_comment(comment: str) -> None:
"""
Validate the comment value
Parameters
----------
comment
Tracking ID value to validate
Raises
------
TypeError
`comment`'s value is not a string
"""
if not isinstance(comment, str):
msg = f"The `comment` attribute must be a string, received {comment=!r}."
raise TypeError(msg)
17 changes: 12 additions & 5 deletions src/input4mips_validation/validation/datasets_to_write_to_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import xarray as xr

from input4mips_validation.cvs import Input4MIPsCVs
from input4mips_validation.validation.comment import validate_comment
from input4mips_validation.validation.creation_date import validate_creation_date
from input4mips_validation.validation.error_catching import (
ValidationResultsStore,
Expand Down Expand Up @@ -94,7 +95,7 @@ def validate_attribute(
if attribute not in ds.attrs:
raise MissingAttributeError(attribute)

attribute_value = str(ds.attrs[attribute])
attribute_value = ds.attrs[attribute]
validation_function(attribute_value)


Expand Down Expand Up @@ -136,8 +137,8 @@ def validate_attribute_that_depends_on_other_attribute(
if attribute_dependent_on not in ds.attrs:
raise MissingAttributeError(attribute_dependent_on)

attribute_value = str(ds.attrs[attribute])
attribute_dependent_on_value = str(ds.attrs[attribute_dependent_on])
attribute_value = ds.attrs[attribute]
attribute_dependent_on_value = ds.attrs[attribute_dependent_on]
validation_function(attribute_value, attribute_dependent_on_value)


Expand Down Expand Up @@ -182,10 +183,16 @@ def get_ds_to_write_to_disk_validation_result(
vrs = ValidationResultsStore()

# Metadata that can be validated standalone
verification_standalone = (
verification_standalone_l = [
("creation_date", validate_creation_date),
("tracking_id", validate_tracking_id),
)
]
# Optional attributes
for optional_attr, verification_func in (("comment", validate_comment),):
if optional_attr in ds.attrs:
verification_standalone_l.append((optional_attr, verification_func))

verification_standalone = tuple(verification_standalone_l)

# Metadata that depends on the data
ds_variables = xr_variable_processor.get_ds_variables(
Expand Down

0 comments on commit 06b4aee

Please sign in to comment.