The base class for any matcher. A matcher must implement the method matches(). It should also provide its own implementation of __str__(), to describe what values it matches.
Returns True if this matcher matches value, False otherwise.
If the matcher matches value, then mismatch_output should not be used. Otherwise, the reason for the mismatch should be written to mismatch_output using mismatch_output.append.
An example matcher is IsAnInt (this is generalised in is_a()):
class IsAnInt(Matcher):
def matches(self, value, mismatch_output):
if not isinstance(value, int):
mismatch_output.append("value was of type %s" % type(value).__name__)
return False
return True
def __str__(self):
return "<value of type: int>"
Matches all values
Matches any value that is an instance of type_.
Matches actual if, for every pair (key, value) in attributes, actual.key matches value. If value is a matcher, then value.matches is used to determine if there is a match. Otherwise, actual matches value if actual == value.
Matches any value equal to value.
Matches actual if actual is value.
Negates the given matcher. For instance, not_(equal_to(20)) will match any value not equal to 20.
Matches a value if all of the passed matchers match the value.
Matches a value if any of the passed matchers match the value.