summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustavo Niemeyer <gustavo@niemeyer.net>2007-12-04 23:47:03 -0200
committerGustavo Niemeyer <gustavo@niemeyer.net>2007-12-04 23:47:03 -0200
commitdd13d97f602ebb08b0357701a6b22a7441c4abea (patch)
treeaf208ab3699abc269dc0e7a4ec5f097313dc08b2
parentcaeaec199b25c99e18ed13abc7ad89ff624ec44a (diff)
downloadmocker-dd13d97f602ebb08b0357701a6b22a7441c4abea.tar.gz
MockerTestCase now verifies if the mocker is put in replay
mode in cases where events were recorded.
-rw-r--r--NEWS3
-rw-r--r--mocker.py8
-rwxr-xr-xtest.py20
3 files changed, 30 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index 85ed71e..bf98e44 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,9 @@
0.X.X (2007-11-XX)
==================
+- MockerTestCase now verifies if the mocker is put in replay
+ mode in cases where events were recorded.
+
- 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 79f7191..e146ae4 100644
--- a/mocker.py
+++ b/mocker.py
@@ -98,7 +98,13 @@ class MockerTestCase(unittest.TestCase):
if test_method is not None:
def test_method_wrapper():
try:
- result = test_method()
+ try:
+ result = test_method()
+ finally:
+ if (self.mocker.is_recording() and
+ self.mocker.get_events()):
+ raise RuntimeError("Mocker must be put in replay "
+ "mode with self.mocker.replay()")
except:
self.__cleanup()
raise
diff --git a/test.py b/test.py
index a427c64..a1810fd 100755
--- a/test.py
+++ b/test.py
@@ -325,6 +325,26 @@ class MockerTestCaseTest(TestCase):
self.assertEquals(str(e), str(expected_error))
self.assertEquals(type(e), type(expected_error))
+ def test_raises_runtime_error_if_not_in_replay_mode_with_events(self):
+ class MyTest(MockerTestCase):
+ def test_method(self):
+ pass
+
+ test = MyTest("test_method")
+
+ # That's fine.
+ test.test_method()
+
+ test.mocker.add_event(Event())
+
+ # That's not.
+ self.assertRaises(RuntimeError, test.test_method)
+
+ test.mocker.replay()
+
+ # Fine again.
+ test.test_method()
+
def test_mocker_is_verified_and_restored_after_test_method_is_run(self):
calls = []
class MyEvent(Event):