1
# Copyright (c) 2001-2010 Twisted Matrix Laboratories.
2
# See LICENSE for details.
5
Helper class to writing deterministic time-based unit tests.
7
Do not use this module. It is a lie. See L{twisted.internet.task.Clock}
13
"twisted.test.time_helpers is deprecated since Twisted 10.0. "
14
"See twisted.internet.task.Clock instead.",
15
category=DeprecationWarning, stacklevel=2)
20
A utility for monkey-patches various parts of Twisted to use a
21
simulated timing mechanism. DO NOT use this class. Use
22
L{twisted.internet.task.Clock}.
28
Return the current simulated time.
34
Monkeypatch L{twisted.internet.reactor.seconds} to use
35
L{__call__} as a time source
38
from twisted.internet import reactor
39
self.reactor_original = reactor.seconds
40
reactor.seconds = self
44
Remove the monkeypatching of L{twisted.internet.reactor.seconds}.
46
from twisted.internet import reactor
47
reactor.seconds = self.reactor_original
49
def adjust(self, amount):
51
Adjust the current simulated time upward by the given C{amount}.
53
Note that this does not cause any scheduled calls to be run.
55
self.rightNow += amount
57
def pump(self, reactor, timings):
59
Iterate the given C{reactor} with increments of time specified
62
For each timing, the simulated time will be L{adjust}ed and
63
the reactor will be iterated twice.
65
timings = list(timings)
67
self.adjust(timings.pop())
69
self.adjust(timings.pop())