onecondition
An ultra-lightweight package for validating single conditions.
- Example:
>>> import onecondition as oc >>> oc.validate.not_negative(42) >>> oc.validate.range_non_inclusive(0, 0, 1) Traceback (most recent call last): ... onecondition.ValidationError: Value `0` must be between 0 and 1 (non-inclusive)
Submodules
Package Contents
- exception onecondition.ValidationError(value: Any, condition: str, message_format: str = 'Value `{value_repr}` must {condition}')
Bases:
ValueErrorA subclass of ValueError, this is raised any time a validation check fails.
- Parameters:
value (Any) – The value to use in the error message
condition (str) – The descriptive condition under which the error is raised
message_format (str) – The format string to use for the message. Supports “{value}, {value_repr}, and {condition}”
- Example:
>>> raise ValidationError(42, "be the answer to life, the universe, and everything") Traceback (most recent call last): ... onecondition.ValidationError: Value `42` must be the answer to life, the universe, and everything