test_main.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. Tests for L{twisted.internet.main}.
  5. """
  6. from __future__ import division, absolute_import
  7. from twisted.trial import unittest
  8. from twisted.internet.error import ReactorAlreadyInstalledError
  9. from twisted.internet.main import installReactor
  10. from twisted.internet.test.modulehelpers import NoReactor
  11. class InstallReactorTests(unittest.SynchronousTestCase):
  12. """
  13. Tests for L{installReactor}.
  14. """
  15. def test_installReactor(self):
  16. """
  17. L{installReactor} installs a new reactor if none is present.
  18. """
  19. with NoReactor():
  20. newReactor = object()
  21. installReactor(newReactor)
  22. from twisted.internet import reactor
  23. self.assertIs(newReactor, reactor)
  24. def test_alreadyInstalled(self):
  25. """
  26. If a reactor is already installed, L{installReactor} raises
  27. L{ReactorAlreadyInstalledError}.
  28. """
  29. with NoReactor():
  30. installReactor(object())
  31. self.assertRaises(ReactorAlreadyInstalledError, installReactor,
  32. object())
  33. def test_errorIsAnAssertionError(self):
  34. """
  35. For backwards compatibility, L{ReactorAlreadyInstalledError} is an
  36. L{AssertionError}.
  37. """
  38. self.assertTrue(issubclass(ReactorAlreadyInstalledError,
  39. AssertionError))