diff options
author | Gustavo Niemeyer <gustavo@niemeyer.net> | 2007-12-04 23:47:03 -0200 |
---|---|---|
committer | Gustavo Niemeyer <gustavo@niemeyer.net> | 2007-12-04 23:47:03 -0200 |
commit | dd13d97f602ebb08b0357701a6b22a7441c4abea (patch) | |
tree | af208ab3699abc269dc0e7a4ec5f097313dc08b2 | |
parent | caeaec199b25c99e18ed13abc7ad89ff624ec44a (diff) | |
download | mocker-dd13d97f602ebb08b0357701a6b22a7441c4abea.tar.gz |
MockerTestCase now verifies if the mocker is put in replay
mode in cases where events were recorded.
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | mocker.py | 8 | ||||
-rwxr-xr-x | test.py | 20 |
3 files changed, 30 insertions, 1 deletions
@@ -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. @@ -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 @@ -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): |