Skip to content

all_validator

trestle.core.all_validator ¤

Validate based on all registered validators.

Classes¤

AllValidator ¤

Bases: Validator

Validator to confirm the model passes all registered validation tests.

Source code in trestle/core/all_validator.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
Attributes¤
last_failure_msg: str instance-attribute ¤
Functions¤
error_msg() ¤

Return information on which validation failed.

Source code in trestle/core/all_validator.py
30
31
32
def error_msg(self) -> str:
    """Return information on which validation failed."""
    return self.last_failure_msg
model_is_valid(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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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