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 the ValidatorEffect.

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.

as_json() Dict[source]

Parse the validator to a proper validator json.

validate_json() Any[source]

Validate the json representation of the validator against the validator jsonschema.

classmethod parse(json: Dict) Any[source]

Parse a json dict and return the correct subclass.

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 to pykechain.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

get_reason() AnyStr[source]

Retrieve the reason of the (in)validation.

Returns:

reason text

Return type:

basestring

class ValidatorEffect(json=None, *args, **kwargs)[source]

A Validator Effect.

This is an effect that can be associated with the PropertyValidator.on_valid or PropertyValidator.on_invalid. The effects associated are called based on the results of the validation of the PropertyValidator.

New in version 2.2.

Variables:

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 to enums.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

as_json() Dict[source]

JSON representation of the effect.

Returns:

a python dictionary, serializable as json of the effect

Return type:

dict