Skip to content

model_condition

mlte/validation/model_condition.py

Model implementation for the Validator and Condition.

ConditionModel

Bases: BaseModel

A description of a condition for a QACategory.

Source code in mlte/validation/model_condition.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class ConditionModel(BaseModel):
    """A description of a condition for a QACategory."""

    name: str
    """A decriptive name for the condition, usually the method name used to call it."""

    arguments: list[Any] = []
    """The arguments used when validating the condition."""

    validator: ValidatorModel
    """A serialized version of the validator to execute when validating this condition."""

    value_class: Optional[str]
    """A string indicating the full module and class name of the Value used to generate this condition, if any."""

    def args_to_json_str(self) -> str:
        """
        Serialize the model arguments field into a string.
        :return: The JSON str representation of the model
        """
        # First convert whole thing, to see if arguments will trigger error (and if so, just let it bubble up).
        self.to_json()

        # Now convert only the actual arguments not only to JSON, but to a JSON string.
        json_str_args = json.dumps(self.arguments)
        return json_str_args

arguments = [] class-attribute instance-attribute

The arguments used when validating the condition.

name instance-attribute

A decriptive name for the condition, usually the method name used to call it.

validator instance-attribute

A serialized version of the validator to execute when validating this condition.

value_class instance-attribute

A string indicating the full module and class name of the Value used to generate this condition, if any.

args_to_json_str()

Serialize the model arguments field into a string.

Returns:

Type Description
str

The JSON str representation of the model

Source code in mlte/validation/model_condition.py
56
57
58
59
60
61
62
63
64
65
66
def args_to_json_str(self) -> str:
    """
    Serialize the model arguments field into a string.
    :return: The JSON str representation of the model
    """
    # First convert whole thing, to see if arguments will trigger error (and if so, just let it bubble up).
    self.to_json()

    # Now convert only the actual arguments not only to JSON, but to a JSON string.
    json_str_args = json.dumps(self.arguments)
    return json_str_args

ValidatorModel

Bases: BaseModel

A description of a validator for a test.

Source code in mlte/validation/model_condition.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class ValidatorModel(BaseModel):
    """A description of a validator for a test."""

    bool_exp: Optional[str]
    """A text-encoded, dilled-serialized version of the function to execute when checking the bool condition."""

    bool_exp_str: Optional[str]
    """A string representation of the code for the bool expression to check for."""

    success: Optional[str]
    """A string to be used when recording that the validation was succesful."""

    failure: Optional[str]
    """A string to be used when recording that the validation was not succesful."""

    info: Optional[str]
    """A string to be used when recording that the validation was not checked against a condition, just recorded information."""

    creator_class: Optional[str] = None
    """The name of the class used to create this validator, if any."""

    creator_function: Optional[str] = None
    """The name of the function used to create this validator, if any."""

    creator_args: list[Any] = []
    """The arguments of the function used to create this validator, if any."""

bool_exp instance-attribute

A text-encoded, dilled-serialized version of the function to execute when checking the bool condition.

bool_exp_str instance-attribute

A string representation of the code for the bool expression to check for.

creator_args = [] class-attribute instance-attribute

The arguments of the function used to create this validator, if any.

creator_class = None class-attribute instance-attribute

The name of the class used to create this validator, if any.

creator_function = None class-attribute instance-attribute

The name of the function used to create this validator, if any.

failure instance-attribute

A string to be used when recording that the validation was not succesful.

info instance-attribute

A string to be used when recording that the validation was not checked against a condition, just recorded information.

success instance-attribute

A string to be used when recording that the validation was succesful.