1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
5 Tests for L{twisted.internet.default}.
9 from twisted.trial.unittest import TestCase
10 from twisted.python.runtime import Platform
11 from twisted.internet.default import _getInstallFunction
13 unix = Platform('posix', 'other')
14 linux = Platform('posix', 'linux2')
15 windows = Platform('nt', 'win32')
16 osx = Platform('posix', 'darwin')
19 class PollReactorTests(TestCase):
21 Tests for the cases of L{twisted.internet.default._getInstallFunction}
22 in which it picks the poll(2) or epoll(7)-based reactors.
25 def assertIsPoll(self, install):
27 Assert the given function will install the poll() reactor, or select()
28 if poll() is unavailable.
30 if hasattr(select, "poll"):
32 install.__module__, 'twisted.internet.pollreactor')
35 install.__module__, 'twisted.internet.selectreactor')
40 L{_getInstallFunction} chooses the poll reactor on arbitrary Unix
41 platforms, falling back to select(2) if it is unavailable.
43 install = _getInstallFunction(unix)
44 self.assertIsPoll(install)
49 L{_getInstallFunction} chooses the epoll reactor on Linux, or poll if
52 install = _getInstallFunction(linux)
54 from twisted.internet import epollreactor
56 self.assertIsPoll(install)
59 install.__module__, 'twisted.internet.epollreactor')
63 class SelectReactorTests(TestCase):
65 Tests for the cases of L{twisted.internet.default._getInstallFunction}
66 in which it picks the select(2)-based reactor.
70 L{_getInstallFunction} chooses the select reactor on OS X.
72 install = _getInstallFunction(osx)
74 install.__module__, 'twisted.internet.selectreactor')
77 def test_windows(self):
79 L{_getInstallFunction} chooses the select reactor on Windows.
81 install = _getInstallFunction(windows)
83 install.__module__, 'twisted.internet.selectreactor')