simdb.validation.validator module¶
- class simdb.validation.validator.CustomValidator(*args, **kwargs)[source]¶
Bases:
ValidatorValidator class. Normalizes and/or validates any mapping against a validation-schema which is provided as an argument at class instantiation or upon calling the
validate(),validated()ornormalized()method. An instance itself is callable and executes a validation.All instantiation parameters are optional.
There are the introspective properties
types,validators,coercers,default_setters,rules,normalization_rulesandvalidation_rules.The attributes reflecting the available rules are assembled considering constraints that are defined in the docstrings of rules’ methods and is effectively used as validation schema for
schema.- Parameters:
schema (any mapping) – See
schema. Defaults toNone.ignore_none_values (
bool) – Seeignore_none_values. Defaults toFalse.allow_unknown (
boolor any mapping) – Seeallow_unknown. Defaults toFalse.require_all (
bool) – Seerequire_all. Defaults toFalse.purge_unknown (
bool) – Seepurge_unknown. Defaults to toFalse.purge_readonly (
bool) – Removes all fields that are defined asreadonlyin the normalization phase.error_handler (class or instance based on
BaseErrorHandlerortuple) – The error handler that formats the result oferrors. When given as two-value tuple with an error-handler class and a dictionary, the latter is passed to the initialization of the error handler. Default:BasicErrorHandler.
- checkers = ()¶
- coercers = ('float', 'int', 'numpy')¶
- default_setters = ()¶
- normalization_rules = {'coerce': {'oneof': [{'type': 'callable'}, {'schema': {'oneof': [{'type': 'callable'}, {'allowed': ('float', 'int', 'numpy'), 'type': 'string'}]}, 'type': 'list'}, {'allowed': ('float', 'int', 'numpy'), 'type': 'string'}]}, 'default': {'nullable': True}, 'default_setter': {'oneof': [{'type': 'callable'}, {'allowed': (), 'type': 'string'}]}, 'purge_unknown': {'type': 'boolean'}, 'rename': {'type': 'hashable'}, 'rename_handler': {'oneof': [{'type': 'callable'}, {'schema': {'oneof': [{'type': 'callable'}, {'allowed': ('float', 'int', 'numpy'), 'type': 'string'}]}, 'type': 'list'}, {'allowed': ('float', 'int', 'numpy'), 'type': 'string'}]}}¶
- np = <module 'numpy' from '/home/docs/checkouts/readthedocs.org/user_builds/simdb/envs/stable/lib/python3.11/site-packages/numpy/__init__.py'>¶
- rules = {'allof': {'logical': 'allof', 'type': 'list'}, 'allow_unknown': {'oneof': [{'type': 'boolean'}, {'check_with': 'bulk_schema', 'type': ['dict', 'string']}]}, 'allowed': {'type': 'container'}, 'anyof': {'logical': 'anyof', 'type': 'list'}, 'check_with': {'oneof': [{'type': 'callable'}, {'schema': {'oneof': [{'type': 'callable'}, {'allowed': (), 'type': 'string'}]}, 'type': 'list'}, {'allowed': (), 'type': 'string'}]}, 'checksum': {'check_with': 'type', 'type': ['string']}, 'coerce': {'oneof': [{'type': 'callable'}, {'schema': {'oneof': [{'type': 'callable'}, {'allowed': ('float', 'int', 'numpy'), 'type': 'string'}]}, 'type': 'list'}, {'allowed': ('float', 'int', 'numpy'), 'type': 'string'}]}, 'contains': {'empty': False}, 'default': {'nullable': True}, 'default_setter': {'oneof': [{'type': 'callable'}, {'allowed': (), 'type': 'string'}]}, 'dependencies': {'check_with': 'dependencies', 'type': ('dict', 'hashable', 'list')}, 'empty': {'type': 'boolean'}, 'excludes': {'schema': {'type': 'hashable'}, 'type': ('hashable', 'list')}, 'exists': {'check_with': 'type', 'type': ['string']}, 'forbidden': {'type': 'list'}, 'ge': {'type': 'float'}, 'gt': {'type': 'float'}, 'items': {'check_with': 'items', 'type': 'list'}, 'keysrules': {'check_with': 'bulk_schema', 'forbidden': ['rename', 'rename_handler'], 'type': ['dict', 'string']}, 'le': {'type': 'float'}, 'lt': {'type': 'float'}, 'max': {'nullable': False}, 'max_value': {'type': 'float'}, 'maxlength': {'type': 'integer'}, 'meta': {}, 'min': {'nullable': False}, 'min_value': {'type': 'float'}, 'minlength': {'type': 'integer'}, 'noneof': {'logical': 'noneof', 'type': 'list'}, 'nullable': {'type': 'boolean'}, 'oneof': {'logical': 'oneof', 'type': 'list'}, 'purge_unknown': {'type': 'boolean'}, 'readonly': {'type': 'boolean'}, 'regex': {'type': 'string'}, 'rename': {'type': 'hashable'}, 'rename_handler': {'oneof': [{'type': 'callable'}, {'schema': {'oneof': [{'type': 'callable'}, {'allowed': ('float', 'int', 'numpy'), 'type': 'string'}]}, 'type': 'list'}, {'allowed': ('float', 'int', 'numpy'), 'type': 'string'}]}, 'require_all': {'type': 'boolean'}, 'required': {'type': 'boolean'}, 'schema': {'anyof': [{'check_with': 'schema'}, {'check_with': 'bulk_schema'}], 'type': ['dict', 'string']}, 'type': {'check_with': 'type', 'type': ['string', 'list']}, 'valuesrules': {'check_with': 'bulk_schema', 'forbidden': ['rename', 'rename_handler'], 'type': ['dict', 'string']}}¶
- types_mapping = {'binary': ('binary', (<class 'bytes'>, <class 'bytearray'>), ()), 'boolean': ('boolean', (<class 'bool'>,), ()), 'container': ('container', (<class 'collections.abc.Container'>,), (<class 'str'>,)), 'date': ('date', (<class 'datetime.date'>,), ()), 'datetime': ('datetime', (<class 'datetime.datetime'>,), ()), 'dict': ('dict', (<class 'collections.abc.Mapping'>,), ()), 'float': ('float', (<class 'float'>, (<class 'int'>,)), ()), 'integer': ('integer', ((<class 'int'>,),), ()), 'list': ('list', (<class 'collections.abc.Sequence'>,), (<class 'str'>,)), 'number': ('number', ((<class 'int'>,), <class 'float'>), (<class 'bool'>,)), 'numpy': ('numpy', (<class 'numpy.ndarray'>,), ()), 'set': ('set', (<class 'set'>,), ()), 'string': ('string', (<class 'str'>,), ())}¶
This mapping holds all available constraints for the type rule and their assigned
TypeDefinition.
- validation_rules = {'allof': {'logical': 'allof', 'type': 'list'}, 'allow_unknown': {'oneof': [{'type': 'boolean'}, {'check_with': 'bulk_schema', 'type': ['dict', 'string']}]}, 'allowed': {'type': 'container'}, 'anyof': {'logical': 'anyof', 'type': 'list'}, 'check_with': {'oneof': [{'type': 'callable'}, {'schema': {'oneof': [{'type': 'callable'}, {'allowed': (), 'type': 'string'}]}, 'type': 'list'}, {'allowed': (), 'type': 'string'}]}, 'checksum': {'check_with': 'type', 'type': ['string']}, 'contains': {'empty': False}, 'dependencies': {'check_with': 'dependencies', 'type': ('dict', 'hashable', 'list')}, 'empty': {'type': 'boolean'}, 'excludes': {'schema': {'type': 'hashable'}, 'type': ('hashable', 'list')}, 'exists': {'check_with': 'type', 'type': ['string']}, 'forbidden': {'type': 'list'}, 'ge': {'type': 'float'}, 'gt': {'type': 'float'}, 'items': {'check_with': 'items', 'type': 'list'}, 'keysrules': {'check_with': 'bulk_schema', 'forbidden': ['rename', 'rename_handler'], 'type': ['dict', 'string']}, 'le': {'type': 'float'}, 'lt': {'type': 'float'}, 'max': {'nullable': False}, 'max_value': {'type': 'float'}, 'maxlength': {'type': 'integer'}, 'meta': {}, 'min': {'nullable': False}, 'min_value': {'type': 'float'}, 'minlength': {'type': 'integer'}, 'noneof': {'logical': 'noneof', 'type': 'list'}, 'nullable': {'type': 'boolean'}, 'oneof': {'logical': 'oneof', 'type': 'list'}, 'readonly': {'type': 'boolean'}, 'regex': {'type': 'string'}, 'require_all': {'type': 'boolean'}, 'required': {'type': 'boolean'}, 'schema': {'anyof': [{'check_with': 'schema'}, {'check_with': 'bulk_schema'}], 'type': ['dict', 'string']}, 'type': {'check_with': 'type', 'type': ['string', 'list']}, 'valuesrules': {'check_with': 'bulk_schema', 'forbidden': ['rename', 'rename_handler'], 'type': ['dict', 'string']}}¶
- class simdb.validation.validator.Validator(schema: Dict)[source]¶
Bases:
object- validate(sim: Simulation) None[source]¶
- classmethod validation_schemas(config: Config, simulation: Simulation | None, path=None) List[Dict][source]¶