Skip to content

cross_validator

Class and interface definitions for top level validators.

CompositeValidator

Class to compose CrossValidators.

Source code in mlte/store/validators/cross_validator.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
class CompositeValidator:
    """Class to compose CrossValidators."""

    def __init__(self, validators: list[CrossValidator] = []):
        """Initialize a CompositeValidator instance."""

        self.validators: list[CrossValidator] = validators
        """List of validators to execute."""

    def validate_all(self, new_resource: Any):
        """Validate all validators."""
        if self.validators:
            for validator in self.validators:
                validator.validate(new_resource)

validators = validators instance-attribute

List of validators to execute.

__init__(validators=[])

Initialize a CompositeValidator instance.

Source code in mlte/store/validators/cross_validator.py
12
13
14
15
16
def __init__(self, validators: list[CrossValidator] = []):
    """Initialize a CompositeValidator instance."""

    self.validators: list[CrossValidator] = validators
    """List of validators to execute."""

validate_all(new_resource)

Validate all validators.

Source code in mlte/store/validators/cross_validator.py
18
19
20
21
22
def validate_all(self, new_resource: Any):
    """Validate all validators."""
    if self.validators:
        for validator in self.validators:
            validator.validate(new_resource)

CrossValidator

Bases: ABC

Interface to define a CrossValidator that validates store entries against data in separate stores.

Source code in mlte/store/validators/cross_validator.py
25
26
27
28
29
30
31
32
33
34
35
36
37
class CrossValidator(ABC):
    """Interface to define a CrossValidator that validates store entries against data in separate stores."""

    @abstractmethod
    def validate(self, new_resource: Any) -> None:
        """
        Validate a resource.
        :param new_resource: The data to create or edit the resource to be validated
        :raises RuntimeError: On failed validation
        """
        raise NotImplementedError(
            "Can't validate without a specific implementation."
        )

validate(new_resource) abstractmethod

Validate a resource.

Parameters:

Name Type Description Default
new_resource Any

The data to create or edit the resource to be validated

required

Raises:

Type Description
RuntimeError

On failed validation

Source code in mlte/store/validators/cross_validator.py
28
29
30
31
32
33
34
35
36
37
@abstractmethod
def validate(self, new_resource: Any) -> None:
    """
    Validate a resource.
    :param new_resource: The data to create or edit the resource to be validated
    :raises RuntimeError: On failed validation
    """
    raise NotImplementedError(
        "Can't validate without a specific implementation."
    )