diff options
author | Gustavo Niemeyer <gustavo@niemeyer.net> | 2007-11-17 15:30:34 -0200 |
---|---|---|
committer | Gustavo Niemeyer <gustavo@niemeyer.net> | 2007-11-17 15:30:34 -0200 |
commit | 745fc9a11340f192e2f73c0f1f3101866d26f74f (patch) | |
tree | 2626e5ddf71d2d96e6d358b7f0e55c5d2d713e9e /test.py | |
parent | 90e0d73ee9238af7c80d9342a028d04028d4ae3a (diff) | |
download | mocker-745fc9a11340f192e2f73c0f1f3101866d26f74f.tar.gz |
Added MockerTestCase.assertMethodsMatch(). It will verify if all
public methods found in the class passed as the first argument are
also present in the class passed as the second argument, and that
they accept the same arguments. This is useful to verify if a fake
or stub class have the same API as the real class being simulated.
Diffstat (limited to 'test.py')
-rwxr-xr-x | test.py | 62 |
1 files changed, 62 insertions, 0 deletions
@@ -481,6 +481,65 @@ class MockerTestCaseTest(unittest.TestCase): except AssertionError: self.fail("AssertionError shouldn't be raised") + def test_fail_unless_methods_match_raises_on_different_method(self): + class Fake(object): + def method(self, a): pass + class Real(object): + def method(self, b): pass + try: + self.test.failUnlessMethodsMatch(Fake, Real) + except AssertionError, e: + self.assertEquals(str(e), "Fake.method(self, a) != " + "Real.method(self, b)") + else: + self.fail("AssertionError not raised") + + def test_fail_unless_methods_match_raises_on_missing_method(self): + class Fake(object): + def method(self, a): pass + class Real(object): + pass + try: + self.test.failUnlessMethodsMatch(Fake, Real) + except AssertionError, e: + self.assertEquals(str(e), "Fake.method(self, a) not present " + "in Real") + else: self.fail("AssertionError not raised") + + def test_fail_unless_methods_match_succeeds_on_missing_priv_method(self): + class Fake(object): + def _method(self, a): pass + class Real(object): + pass + try: + self.test.failUnlessMethodsMatch(Fake, Real) + except AssertionError, e: + self.fail("AssertionError shouldn't be raised") + + def test_fail_unless_methods_match_raises_on_different_priv_method(self): + class Fake(object): + def _method(self, a): pass + class Real(object): + def _method(self, b): pass + try: + self.test.failUnlessMethodsMatch(Fake, Real) + except AssertionError, e: + self.assertEquals(str(e), "Fake._method(self, a) != " + "Real._method(self, b)") + else: + self.fail("AssertionError not raised") + + def test_fail_unless_methods_match_succeeds(self): + class Fake(object): + def method(self, a): pass + class Real(object): + def method(self, a): pass + obj = [] + try: + self.test.failUnlessMethodsMatch(Fake, Real) + except AssertionError: + self.fail("AssertionError shouldn't be raised") + def test_aliases(self): get_method = MockerTestCase.__dict__.get @@ -502,6 +561,9 @@ class MockerTestCaseTest(unittest.TestCase): self.assertEquals(get_method("assertNotApproximates"), get_method("failIfApproximates")) + self.assertEquals(get_method("assertMethodsMatch"), + get_method("failUnlessMethodsMatch")) + def test_twisted_trial_aliases(self): get_method = MockerTestCase.__dict__.get |