Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(273)

Side by Side Diff: third_party/twisted_8_1/twisted/test/time_helpers.py

Issue 12261012: Remove third_party/twisted_8_1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright (c) 2001-2007 Twisted Matrix Laboratories.
2 # See LICENSE for details.
3
4 """
5 Helper class to writing deterministic time-based unit tests.
6
7 Do not use this module. It is a lie. See L{twisted.internet.task.Clock}
8 instead.
9 """
10
11 class Clock(object):
12 """
13 A utility for monkey-patches various parts of Twisted to use a
14 simulated timing mechanism. DO NOT use this class. Use
15 L{twisted.internet.task.Clock}.
16 """
17 rightNow = 0.0
18
19 def __call__(self):
20 """
21 Return the current simulated time.
22 """
23 return self.rightNow
24
25 def install(self):
26 """
27 Monkeypatch L{twisted.internet.reactor.seconds} to use
28 L{__call__} as a time source
29 """
30 # Violation is fun.
31 from twisted.internet import reactor
32 self.reactor_original = reactor.seconds
33 reactor.seconds = self
34
35 def uninstall(self):
36 """
37 Remove the monkeypatching of L{twisted.internet.reactor.seconds}.
38 """
39 from twisted.internet import reactor
40 reactor.seconds = self.reactor_original
41
42 def adjust(self, amount):
43 """
44 Adjust the current simulated time upward by the given C{amount}.
45
46 Note that this does not cause any scheduled calls to be run.
47 """
48 self.rightNow += amount
49
50 def pump(self, reactor, timings):
51 """
52 Iterate the given C{reactor} with increments of time specified
53 by C{timings}.
54
55 For each timing, the simulated time will be L{adjust}ed and
56 the reactor will be iterated twice.
57 """
58 timings = list(timings)
59 timings.reverse()
60 self.adjust(timings.pop())
61 while timings:
62 self.adjust(timings.pop())
63 reactor.iterate()
64 reactor.iterate()
65
OLDNEW
« no previous file with comments | « third_party/twisted_8_1/twisted/test/threading_latency.py ('k') | third_party/twisted_8_1/twisted/topfiles/CREDITS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698