Skip to content

all_validator

trestle.core.all_validator ¤

Validate based on all registered validators.

Classes¤

AllValidator (Validator) ¤

Validator to confirm the model passes all registered validation tests.

Source code in trestle/core/all_validator.py
class AllValidator(Validator):
    """Validator to confirm the model passes all registered validation tests."""

    last_failure_msg: str

    def error_msg(self) -> str:
        """Return information on which validation failed."""
        return self.last_failure_msg

    def model_is_valid(self, model: OscalBaseModel, quiet: bool, trestle_root: Optional[pathlib.Path] = None) -> bool:
        """
        Validate an oscal model against all available validators in the trestle library.

        args:
            model: An Oscal model that can be passed to the validator.
            quiet: Don't report msgs unless invalid.

        returns:
            True (valid) if the model passed all registered validators.
        """
        self.last_failure_msg = self.__doc__
        for val in vfact.validator_factory.get_all():
            if val != self and not val.model_is_valid(model, quiet, trestle_root):
                self.last_failure_msg = val.error_msg()
                return False
        return True
Methods¤
error_msg(self) ¤

Return information on which validation failed.

Source code in trestle/core/all_validator.py
def error_msg(self) -> str:
    """Return information on which validation failed."""
    return self.last_failure_msg
model_is_valid(self, model, quiet, trestle_root=None) ¤

Validate an oscal model against all available validators in the trestle library.

Parameters:

Name Type Description Default
model OscalBaseModel

An Oscal model that can be passed to the validator.

required
quiet bool

Don't report msgs unless invalid.

required

Returns:

Type Description
bool

True (valid) if the model passed all registered validators.

Source code in trestle/core/all_validator.py
def model_is_valid(self, model: OscalBaseModel, quiet: bool, trestle_root: Optional[pathlib.Path] = None) -> bool:
    """
    Validate an oscal model against all available validators in the trestle library.

    args:
        model: An Oscal model that can be passed to the validator.
        quiet: Don't report msgs unless invalid.

    returns:
        True (valid) if the model passed all registered validators.
    """
    self.last_failure_msg = self.__doc__
    for val in vfact.validator_factory.get_all():
        if val != self and not val.model_is_valid(model, quiet, trestle_root):
            self.last_failure_msg = val.error_msg()
            return False
    return True

handler: python