diff options
author | Gustavo Niemeyer <gustavo@niemeyer.net> | 2010-06-20 15:04:54 -0300 |
---|---|---|
committer | Gustavo Niemeyer <gustavo@niemeyer.net> | 2010-06-20 15:04:54 -0300 |
commit | 3a4c487d0d08f51dca83e31f35aae5ecb3affb82 (patch) | |
tree | fd641989efbaec56956bbadaa9cbe2fd7ce5e3c2 /test.py | |
parent | 1a572f6c05cc6c7aa2b58e810684525cb8b66de7 (diff) | |
download | mocker-3a4c487d0d08f51dca83e31f35aae5ecb3affb82.tar.gz |
Fixed support for MockerTestCase.addCleanup() in Python 2.3,
by Anders F Björklund (#528657).
Diffstat (limited to 'test.py')
-rwxr-xr-x | test.py | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -450,6 +450,44 @@ class MockerTestCaseTest(TestCase): self.assertEquals(stash, [[], (1, 2), (3, 4)]) + def test_cleanup_wrapper_in__call__for_2_3(self): + version_info = sys.version_info + __call__ = unittest.TestCase.__call__ + try: + sys.version_info = (2, 3, 5) + stash = [] + def call(self, *args, **kwargs): + self.addCleanup(lambda: stash.append(True)) + unittest.TestCase.__call__ = call + class MyTest(MockerTestCase): + def test_method(self): + pass + MyTest("test_method")() + self.assertEquals(stash, [True]) + finally: + unittest.TestCase.__call__ = __call__ + sys.version_info = version_info + + def test_cleanup_wrapper_in__call__for_2_4(self): + version_info = sys.version_info + __call__ = unittest.TestCase.__call__ + try: + sys.version_info = (2, 4) + stash = [] + def call(self, *args, **kwargs): + self.addCleanup(lambda: stash.append(True)) + unittest.TestCase.__call__ = call + class MyTest(MockerTestCase): + def test_method(self): + pass + MyTest("test_method")() + # Python 2.4+ handles cleanup in run(), registered inside + # MockerTestCase.__init__, so this should *not* work. + self.assertEquals(stash, []) + finally: + unittest.TestCase.__call__ = __call__ + sys.version_info = version_info + def test_twisted_trial_deferred_support(self): calls = [] callbacks = [] |