diff options
author | Thomas Hervé <thomas@canonical.com> | 2008-11-19 16:16:49 +0100 |
---|---|---|
committer | Thomas Hervé <thomas@canonical.com> | 2008-11-19 16:16:49 +0100 |
commit | a94098f9400c9b67b5d281dc90bdc51569a7a79a (patch) | |
tree | 14c0f1eff20bb7dba3f97e6c38636cad414175dd /test.py | |
parent | 8a4227cfcc32fed041462ebf6031d722bb0c39a1 (diff) | |
download | mocker-a94098f9400c9b67b5d281dc90bdc51569a7a79a.tar.gz |
Return exception in failUnlessRaises, test it.
Diffstat (limited to 'test.py')
-rwxr-xr-x | test.py | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -767,6 +767,40 @@ class MockerTestCaseTest(TestCase): except AssertionError: self.fail("AssertionError shouldn't be raised") + def test_fail_unless_raises_succeeds(self): + class MyException(Exception): + pass + def f(*args): + raise MyException(*args) + error = self.test.failUnlessRaises(MyException, f, 1, "foo") + self.assertEquals(error.args, (1, "foo")) + + def test_fail_unless_raises_error(self): + def f(*args): + return args + try: + self.test.failUnlessRaises(ValueError, f, 1, "foo") + except AssertionError, e: + self.assertEquals( + str(e), + "ValueError not raised ((1, 'foo') returned)") + else: + self.fail("AssertionError not raised") + + def test_fail_unless_raises_other_exception(self): + class MyException1(Exception): + pass + class MyException2(Exception): + pass + def f(*args): + raise MyException2(*args) + try: + self.test.failUnlessRaises(MyException1, f, 1, "foo") + except MyException2: + pass + else: + self.fail("MyException2 not raised") + def test_aliases(self): get_method = MockerTestCase.__dict__.get @@ -803,6 +837,9 @@ class MockerTestCaseTest(TestCase): self.assertEquals(get_method("assertMethodsMatch"), get_method("failUnlessMethodsMatch")) + self.assertEquals(get_method("assertRaises"), + get_method("failUnlessRaises")) + def test_twisted_trial_aliases(self): get_method = MockerTestCase.__dict__.get |