test_strports.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. Tests for L{twisted.application.strports}.
  5. """
  6. from __future__ import absolute_import, division
  7. from twisted.trial.unittest import TestCase
  8. from twisted.application import strports
  9. from twisted.application import internet
  10. from twisted.internet.protocol import Factory
  11. from twisted.internet.endpoints import TCP4ServerEndpoint
  12. class ServiceTests(TestCase):
  13. """
  14. Tests for L{strports.service}.
  15. """
  16. def test_service(self):
  17. """
  18. L{strports.service} returns a L{StreamServerEndpointService}
  19. constructed with an endpoint produced from
  20. L{endpoint.serverFromString}, using the same syntax.
  21. """
  22. reactor = object() # the cake is a lie
  23. aFactory = Factory()
  24. aGoodPort = 1337
  25. svc = strports.service(
  26. 'tcp:' + str(aGoodPort), aFactory, reactor=reactor)
  27. self.assertIsInstance(svc, internet.StreamServerEndpointService)
  28. # See twisted.application.test.test_internet.EndpointServiceTests.
  29. # test_synchronousRaiseRaisesSynchronously
  30. self.assertTrue(svc._raiseSynchronously)
  31. self.assertIsInstance(svc.endpoint, TCP4ServerEndpoint)
  32. # Maybe we should implement equality for endpoints.
  33. self.assertEqual(svc.endpoint._port, aGoodPort)
  34. self.assertIs(svc.factory, aFactory)
  35. self.assertIs(svc.endpoint._reactor, reactor)
  36. def test_serviceDefaultReactor(self):
  37. """
  38. L{strports.service} will use the default reactor when none is provided
  39. as an argument.
  40. """
  41. from twisted.internet import reactor as globalReactor
  42. aService = strports.service("tcp:80", None)
  43. self.assertIs(aService.endpoint._reactor, globalReactor)