Ticket #2245: cdefer.4.patch

File cdefer.4.patch, 1.9 KB (added by Peaker, 9 years ago)

Fixes setDebugging/setTimeout tests

  • twisted/test/test_defer.py

     
    278278        """
    279279        L = []
    280280        d = defer.Deferred()
     281        if not hasattr(d, 'setTimeout'):
     282            log.msg("setTimeout support not in Deferred, so will not be tested")
     283            return
    281284        d.setTimeout(0.01)
    282285        self.assertFailure(d, defer.TimeoutError)
    283286        d.addCallback(L.append)
     
    300303        """
    301304        l = []
    302305        d = defer.succeed("success")
     306        if not hasattr(d, 'setTimeout'):
     307            log.msg("setTimeout support not in Deferred, so will not be tested")
     308            return
    303309        d.setTimeout(1.0)
    304310        d.addCallback(l.append)
    305311        self.assertEquals(l, ["success"])
  • twisted/internet/defer.py

     
    439439        return False
    440440
    441441try:
    442     from twisted.internet.cdefer import Deferred
     442    from twisted.internet.cdefer import Deferred as CDeferred
    443443except ImportError:
    444444    pass
    445445else:
    446     # Stubs for setDebugging/getDebugging for backwards compatibility
    447     # when using cdefer.
    448     is_debug = False
     446    PyDeferred = Deferred
     447    PyDeferred.debug = True
     448    # Debugging enabled via use of PyDeferred
    449449    def setDebugging(new_value):
    450         global is_debug
     450        global is_debug, Deferred
    451451        is_debug = new_value
     452        if is_debug:
     453            Deferred = PyDeferred
     454        else:
     455            Deferred = CDeferred
    452456    def getDebugging():
    453457        global is_debug
    454458        return is_debug
    455459
     460    setDebugging(False)
     461
    456462class DeferredList(Deferred):
    457463    """I combine a group of deferreds into one callback.
    458464