summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustavo Niemeyer <gustavo@niemeyer.net>2007-12-04 23:56:34 -0200
committerGustavo Niemeyer <gustavo@niemeyer.net>2007-12-04 23:56:34 -0200
commita902346fb27f6e70fe778a8eb3a8adc2145dee08 (patch)
tree14eda8d9269de1d0fe581ca83d32f39d1a30fbb2
parentdd13d97f602ebb08b0357701a6b22a7441c4abea (diff)
downloadmocker-a902346fb27f6e70fe778a8eb3a8adc2145dee08.tar.gz
Now when a spec is provided (or with proxy/replace/patch) the
existence of the real method is checked even if the mocked method doesn't have to execute (e.g. due to count(0)).
-rw-r--r--NEWS4
-rw-r--r--mocker.py4
-rwxr-xr-xtest.py18
3 files changed, 26 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index bf98e44..7cc912e 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,10 @@
- MockerTestCase now verifies if the mocker is put in replay
mode in cases where events were recorded.
+- Now when a spec is provided (or with proxy/replace/patch) the
+ existence of the real method is checked even if the mocked
+ method doesn't have to execute (e.g. due to count(0)).
+
- Implemented support for Deferred results as understood by
Twisted Trial's TestCase, so that coexistence by multiple
inheritance is possible and trivial.
diff --git a/mocker.py b/mocker.py
index e146ae4..6189ccd 100644
--- a/mocker.py
+++ b/mocker.py
@@ -1780,6 +1780,10 @@ class SpecChecker(Task):
raise AssertionError("Specification is %s%s: %s" %
(self._method.__name__, spec, message))
+ def verify(self):
+ if not self._method:
+ raise AssertionError("Method not found in real specification")
+
def run(self, path):
if not self._method:
raise AssertionError("Method not found in real specification")
diff --git a/test.py b/test.py
index a1810fd..92fb8a3 100755
--- a/test.py
+++ b/test.py
@@ -217,6 +217,15 @@ class IntegrationTest(TestCase):
mock.method(1, 2)
self.assertRaises(AssertionError, mock.method, 1)
+ def test_patch_with_spec_and_unexistent(self):
+ class C(object):
+ pass
+ mock = self.mocker.patch(C)
+ mock.method(1, 2)
+ self.mocker.count(0)
+ self.mocker.replay()
+ self.assertRaises(AssertionError, self.mocker.verify)
+
def test_mock_iter(self):
"""
list() uses len() as a hint. When we mock iter(), it shouldn't
@@ -3146,6 +3155,15 @@ class SpecCheckerTest(TestCase):
else:
self.fail("AssertionError not raised")
+ def test_verify_unexistent_method(self):
+ task = SpecChecker(None)
+ try:
+ task.verify()
+ except AssertionError, e:
+ self.assertEquals(str(e), "Method not found in real specification")
+ else:
+ self.fail("AssertionError not raised")
+
def test_unsupported_object_for_getargspec(self):
from zlib import adler32
# If that fails, this test has to change because either adler32 has