mockify.matchers - Classes for wildcarding expected arguments¶
Module containing predefined matchers.
A matcher is every class that inherits from
Matcher and implements
- Return matcher’s text representation.
selfis equal to
Here we use standard Python
__eq__operator as it will be automatically executed by Python no matter where the matcher is used. But equality definition is completely up to the matcher implementation.
Matcher that matches any value.
It is available also as
_(underscore) single instance that can be imported from this module.
For example, you can record expectation that mock must be called with one positional argument of any value but exactly 3 times:
>>> from mockify.matchers import _ >>> from mockify.mock import Function >>> foo = Function('foo') >>> foo.expect_call(_).times(3) <mockify.Expectation: foo(_)> >>> for i in range(3): ... foo(i) >>> foo.assert_satisfied()
Matcher that matches any value and keeps ordered track of unique values.
This can be used as a replacement for
Anyin case that you need to ensure that mock was called in specified order.
>>> from mockify.mock import Function >>> arg = SaveArg() >>> foo = Function('foo') >>> foo.expect_call(arg).times(3) <mockify.Expectation: foo(SaveArg)> >>> for i in range(3): ... foo(i) >>> foo.assert_satisfied() >>> arg.called_with == [0, 1, 2] True
List of ordered unique values that this matcher was called with.