|
11 | 11 | import xarray as xr |
12 | 12 |
|
13 | 13 | from input4mips_validation.cvs import Input4MIPsCVs |
| 14 | +from input4mips_validation.validation.comment import validate_comment |
14 | 15 | from input4mips_validation.validation.creation_date import validate_creation_date |
15 | 16 | from input4mips_validation.validation.error_catching import ( |
16 | 17 | ValidationResultsStore, |
@@ -94,7 +95,7 @@ def validate_attribute( |
94 | 95 | if attribute not in ds.attrs: |
95 | 96 | raise MissingAttributeError(attribute) |
96 | 97 |
|
97 | | - attribute_value = str(ds.attrs[attribute]) |
| 98 | + attribute_value = ds.attrs[attribute] |
98 | 99 | validation_function(attribute_value) |
99 | 100 |
|
100 | 101 |
|
@@ -136,8 +137,8 @@ def validate_attribute_that_depends_on_other_attribute( |
136 | 137 | if attribute_dependent_on not in ds.attrs: |
137 | 138 | raise MissingAttributeError(attribute_dependent_on) |
138 | 139 |
|
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] |
141 | 142 | validation_function(attribute_value, attribute_dependent_on_value) |
142 | 143 |
|
143 | 144 |
|
@@ -182,10 +183,16 @@ def get_ds_to_write_to_disk_validation_result( |
182 | 183 | vrs = ValidationResultsStore() |
183 | 184 |
|
184 | 185 | # Metadata that can be validated standalone |
185 | | - verification_standalone = ( |
| 186 | + verification_standalone_l = [ |
186 | 187 | ("creation_date", validate_creation_date), |
187 | 188 | ("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) |
189 | 196 |
|
190 | 197 | # Metadata that depends on the data |
191 | 198 | ds_variables = xr_variable_processor.get_ds_variables( |
|
0 commit comments