models.validators.validators_base¶
Note
This module contains the base classes for all validators.
- class BaseValidator(json=None, *args, **kwargs)[source]¶
Base class for all Validators.
This is the base implementation for both the
PropertyValidator
as well as theValidatorEffect
.New in version 2.2.
- Variables:
jsonschema – jsonschema to validate the json representation of the Validator
accuracy – default value used in comparison of floats, normally 1E-6
Construct a base validator.
- class PropertyValidator(json=None, *args, **kwargs)[source]¶
Base class for all property validators.
If json is provided, the validator is instantiated based on that json.
New in version 2.2.
- Variables:
vtype – Validator type, one of
pykechain.enums.PropertyVTypes
jsonschema – jsonschema to validate the structure of the json representation of the effect against
Construct a Property Validator.
- classmethod parse(json: Dict) PropertyValidator [source]¶
Parse a json dict and return the correct subclass of
PropertyValidator
.It uses the ‘effect’ key to determine which
PropertyValidator
to instantiate. Please refer topykechain.enums.PropertyVTypes
for the supported effects.- Parameters:
json (dict) – dictionary containing the specific keys to parse into a
PropertyValidator
- Returns:
the instantiated subclass of
PropertyValidator
- Return type:
PropertyValidator
or subclass thereof
- as_json() Dict [source]¶
JSON representation of the effect.
- Returns:
a python dictionary, serializable as json of the effect
- Return type:
dict
- is_valid(value: Any) bool [source]¶
Check if the validation against a value, returns a boolean.
This is the logical inverse of the
is_invalid()
method.- Parameters:
value (Any) – The value to check against
- Returns:
True if valid, False if invalid
- Return type:
bool
- is_invalid(value: Any) bool [source]¶
Check if the validation against a value, returns a boolean.
This is the logical inverse of the
is_valid()
method.- Parameters:
value (Any) – The value to check against
- Returns:
True if INvalid, False if valid
- Return type:
bool
- class ValidatorEffect(json=None, *args, **kwargs)[source]¶
A Validator Effect.
This is an effect that can be associated with the
PropertyValidator.on_valid
orPropertyValidator.on_invalid
. The effects associated are called based on the results of the validation of thePropertyValidator
.New in version 2.2.
- Variables:
effect – Effect type, one of
pykechain.enums.ValidatorEffectTypes
jsonschema – jsonschema to validate the structure of the json representation of the effect against
Construct a Validator Effect.
- classmethod parse(json: Dict) ValidatorEffect [source]¶
Parse a json dict and return the correct subclass of
ValidatorEffect
.It uses the ‘effect’ key to determine which
ValidatorEffect
to instantiate. Please refer toenums.ValidatorEffectTypes
for the supported effects.- Parameters:
json (dict) – dictionary containing the specific keys to parse into a
ValidatorEffect
- Returns:
the instantiated subclass of
ValidatorEffect
- Return type:
ValidatorEffect
or subclass