Decorator Matchers¶
Matchers that decorate other matchers for better expression.
See also, Decorator matcher internals.
described_as¶
is_¶
- hamcrest.core.core.is_.is_(x: Type) Matcher[Any]¶
- hamcrest.core.core.is_.is_(x: Matcher[T]) Matcher[T]
- hamcrest.core.core.is_.is_(x: T) Matcher[T]
Decorates another matcher, or provides shortcuts to the frequently used
is(equal_to(x))andis(instance_of(x)).- Parameters:
x – The matcher to satisfy, or a type for
instance_ofmatching, or an expected value forequal_tomatching.
This matcher compares the evaluated object to the given matcher.
Note
PyHamcrest’s
is_matcher is unrelated to Python’sisoperator. The matcher for object identity issame_instance.If the
xargument is a matcher, its behavior is retained, but the test may be more expressive. For example:assert_that(value, less_than(5)) assert_that(value, is_(less_than(5)))
If the
xargument is a type, it is wrapped in aninstance_ofmatcher. This makes the following statements equivalent:assert_that(cheese, instance_of(Cheddar)) assert_that(cheese, is_(instance_of(Cheddar))) assert_that(cheese, is_(Cheddar))
Otherwise, if the
xargument is not a matcher, it is wrapped in anequal_tomatcher. This makes the following statements equivalent:assert_that(cheese, equal_to(smelly)) assert_that(cheese, is_(equal_to(smelly))) assert_that(cheese, is_(smelly))
Choose the style that makes your expression most readable. This will vary depending on context.