Initial import to Tizen
[profile/ivi/python-twisted.git] / twisted / internet / test / test_default.py
1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
3
4 """
5 Tests for L{twisted.internet.default}.
6 """
7
8 import select
9 from twisted.trial.unittest import TestCase
10 from twisted.python.runtime import Platform
11 from twisted.internet.default import _getInstallFunction
12
13 unix = Platform('posix', 'other')
14 linux = Platform('posix', 'linux2')
15 windows = Platform('nt', 'win32')
16 osx = Platform('posix', 'darwin')
17
18
19 class PollReactorTests(TestCase):
20     """
21     Tests for the cases of L{twisted.internet.default._getInstallFunction}
22     in which it picks the poll(2) or epoll(7)-based reactors.
23     """
24
25     def assertIsPoll(self, install):
26         """
27         Assert the given function will install the poll() reactor, or select()
28         if poll() is unavailable.
29         """
30         if hasattr(select, "poll"):
31             self.assertEqual(
32                 install.__module__, 'twisted.internet.pollreactor')
33         else:
34             self.assertEqual(
35                 install.__module__, 'twisted.internet.selectreactor')
36
37
38     def test_unix(self):
39         """
40         L{_getInstallFunction} chooses the poll reactor on arbitrary Unix
41         platforms, falling back to select(2) if it is unavailable.
42         """
43         install = _getInstallFunction(unix)
44         self.assertIsPoll(install)
45
46
47     def test_linux(self):
48         """
49         L{_getInstallFunction} chooses the epoll reactor on Linux, or poll if
50         epoll is unavailable.
51         """
52         install = _getInstallFunction(linux)
53         try:
54             from twisted.internet import epollreactor
55         except ImportError:
56             self.assertIsPoll(install)
57         else:
58             self.assertEqual(
59                 install.__module__, 'twisted.internet.epollreactor')
60
61
62
63 class SelectReactorTests(TestCase):
64     """
65     Tests for the cases of L{twisted.internet.default._getInstallFunction}
66     in which it picks the select(2)-based reactor.
67     """
68     def test_osx(self):
69         """
70         L{_getInstallFunction} chooses the select reactor on OS X.
71         """
72         install = _getInstallFunction(osx)
73         self.assertEqual(
74             install.__module__, 'twisted.internet.selectreactor')
75
76
77     def test_windows(self):
78         """
79         L{_getInstallFunction} chooses the select reactor on Windows.
80         """
81         install = _getInstallFunction(windows)
82         self.assertEqual(
83             install.__module__, 'twisted.internet.selectreactor')