Ticket #5178: 5178.diff

File 5178.diff, 3.2 KB (added by Forrest Voight, 11 years ago)

patch to duplicate the Deferred's Failure before cleaning it to store it in DebugInfo

  • twisted/test/test_defer.py

     
    966966        fail = l[0]
    967967        self.assertEquals(fail.value, exc)
    968968        localz, globalz = fail.frames[0][-2:]
    969         self.assertEquals([], localz)
    970         self.assertEquals([], globalz)
     969        self.assertEqual([], list(localz))
     970        self.assertEqual([], list(globalz))
    971971
    972972
    973973    def test_errbackWithNoArgs(self):
     
    988988        fail = l[0]
    989989        self.assertEquals(fail.value, exc)
    990990        localz, globalz = fail.frames[0][-2:]
    991         self.assertNotEquals([], localz)
    992         self.assertNotEquals([], globalz)
     991        self.assertNotEqual([], list(localz))
     992        self.assertNotEqual([], list(globalz))
    993993
    994994
    995995    def test_errorInCallbackDoesNotCaptureVars(self):
     
    10071007        d.addErrback(l.append)
    10081008        fail = l[0]
    10091009        localz, globalz = fail.frames[0][-2:]
    1010         self.assertEquals([], localz)
    1011         self.assertEquals([], globalz)
     1010        self.assertEqual([], list(localz))
     1011        self.assertEqual([], list(globalz))
    10121012
    10131013
    10141014    def test_errorInCallbackCapturesVarsWhenDebugging(self):
     
    10261026        d.addErrback(l.append)
    10271027        fail = l[0]
    10281028        localz, globalz = fail.frames[0][-2:]
    1029         self.assertNotEquals([], localz)
    1030         self.assertNotEquals([], globalz)
     1029        self.assertNotEqual([], list(localz))
     1030        self.assertNotEqual([], list(globalz))
    10311031
    10321032
     1033    def test_immediateErrbackDoesNotResultInCleanedFailure(self):
     1034        d = defer.Deferred()
     1035        try:
     1036            1/0
     1037        except:
     1038            d.errback()
     1039        called = [False]
     1040        def err(fail):
     1041            called[0] = True
     1042            self.assertIsNot(fail.tb, None)
     1043        d.addErrback(err)
     1044        self.assertTrue(called[0])
    10331045
     1046
     1047
    10341048class FirstErrorTests(unittest.TestCase):
    10351049    """
    10361050    Tests for L{FirstError}.
  • twisted/topfiles/3622.bugfix

     
     1Deferred._runCallbacks now doesn't alter its Failure when providing a cleaned Failure to its DebugInfo.
  • twisted/internet/defer.py

     
    580580                if isinstance(current.result, failure.Failure):
    581581                    # Stash the Failure in the _debugInfo for unhandled error
    582582                    # reporting.
    583                     current.result.cleanFailure()
    584583                    if current._debugInfo is None:
    585584                        current._debugInfo = DebugInfo()
    586                     current._debugInfo.failResult = current.result
     585
     586                    fail = failure.Failure(current.result)
     587                    fail.cleanFailure()
     588                    current._debugInfo.failResult = fail
    587589                else:
    588590                    # Clear out any Failure in the _debugInfo, since the result
    589591                    # is no longer a Failure.