expyct.number module
- class expyct.number.CloseTo(close_to: Optional[numbers.Number] = None, error: float = 0.001)
Bases:
expyct.base.BaseMatcher
Mixin for matching number that is close to given target within a certain two-side error. In other words, the difference between the number and close_to must be at most error.
- Parameters
close_to – number must be close to this
error – two-sided allowed error
- class expyct.number.Float(*args, **kwargs)
Bases:
expyct.number.CloseTo
,expyct.number.MinMaxStrict
,expyct.number.MinMax
,expyct.base.Satisfies
,expyct.base.Equals
[numbers.Number
],expyct.base.Instance
,expyct.base.Optional
,expyct.base.MapBefore
,expyct.base.BaseMatcher
Match any object that is an instance of float.
- Parameters
map_before – apply function before checking equality
type – type of object must equal to given type
instance_of – object must be an instance of given type
equals – object must equal exactly. This is useful together with map_before to check a value after applying a function
optional – whether None is allowed
satisfies – object must satisfy predicate
min – number must be larger than or equal to given
max – number must be smaller than or equal to given
min_strict – number must be larger than given
max_strict – number must be smaller than given
close_to – number must be close to this
error – two-sided allowed error
- class expyct.number.Int(*args, **kwargs)
Bases:
expyct.number.CloseTo
,expyct.number.MinMaxStrict
,expyct.number.MinMax
,expyct.base.Satisfies
,expyct.base.Equals
[numbers.Number
],expyct.base.Instance
,expyct.base.Optional
,expyct.base.MapBefore
,expyct.base.BaseMatcher
Match any object that is an instance of int.
- Parameters
map_before – apply function before checking equality
type – type of object must equal to given type
instance_of – object must be an instance of given type
equals – object must equal exactly. This is useful together with map_before to check a value after applying a function
optional – whether None is allowed
satisfies – object must satisfy predicate
min – number must be larger than or equal to given
max – number must be smaller than or equal to given
min_strict – number must be larger than given
max_strict – number must be smaller than given
close_to – number must be close to this
error – two-sided allowed error a
- class expyct.number.MinMax(min: Optional[numbers.Number] = None, max: Optional[numbers.Number] = None)
Bases:
expyct.base.BaseMatcher
Mixin for matching a number that is equal to, larger or smaller than given bounds.
- Parameters
min – number must be larger than or equal to given
max – number must be smaller than or equal to given
- class expyct.number.MinMaxStrict(min_strict: Optional[numbers.Number] = None, max_strict: Optional[numbers.Number] = None)
Bases:
expyct.base.BaseMatcher
Mixin for matching number that is strictly larger or smaller than given bounds.
- Parameters
min_strict – number must be larger than given
max_strict – number must be smaller than given
- class expyct.number.Number(*args, **kwargs)
Bases:
expyct.number.CloseTo
,expyct.number.MinMaxStrict
,expyct.number.MinMax
,expyct.base.Satisfies
,expyct.base.Equals
[numbers.Number
],expyct.base.Instance
,expyct.base.Optional
,expyct.base.MapBefore
,expyct.base.BaseMatcher
Match any number.
- Parameters
map_before – apply function before checking equality
type – type of object must equal to given type
instance_of – object must be an instance of given type
equals – object must equal exactly. This is useful together with map_before to check a value after applying a function
optional – whether None is allowed [default: False]
satisfies – object must satisfy predicate
min – number must be larger than or equal to given
max – number must be smaller than or equal to given
min_strict – number must be larger than given
max_strict – number must be smaller than given
close_to – number must be close to this
error – two-sided allowed error a
- expyct.number.parse_float_string(obj: str) float
Parse a string as float. Throws a ValueError if obj is not a string.
- Parameters
obj – the string to parse
- expyct.number.parse_int_string(obj: str) int
Parse a string as int. Throws a ValueError if obj is not a string.
- Parameters
obj – the string to parse
- expyct.number.parse_number_string(obj: str) Union[int, float]
Parse a string as number. First tries to parse as int, then as float. Throws a ValueError if obj is not a string.
- Parameters
obj – the string to parse
- expyct.number.ANY_FLOAT = expyct.Instance(error=0.01)
Any instance of float
- expyct.number.ANY_FLOAT_STRING = expyct.Instance(map_before=<function parse_float_string>, error=0.01)
Any instance of float, parsed from a string
- expyct.number.ANY_INT = expyct.Instance(error=0.01)
Any instance of int
- expyct.number.ANY_INT_STRING = expyct.Instance(map_before=<function parse_int_string>, error=0.01)
Any instance of int, parsed from a string
- expyct.number.ANY_NUMBER = expyct.Instance(error=0.01)
Any number
- expyct.number.ANY_NUMBER_STRING = expyct.Instance(map_before=<function parse_number_string>, error=0.01)
Any number, parsed from a string