Skip to content

input4mips_validation.validation.Conventions#

input4mips_validation.validation.Conventions #

Validation of the Conventions attribute

REGEXP_TO_MATCH: str = 'CF-[0-9]+\\.[0-9]+' module-attribute #

Regular expression that the Conventions attribute must match

This constant is exposed for clarity. If you change it, we do not guarantee correct performance of the codebase.

validate_Conventions(Conventions) #

Validate the Conventions value

Parameters:

Name Type Description Default
Conventions str

Conventions value to validate.

required

Raises:

Type Description
ValueError

Conventions's value is incorrect

Source code in src/input4mips_validation/validation/Conventions.py
def validate_Conventions(Conventions: str) -> None:
    """
    Validate the Conventions value

    Parameters
    ----------
    Conventions
        Conventions value to validate.

    Raises
    ------
    ValueError
        `Conventions`'s value is incorrect
    """
    try:
        validate_matches_regexp(
            value=Conventions,
            regexp_to_match=REGEXP_TO_MATCH,
        )

    except DoesNotMatchRegexpError as exc:
        msg = (
            f"The `Conventions` attribute must be of the form 'CF-X.Y', "
            f"i.e. match the regular expression {REGEXP_TO_MATCH!r}. "
            f"Received {Conventions=!r}."
        )
        raise ValueError(msg) from exc