Server IP : 104.21.38.3 / Your IP : 172.69.176.166 Web Server : Apache System : Linux krdc-ubuntu-s-2vcpu-4gb-amd-blr1-01.localdomain 5.15.0-142-generic #152-Ubuntu SMP Mon May 19 10:54:31 UTC 2025 x86_64 User : www ( 1000) PHP Version : 7.4.33 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /lib/python3/dist-packages/twisted/internet/test/ |
Upload File : |
# Copyright (c) Twisted Matrix Laboratories. # See LICENSE for details. """ Tests for L{twisted.internet.default}. """ import select import sys from twisted.internet import default from twisted.internet.default import _getInstallFunction, install from twisted.internet.interfaces import IReactorCore from twisted.internet.test.test_main import NoReactor from twisted.python.reflect import requireModule from twisted.python.runtime import Platform from twisted.trial.unittest import SynchronousTestCase unix = Platform("posix", "other") linux = Platform("posix", "linux2") windows = Platform("nt", "win32") osx = Platform("posix", "darwin") class PollReactorTests(SynchronousTestCase): """ Tests for the cases of L{twisted.internet.default._getInstallFunction} in which it picks the poll(2) or epoll(7)-based reactors. """ def assertIsPoll(self, install): """ Assert the given function will install the poll() reactor, or select() if poll() is unavailable. """ if hasattr(select, "poll"): self.assertEqual(install.__module__, "twisted.internet.pollreactor") else: self.assertEqual(install.__module__, "twisted.internet.selectreactor") def test_unix(self): """ L{_getInstallFunction} chooses the poll reactor on arbitrary Unix platforms, falling back to select(2) if it is unavailable. """ install = _getInstallFunction(unix) self.assertIsPoll(install) def test_linux(self): """ L{_getInstallFunction} chooses the epoll reactor on Linux, or poll if epoll is unavailable. """ install = _getInstallFunction(linux) if requireModule("twisted.internet.epollreactor") is None: self.assertIsPoll(install) else: self.assertEqual(install.__module__, "twisted.internet.epollreactor") class SelectReactorTests(SynchronousTestCase): """ Tests for the cases of L{twisted.internet.default._getInstallFunction} in which it picks the select(2)-based reactor. """ def test_osx(self): """ L{_getInstallFunction} chooses the select reactor on macOS. """ install = _getInstallFunction(osx) self.assertEqual(install.__module__, "twisted.internet.selectreactor") def test_windows(self): """ L{_getInstallFunction} chooses the select reactor on Windows. """ install = _getInstallFunction(windows) self.assertEqual(install.__module__, "twisted.internet.selectreactor") class InstallationTests(SynchronousTestCase): """ Tests for actual installation of the reactor. """ def test_install(self): """ L{install} installs a reactor. """ with NoReactor(): install() self.assertIn("twisted.internet.reactor", sys.modules) def test_reactor(self): """ Importing L{twisted.internet.reactor} installs the default reactor if none is installed. """ installed = [] def installer(): installed.append(True) return install() self.patch(default, "install", installer) with NoReactor(): from twisted.internet import reactor self.assertTrue(IReactorCore.providedBy(reactor)) self.assertEqual(installed, [True])