diff --git a/src/input4mips_validation/validation/comment.py b/src/input4mips_validation/validation/comment.py index 0cfc77b8..9c5da385 100644 --- a/src/input4mips_validation/validation/comment.py +++ b/src/input4mips_validation/validation/comment.py @@ -20,5 +20,7 @@ def validate_comment(comment: str) -> None: `comment`'s value is not a string """ if not isinstance(comment, str): - msg = f"The `comment` attribute must be a string, received {comment=!r}." + msg = ( # type: ignore[unreachable] + f"The `comment` attribute must be a string, received {comment=!r}." + ) raise TypeError(msg) diff --git a/src/input4mips_validation/validation/datasets_to_write_to_disk.py b/src/input4mips_validation/validation/datasets_to_write_to_disk.py index 9dfa9faf..a11934ae 100644 --- a/src/input4mips_validation/validation/datasets_to_write_to_disk.py +++ b/src/input4mips_validation/validation/datasets_to_write_to_disk.py @@ -183,16 +183,10 @@ def get_ds_to_write_to_disk_validation_result( vrs = ValidationResultsStore() # Metadata that can be validated standalone - verification_standalone_l = [ + verification_standalone = ( ("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( @@ -227,6 +221,16 @@ def get_ds_to_write_to_disk_validation_result( func_description=f"Validate the {attribute!r} attribute", )(ds, attribute, validation_function) + # Optional attributes + for attribute_optional, validation_function_optional in ( + ("comment", validate_comment), + ): + if attribute_optional in ds.attrs: + vrs.wrap( + validate_attribute, + func_description=f"Validate the {attribute_optional!r} attribute", + )(ds, attribute_optional, validation_function_optional) + # Metadata that is defined by the combination of other metadata and the CVs verification_defined_by_cvs_and_other_metadata = ( (