Initial import to Tizen
[profile/ivi/python-twisted.git] / twisted / internet / test / test_time.py
1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
3
4 """
5 Tests for implementations of L{IReactorTime}.
6 """
7
8 __metaclass__ = type
9
10 from twisted.python.runtime import platform
11 from twisted.internet.test.reactormixins import ReactorBuilder
12
13
14 class TimeTestsBuilder(ReactorBuilder):
15     """
16     Builder for defining tests relating to L{IReactorTime}.
17     """
18     def test_delayedCallStopsReactor(self):
19         """
20         The reactor can be stopped by a delayed call.
21         """
22         reactor = self.buildReactor()
23         reactor.callLater(0, reactor.stop)
24         reactor.run()
25
26
27
28 class GlibTimeTestsBuilder(ReactorBuilder):
29     """
30     Builder for defining tests relating to L{IReactorTime} for reactors based
31     off glib.
32     """
33     if platform.isWindows():
34         _reactors = ["twisted.internet.gtk2reactor.PortableGtkReactor"]
35     else:
36         _reactors = ["twisted.internet.glib2reactor.Glib2Reactor",
37                      "twisted.internet.gtk2reactor.Gtk2Reactor"]
38
39     def test_timeout_add(self):
40         """
41         A C{reactor.callLater} call scheduled from a C{gobject.timeout_add}
42         call is run on time.
43         """
44         import gobject
45         reactor = self.buildReactor()
46
47         result = []
48         def gschedule():
49             reactor.callLater(0, callback)
50             return 0
51         def callback():
52             result.append(True)
53             reactor.stop()
54
55         reactor.callWhenRunning(gobject.timeout_add, 10, gschedule)
56         self.runReactor(reactor, 5)
57         self.assertEqual(result, [True])
58
59
60 globals().update(TimeTestsBuilder.makeTestCaseClasses())
61 globals().update(GlibTimeTestsBuilder.makeTestCaseClasses())