Skip to content

input4mips_validation.cvs.exceptions#

input4mips_validation.cvs.exceptions #

Exceptions related to CVs

ValueInconsistentWithCVsError #

Bases: ValueError

Raised when a value is inconsistent with the value expected by the CVs

Source code in src/input4mips_validation/cvs/exceptions.py
class ValueInconsistentWithCVsError(ValueError):
    """
    Raised when a value is inconsistent with the value expected by the CVs
    """

    def __init__(  # noqa: PLR0913
        self,
        value: str,
        expected_value: str,
        cv_component: str,
        cv_component_dependent_on: str,
        cv_entry_dependenty_component: Any,
    ) -> None:
        """
        Initialise the error

        Parameters
        ----------
        value
            The invalid value

        expected_value
            The value expected by the CVs

        cv_component
            The component of the CVs being considered

        cv_component_dependent_on
            The component of the CVs that the component being considered is dependent on

        cv_entry_dependenty_component
            The entry that defines the value, as it is in the CVs
        """
        error_msg = (
            f"The value provided for {cv_component} was {value!r}. "
            "According to the CVs, "
            f"{cv_component} depends on the value of {cv_component_dependent_on}. "
            f"As a result, {cv_component} must be {expected_value!r}. "
            f"If helpful, the full CV entry for {cv_component_dependent_on} is: "
            f"{cv_entry_dependenty_component}."
        )

        super().__init__(error_msg)

__init__(value, expected_value, cv_component, cv_component_dependent_on, cv_entry_dependenty_component) #

Initialise the error

Parameters:

Name Type Description Default
value str

The invalid value

required
expected_value str

The value expected by the CVs

required
cv_component str

The component of the CVs being considered

required
cv_component_dependent_on str

The component of the CVs that the component being considered is dependent on

required
cv_entry_dependenty_component Any

The entry that defines the value, as it is in the CVs

required
Source code in src/input4mips_validation/cvs/exceptions.py
def __init__(  # noqa: PLR0913
    self,
    value: str,
    expected_value: str,
    cv_component: str,
    cv_component_dependent_on: str,
    cv_entry_dependenty_component: Any,
) -> None:
    """
    Initialise the error

    Parameters
    ----------
    value
        The invalid value

    expected_value
        The value expected by the CVs

    cv_component
        The component of the CVs being considered

    cv_component_dependent_on
        The component of the CVs that the component being considered is dependent on

    cv_entry_dependenty_component
        The entry that defines the value, as it is in the CVs
    """
    error_msg = (
        f"The value provided for {cv_component} was {value!r}. "
        "According to the CVs, "
        f"{cv_component} depends on the value of {cv_component_dependent_on}. "
        f"As a result, {cv_component} must be {expected_value!r}. "
        f"If helpful, the full CV entry for {cv_component_dependent_on} is: "
        f"{cv_entry_dependenty_component}."
    )

    super().__init__(error_msg)

ValueNotAllowedByCVsError #

Bases: ValueError

Raised when a value is not in the values allowed by the CVs

Source code in src/input4mips_validation/cvs/exceptions.py
class ValueNotAllowedByCVsError(ValueError):
    """
    Raised when a value is not in the values allowed by the CVs
    """

    def __init__(
        self,
        value: str,
        cv_component: str,
        cv_allowed_values: Collection[str],
        cv_entries: Collection[Any],
    ) -> None:
        """
        Initialise the error

        Parameters
        ----------
        value
            The invalid value

        cv_component
            The component of the CVs being considered

        cv_allowed_values
            The values that the attribute can have, according to the CVs

        cv_entries
            The full entries as they are in the CVs
        """
        entries_newline = "\n".join([str(entry) for entry in cv_entries])

        error_msg = (
            f"The value provided for {cv_component} was {value!r}. "
            "According to the CVs, "
            f"{cv_component} must be one of {cv_allowed_values!r}. "
            f"If helpful, the full CV entries are:\n{entries_newline}."
        )

        super().__init__(error_msg)

__init__(value, cv_component, cv_allowed_values, cv_entries) #

Initialise the error

Parameters:

Name Type Description Default
value str

The invalid value

required
cv_component str

The component of the CVs being considered

required
cv_allowed_values Collection[str]

The values that the attribute can have, according to the CVs

required
cv_entries Collection[Any]

The full entries as they are in the CVs

required
Source code in src/input4mips_validation/cvs/exceptions.py
def __init__(
    self,
    value: str,
    cv_component: str,
    cv_allowed_values: Collection[str],
    cv_entries: Collection[Any],
) -> None:
    """
    Initialise the error

    Parameters
    ----------
    value
        The invalid value

    cv_component
        The component of the CVs being considered

    cv_allowed_values
        The values that the attribute can have, according to the CVs

    cv_entries
        The full entries as they are in the CVs
    """
    entries_newline = "\n".join([str(entry) for entry in cv_entries])

    error_msg = (
        f"The value provided for {cv_component} was {value!r}. "
        "According to the CVs, "
        f"{cv_component} must be one of {cv_allowed_values!r}. "
        f"If helpful, the full CV entries are:\n{entries_newline}."
    )

    super().__init__(error_msg)