Skip to content

Commit 06b4aee

Browse files
committed
Pass tests
1 parent 37fada4 commit 06b4aee

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
Validation of the `comment` attribute
3+
"""
4+
5+
from __future__ import annotations
6+
7+
8+
def validate_comment(comment: str) -> None:
9+
"""
10+
Validate the comment value
11+
12+
Parameters
13+
----------
14+
comment
15+
Tracking ID value to validate
16+
17+
Raises
18+
------
19+
TypeError
20+
`comment`'s value is not a string
21+
"""
22+
if not isinstance(comment, str):
23+
msg = f"The `comment` attribute must be a string, received {comment=!r}."
24+
raise TypeError(msg)

src/input4mips_validation/validation/datasets_to_write_to_disk.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import xarray as xr
1212

1313
from input4mips_validation.cvs import Input4MIPsCVs
14+
from input4mips_validation.validation.comment import validate_comment
1415
from input4mips_validation.validation.creation_date import validate_creation_date
1516
from input4mips_validation.validation.error_catching import (
1617
ValidationResultsStore,
@@ -94,7 +95,7 @@ def validate_attribute(
9495
if attribute not in ds.attrs:
9596
raise MissingAttributeError(attribute)
9697

97-
attribute_value = str(ds.attrs[attribute])
98+
attribute_value = ds.attrs[attribute]
9899
validation_function(attribute_value)
99100

100101

@@ -136,8 +137,8 @@ def validate_attribute_that_depends_on_other_attribute(
136137
if attribute_dependent_on not in ds.attrs:
137138
raise MissingAttributeError(attribute_dependent_on)
138139

139-
attribute_value = str(ds.attrs[attribute])
140-
attribute_dependent_on_value = str(ds.attrs[attribute_dependent_on])
140+
attribute_value = ds.attrs[attribute]
141+
attribute_dependent_on_value = ds.attrs[attribute_dependent_on]
141142
validation_function(attribute_value, attribute_dependent_on_value)
142143

143144

@@ -182,10 +183,16 @@ def get_ds_to_write_to_disk_validation_result(
182183
vrs = ValidationResultsStore()
183184

184185
# Metadata that can be validated standalone
185-
verification_standalone = (
186+
verification_standalone_l = [
186187
("creation_date", validate_creation_date),
187188
("tracking_id", validate_tracking_id),
188-
)
189+
]
190+
# Optional attributes
191+
for optional_attr, verification_func in (("comment", validate_comment),):
192+
if optional_attr in ds.attrs:
193+
verification_standalone_l.append((optional_attr, verification_func))
194+
195+
verification_standalone = tuple(verification_standalone_l)
189196

190197
# Metadata that depends on the data
191198
ds_variables = xr_variable_processor.get_ds_variables(

0 commit comments

Comments
 (0)