RuleChecker Class
- class kwhelp.checks.RuleChecker(rules_all: Optional[Iterable[kwhelp.rules.IRule]] = None, rules_any: Optional[Iterable[kwhelp.rules.IRule]] = None, **kwargs)[source]
Class that validates args match a given rule
- __init__(rules_all: Optional[Iterable[kwhelp.rules.IRule]] = None, rules_any: Optional[Iterable[kwhelp.rules.IRule]] = None, **kwargs)[source]
Constructor
- Parameters
- Keyword Arguments
raise_error (bool, optional) – If
True
then rules can raise errors when validation fails. DefaultFalse
.- Raises
TypeError – If
rule_all
is not an iterable objectTypeError – If
rule_any
is not an iterable object
- validate_all(*args, **kwargs) bool [source]
Validates all. All
*args
and**kwargs
must matchrules_all
- Returns
True
if all*args
and**kwargs
are valid; Otherwise,False
- Return type
bool
- Raises
Exception – If
raise_error
isTrue
and validation Fails. The type of exception raised is dependend on theIRule
that caused validation failure. Most rules raise aValueError
or aTypeError
.
- validate_any(*args, **kwargs) bool [source]
Validates any. All
*args
and**kwargs
must match on ore more ofrules_any
- Returns
True
if all*args
and**kwargs
are valid; Otherwise,False
- Return type
bool
- Raises
Exception – If
raise_error
isTrue
and validation Fails. The type of exception raised is dependend on theIRule
that caused validation failure. Most rules raise aValueError
or aTypeError
.
- property raise_error: bool
Determines if errors will be raised during validation
If
True
then errors will be raised when validation fails. Default value isTrue
.- Getter
Gets if errors can be raised.
- Setter
Sets if errors can be raised.
- property rules_all: Iterable[kwhelp.rules.IRule]
Gets rules passed into
rules_all
of constructor used for validation of args.
- property rules_any: Iterable[kwhelp.rules.IRule]
Gets rules passed into
rules_any
of constructor used for validation of args.