Logical Matchers¶
Boolean logic using other matchers.
all_of¶
-
class
hamcrest.core.core.allof.AllOf(*matchers: hamcrest.core.matcher.Matcher[T], **kwargs)¶ Bases:
hamcrest.core.base_matcher.BaseMatcher[hamcrest.core.core.allof.T]-
describe_mismatch(item: T, mismatch_description: hamcrest.core.description.Description) → None¶ 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 – The item that the
Matcherhas rejected.mismatch_description – The description to be built or appended to.
-
describe_to(description: hamcrest.core.description.Description) → None¶ 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 – The description to be built or appended to.
-
matches(item: T, mismatch_description: Optional[hamcrest.core.description.Description] = None) → bool¶ Evaluates the matcher for argument item.
If a mismatch is detected and argument
mismatch_descriptionis provided, it will generate a description of why the matcher has not accepted the item.- Parameters
item – The object against which the matcher is evaluated.
mismatch_description –
- Returns
Trueifitemmatches, otherwiseFalse.
-
-
hamcrest.core.core.allof.all_of(matcher1[, matcher2[, ...]])¶ Matches if all of the given matchers evaluate to
True.- Parameters
matcher1,.. – A comma-separated list of matchers.
The matchers are evaluated from left to right using short-circuit evaluation, so evaluation stops as soon as a matcher returns
False.Any argument that is not a matcher is implicitly wrapped in an
equal_tomatcher to check for equality.
any_of¶
-
class
hamcrest.core.core.anyof.AnyOf(*matchers: hamcrest.core.matcher.Matcher[T])¶ Bases:
hamcrest.core.base_matcher.BaseMatcher[hamcrest.core.core.anyof.T]-
describe_to(description: hamcrest.core.description.Description) → None¶ 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 – The description to be built or appended to.
-
-
hamcrest.core.core.anyof.any_of(matcher1[, matcher2[, ...]])¶ Matches if any of the given matchers evaluate to
True.- Parameters
matcher1,.. – A comma-separated list of matchers.
The matchers are evaluated from left to right using short-circuit evaluation, so evaluation stops as soon as a matcher returns
True.Any argument that is not a matcher is implicitly wrapped in an
equal_tomatcher to check for equality.
anything¶
-
class
hamcrest.core.core.isanything.IsAnything(description: Optional[str])¶ Bases:
hamcrest.core.base_matcher.BaseMatcher[Any]-
describe_to(description: hamcrest.core.description.Description) → None¶ 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 – The description to be built or appended to.
-
-
hamcrest.core.core.isanything.anything([description])¶ Matches anything.
- Parameters
description – Optional string used to describe this matcher.
This matcher always evaluates to
True. Specify this in composite matchers when the value of a particular element is unimportant.
is_not¶
-
class
hamcrest.core.core.isnot.IsNot(matcher: hamcrest.core.matcher.Matcher[T])¶ Bases:
hamcrest.core.base_matcher.BaseMatcher[hamcrest.core.core.isnot.T]-
describe_mismatch(item: T, mismatch_description: hamcrest.core.description.Description) → None¶ 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 – The item that the
Matcherhas rejected.mismatch_description – The description to be built or appended to.
-
describe_to(description: hamcrest.core.description.Description) → None¶ 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 – The description to be built or appended to.
-
-
hamcrest.core.core.isnot.is_not(match: Type) → hamcrest.core.matcher.Matcher[object]¶ -
hamcrest.core.core.isnot.is_not(match: Union[hamcrest.core.matcher.Matcher[T], T]) → hamcrest.core.matcher.Matcher[T] Inverts the given matcher to its logical negation.
- Parameters
match – The matcher to negate.
This matcher compares the evaluated object to the negation of the given matcher. If the
matchargument is not a matcher, it is implicitly wrapped in anequal_tomatcher to check for equality, and thus matches for inequality.Examples:
assert_that(cheese, is_not(equal_to(smelly))) assert_that(cheese, is_not(smelly))
-
hamcrest.core.core.isnot.not_(match: Union[hamcrest.core.matcher.Matcher[T], T]) → hamcrest.core.matcher.Matcher[T]¶ Alias of
is_notfor better readability of negations.Examples:
assert_that(alist, not_(has_item(item)))