From b04e870828e81f0f519ad31eae43d1eb0091d692 Mon Sep 17 00:00:00 2001 From: Gustavo Niemeyer Date: Wed, 5 Dec 2007 20:49:55 -0200 Subject: New MATCH() argument matcher, which allows using a function to match an argument generically. E.g. MATCH(lambda x: x > 10) --- test.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'test.py') diff --git a/test.py b/test.py index 3d27d54..a37977b 100755 --- a/test.py +++ b/test.py @@ -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}) -- cgit v1.2.1