Number Matchers¶
Matchers that perform numeric comparisons.
- class hamcrest.library.number.iscloseto.IsCloseTo(value, delta)¶
Bases:
hamcrest.core.base_matcher.BaseMatcher
[Union
[float
,decimal.Decimal
]]- Parameters
value (Union[float, decimal.Decimal]) –
delta (Union[float, decimal.Decimal]) –
- Return type
None
- describe_mismatch(item, mismatch_description)¶
Generates a description of why the matcher has not accepted the item.
The description will be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)
isFalse
, but will not check this.- Parameters
item (Union[float, decimal.Decimal]) – The item that the
Matcher
has rejected.mismatch_description (hamcrest.core.description.Description) – The description to be built or appended to.
- Return type
None
- describe_to(description)¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters
description (hamcrest.core.description.Description) – The description to be built or appended to.
- Return type
None
- hamcrest.library.number.iscloseto.close_to(value: float, delta: float) hamcrest.core.matcher.Matcher[float] ¶
- hamcrest.library.number.iscloseto.close_to(value: decimal.Decimal, delta: decimal.Decimal) hamcrest.core.matcher.Matcher[decimal.Decimal]
Matches if object is a number close to a given value, within a given delta.
- Parameters
value – The value to compare against as the expected value.
delta – The maximum delta between the values for which the numbers are considered close.
This matcher compares the evaluated object against
value
to see if the difference is within a positivedelta
.Example:
close_to(3.0, 0.25)
- hamcrest.library.number.iscloseto.isnumeric(value)¶
Confirm that ‘value’ can be treated numerically; duck-test accordingly
- class hamcrest.library.number.ordering_comparison.OrderingComparison(value, comparison_function, comparison_description)¶
Bases:
hamcrest.core.base_matcher.BaseMatcher
[Any
]- Parameters
- Return type
None
- describe_to(description)¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters
description (hamcrest.core.description.Description) – The description to be built or appended to.
- Return type
None
- hamcrest.library.number.ordering_comparison.greater_than(value)¶
Matches if object is greater than a given value.
- Parameters
value (Any) – The value to compare against.
- Return type
- hamcrest.library.number.ordering_comparison.greater_than_or_equal_to(value)¶
Matches if object is greater than or equal to a given value.
- Parameters
value (Any) – The value to compare against.
- Return type
- hamcrest.library.number.ordering_comparison.less_than(value)¶
Matches if object is less than a given value.
- Parameters
value (Any) – The value to compare against.
- Return type