Ticket #5952: patch3.patch

File patch3.patch, 2.6 KB (added by sreepriya, 7 years ago)

The patch includes the comments given by rwall. Coding standards are followed, old test_trapped is removed and broken to two functions, if_PY3 is made closer.

  • test_failure.py

     
    2727    raiser = None
    2828
    2929
    30 
    3130def getDivisionFailure(*args, **kwargs):
    3231    """
    3332    Make a C{Failure} of a divide-by-zero error.
     
    6059        self.assertEqual(f.type, NotImplementedError)
    6160
    6261
    63     def test_notTrapped(self):
     62    def test_trappedAndReRaiseFailure(self):
    6463        """
    65         Making sure L{trap} doesn't trap what it shouldn't.
     64        Fail the test if the exception is not on overflow error.
    6665        """
    6766        exception = ValueError()
    6867        try:
    6968            raise exception
    7069        except:
    7170            f = failure.Failure()
    72 
    73         # On Python 2, the same failure is reraised:
    74         if not _PY3:
    75             untrapped = self.assertRaises(failure.Failure, f.trap, OverflowError)
    76             self.assertIdentical(f, untrapped)
    77 
    78         # On both Python 2 and Python 3, the underlying exception is passed
    79         # on:
    80         try:
    81             f.trap(OverflowError)
    82         except:
    83             untrapped = failure.Failure()
    84             self.assertIdentical(untrapped.value, exception)
    85         else:
    86             self.fail("Exception was not re-raised.")
    87 
    88 
    89     def test_TrappedAndReRaiseFailure(self):
    90         """
    91         If the failure doesn't match the error pre-defined, this test case will raise the same failure.
    92         """
    93         exception = ValueError()
    94         try:
    95             raise exception
    96         except:
    97             f = failure.Failure()
    9871        # On Python 2, the same failure is reraised:   
    9972        untrapped = self.assertRaises(failure.Failure, f.trap, OverflowError)
    10073        self.assertIdentical(f, untrapped)
    10174
    10275
    103     def test_TrappedAndReRaiseException(self):
     76    def test_trappedAndReRaiseException(self):
    10477        """
    105         If the failure doesn't match the error pre-defined, the underlying exception will be re-raised.
     78        Raise an exception if the trapped exception is on
     79        overflow error.
    10680        """
    10781        exception = ValueError()
    10882        try:
     
    11892            self.assertIdentical(untrapped.value, exception)
    11993        else:
    12094            self.fail("Exception was not re-raised.")
     95       
     96    if _PY3:
     97        FailureTestCase.test_TrappedAndReRaiseFailure.skip = "In Python3, failure.trap raises the original Exception instead of a failure instance because Python3 can only raise BaseException subclasses."
    12198
    12299
    123100    def assertStartsWith(self, s, prefix):
     
    1014991
    1015992
    1016993
    1017 if _PY3:
    1018     FailureTestCase.test_TrappedAndReRaiseFailure.skip = "This test works only with Python 2"
    1019994