Ticket #6049: docstring-elaboration.2.patch
| File docstring-elaboration.2.patch, 3.3 KB (added by marktraceur, 7 months ago) |
|---|
-
twisted/topfiles/6049.doc
1 Added and elaborated docstrings in twisted.trial.test.test_asyncassertions to be more complete, and a little more verbose. -
twisted/trial/test/test_asyncassertions.py
17 17 class TestAsynchronousAssertions(unittest.TestCase): 18 18 """ 19 19 Tests for L{TestCase}'s asynchronous extensions to L{SynchronousTestCase}. 20 That is, assertFailure.20 That is, L{TestCase.assertFailure}. 21 21 """ 22 22 def test_assertFailure(self): 23 """ 24 Test that a L{ZeroDivisionError} is raised when we try to run 1/0 in a 25 deferred lambda function, and that assertFailure catches it. 26 """ 23 27 d = defer.maybeDeferred(lambda: 1/0) 24 28 return self.assertFailure(d, ZeroDivisionError) 25 29 26 30 27 31 def test_assertFailure_wrongException(self): 32 """ 33 Test that assertFailure, when called on a function that raises a 34 L{ZeroDivisionError}, will fail the deferred function if it instead 35 raises an L{OverflowError}. 36 """ 28 37 d = defer.maybeDeferred(lambda: 1/0) 29 38 self.assertFailure(d, OverflowError) 30 39 d.addCallbacks(lambda x: self.fail('Should have failed'), … … 33 42 34 43 35 44 def test_assertFailure_noException(self): 45 """ 46 Test that assertFailure will fail the deferred function if there is no 47 exception raised, and a L{ZeroDivisionError} was expected. 48 """ 36 49 d = defer.succeed(None) 37 50 self.assertFailure(d, ZeroDivisionError) 38 51 d.addCallbacks(lambda x: self.fail('Should have failed'), … … 44 57 """ 45 58 In the case of assertFailure failing, check that we get lots of 46 59 information about the exception that was raised. 60 61 See L{_checkInfo} for more information about the checks we run. 47 62 """ 48 63 try: 49 64 1/0 … … 56 71 57 72 58 73 def _checkInfo(self, assertionFailure, f): 74 """ 75 Given an assertion failure and the failure that caused it, check that 76 the information in the L{failure} objects match up. 77 78 Specifically, we check for the error message and the brief traceback, 79 see L{failure.getErrorMessage} and L{failure.getBriefTraceback}. 80 """ 59 81 assert assertionFailure.check(self.failureException) 60 82 output = assertionFailure.getErrorMessage() 61 83 self.assertIn(f.getErrorMessage(), output) … … 64 86 65 87 def test_assertFailure_masked(self): 66 88 """ 67 A single wrong assertFailure should fail the whole test. 89 Run an actual L{unittest.TestCase} with some calls to assertFailure, 90 and make sure that the test case fails when the assertFailure is sure 91 to fail. 92 93 Specifically, we defer a lambda: 1/0, and assert that it will fail with 94 an L{OverflowError}, when clearly it will fail with a 95 L{ZeroDivisionError} instead, so that test case should fail. 68 96 """ 69 97 class ExampleFailure(Exception): 70 98 pass
