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 /test.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 'test.py')
-rwxr-xr-x | test.py | 16 |
1 files changed, 14 insertions, 2 deletions
@@ -23,8 +23,8 @@ from mocker import \ PathMatcher, path_matcher_recorder, RunCounter, ImplicitRunCounter, \ run_counter_recorder, run_counter_removal_recorder, MockReturner, \ mock_returner_recorder, FunctionRunner, Orderer, SpecChecker, \ - spec_checker_recorder, match_params, ANY, IS, CONTAINS, IN, ARGS, KWARGS, \ - MatchError, PathExecuter, ProxyReplacer, Patcher, Undefined, \ + spec_checker_recorder, match_params, ANY, IS, CONTAINS, IN, MATCH, ARGS, \ + KWARGS, MatchError, PathExecuter, ProxyReplacer, Patcher, Undefined, \ PatchedMethod, MockerTestCase, ReplayRestoreEvent, OnRestoreCaller @@ -2089,6 +2089,18 @@ class MatchParamsTest(TestCase): self.assertFalse(IN([1]).matches([1])) self.assertFalse(IN([1]).matches(object())) + def test_match_repr(self): + self.assertEquals(repr(MATCH("obj")), "MATCH('obj')") + + def test_match_equals(self): + obj1, obj2 = [], [] + self.assertEquals(MATCH(obj1), MATCH(obj1)) + self.assertNotEquals(MATCH(obj1), MATCH(obj2)) + + def test_match_matches(self): + self.assertTrue(MATCH(lambda x: x > 10).matches(15)) + self.assertFalse(MATCH(lambda x: x > 10).matches(5)) + def test_normal(self): self.true((), {}, (), {}) self.true((1, 2), {"a": 3}, (1, 2), {"a": 3}) |