diff options
author | Gustavo Niemeyer <gustavo@niemeyer.net> | 2007-12-05 20:49:55 -0200 |
---|---|---|
committer | Gustavo Niemeyer <gustavo@niemeyer.net> | 2007-12-05 20:49:55 -0200 |
commit | b04e870828e81f0f519ad31eae43d1eb0091d692 (patch) | |
tree | 236d722852f5ce47a261a3460e04fe9d83c3aeba /mocker.py | |
parent | 5c7342b0fd9caf32d9b5d3077175e2bf21b7460f (diff) | |
download | mocker-b04e870828e81f0f519ad31eae43d1eb0091d692.tar.gz |
New MATCH() argument matcher, which allows using a function
to match an argument generically. E.g. MATCH(lambda x: x > 10)
Diffstat (limited to 'mocker.py')
-rw-r--r-- | mocker.py | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -18,7 +18,8 @@ if sys.version_info < (2, 4): from sets import Set as set # pragma: nocover -__all__ = ["Mocker", "expect", "IS", "CONTAINS", "IN", "ANY", "ARGS", "KWARGS"] +__all__ = ["Mocker", "expect", "IS", "CONTAINS", "IN", "MATCH", + "ANY", "ARGS", "KWARGS"] __author__ = "Gustavo Niemeyer <gustavo@niemeyer.net>" @@ -1350,6 +1351,15 @@ class IN(SpecialArgument): return other in self.object +class MATCH(SpecialArgument): + + def matches(self, other): + return bool(self.object(other)) + + def __eq__(self, other): + return type(other) == type(self) and self.object is other.object + + def match_params(args1, kwargs1, args2, kwargs2): """Match the two sets of parameters, considering special parameters.""" |