Ticket #3719: time_helpers.diff

File time_helpers.diff, 3.0 KB (added by drake, 7 years ago)
  • twisted/test/time_helpers.py

     
    88instead.
    99"""
    1010
     11import warnings
     12
     13warnings.warn(
     14    "twisted.test.time_helpers is deprecated since 9.0.0.",
     15    category=DeprecationWarning)
     16
     17
    1118class Clock(object):
    1219    """
    1320    A utility for monkey-patches various parts of Twisted to use a
  • twisted/test/test_internet.py

     
    1313from twisted.internet import reactor, protocol, error, abstract, defer
    1414from twisted.internet import interfaces, base
    1515
    16 from twisted.test.time_helpers import Clock
     16from twisted.internet.task import Clock
    1717
    1818try:
    1919    from twisted.internet import ssl
     
    788788        reset or delayed.
    789789        """
    790790        clock = Clock()
    791         clock.install()
    792         try:
    793             callbackTimes = [None, None]
    794791
    795             def resetCallback():
    796                 callbackTimes[0] = clock()
     792        callbackTimes = [None, None]
    797793
    798             def delayCallback():
    799                 callbackTimes[1] = clock()
     794        def resetCallback():
     795            callbackTimes[0] = clock.seconds()
    800796
    801             ireset = reactor.callLater(2, resetCallback)
    802             idelay = reactor.callLater(3, delayCallback)
     797        def delayCallback():
     798            callbackTimes[1] = clock.seconds()
    803799
    804             clock.pump(reactor, [0, 1])
     800        ireset = clock.callLater(2, resetCallback)
     801        idelay = clock.callLater(3, delayCallback)
    805802
    806             self.assertIdentical(callbackTimes[0], None)
    807             self.assertIdentical(callbackTimes[1], None)
     803        clock.pump([0, 1])
    808804
    809             ireset.reset(2) # (now)1 + 2 = 3
    810             idelay.delay(3) # (orig)3 + 3 = 6
     805        self.assertIdentical(callbackTimes[0], None)
     806        self.assertIdentical(callbackTimes[1], None)
    811807
    812             clock.pump(reactor, [0, 1])
     808        ireset.reset(2) # (now)1 + 2 = 3
     809        idelay.delay(3) # (orig)3 + 3 = 6
    813810
    814             self.assertIdentical(callbackTimes[0], None)
    815             self.assertIdentical(callbackTimes[1], None)
     811        clock.pump([0, 1])
    816812
    817             clock.pump(reactor, [0, 1])
     813        self.assertIdentical(callbackTimes[0], None)
     814        self.assertIdentical(callbackTimes[1], None)
    818815
    819             self.assertEquals(callbackTimes[0], 3)
    820             self.assertEquals(callbackTimes[1], None)
     816        clock.pump([0, 1])
    821817
    822             clock.pump(reactor, [0, 3])
    823             self.assertEquals(callbackTimes[1], 6)
    824         finally:
    825             clock.uninstall()
     818        self.assertEquals(callbackTimes[0], 3)
     819        self.assertEquals(callbackTimes[1], None)
    826820
     821        clock.pump([0, 3])
     822        self.assertEquals(callbackTimes[1], 6)
    827823
     824
    828825    def testCallLaterTime(self):
    829826        d = reactor.callLater(10, lambda: None)
    830827        try: