Logical Matchers

Boolean logic using other matchers.

See also, Logical matcher internals

all_of

hamcrest.core.core.allof.all_of(*items)

Matches if all of the given matchers evaluate to True.

Parameters
Return type

hamcrest.core.matcher.Matcher[hamcrest.core.core.allof.T]

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_to matcher to check for equality.

any_of

hamcrest.core.core.anyof.any_of(*items)

Matches if any of the given matchers evaluate to True.

Parameters
Return type

hamcrest.core.matcher.Matcher[hamcrest.core.core.anyof.T]

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_to matcher to check for equality.

anything

hamcrest.core.core.isanything.anything(description=None)

Matches anything.

Parameters

description (Optional[str]) – Optional string used to describe this matcher.

Return type

hamcrest.core.matcher.Matcher[Any]

This matcher always evaluates to True. Specify this in composite matchers when the value of a particular element is unimportant.

is_not

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[hamcrest.core.core.isnot.T], hamcrest.core.core.isnot.T]) hamcrest.core.matcher.Matcher[hamcrest.core.core.isnot.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 match argument is not a matcher, it is implicitly wrapped in an equal_to matcher to check for equality, and thus matches for inequality.

Examples:

assert_that(cheese, is_not(equal_to(smelly)))
assert_that(cheese, is_not(smelly))