Ticket #6049: docstring-elaboration.2.patch

File docstring-elaboration.2.patch, 3.3 KB (added by marktraceur, 3 years ago)

A patch to elaborate existing docstrings and add new ones.

  • twisted/topfiles/6049.doc

     
     1Added and elaborated docstrings in twisted.trial.test.test_asyncassertions to be more complete, and a little more verbose.
  • twisted/trial/test/test_asyncassertions.py

     
    1717class TestAsynchronousAssertions(unittest.TestCase):
    1818    """
    1919    Tests for L{TestCase}'s asynchronous extensions to L{SynchronousTestCase}.
    20     That is, assertFailure.
     20    That is, L{TestCase.assertFailure}.
    2121    """
    2222    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        """
    2327        d = defer.maybeDeferred(lambda: 1/0)
    2428        return self.assertFailure(d, ZeroDivisionError)
    2529
    2630
    2731    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        """
    2837        d = defer.maybeDeferred(lambda: 1/0)
    2938        self.assertFailure(d, OverflowError)
    3039        d.addCallbacks(lambda x: self.fail('Should have failed'),
     
    3342
    3443
    3544    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        """
    3649        d = defer.succeed(None)
    3750        self.assertFailure(d, ZeroDivisionError)
    3851        d.addCallbacks(lambda x: self.fail('Should have failed'),
     
    4457        """
    4558        In the case of assertFailure failing, check that we get lots of
    4659        information about the exception that was raised.
     60
     61        See L{_checkInfo} for more information about the checks we run.
    4762        """
    4863        try:
    4964            1/0
     
    5671
    5772
    5873    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        """
    5981        assert assertionFailure.check(self.failureException)
    6082        output = assertionFailure.getErrorMessage()
    6183        self.assertIn(f.getErrorMessage(), output)
     
    6486
    6587    def test_assertFailure_masked(self):
    6688        """
    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.
    6896        """
    6997        class ExampleFailure(Exception):
    7098            pass