test_inetdconf.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. Tests for implementations of L{inetdconf}.
  5. """
  6. from twisted.runner import inetdconf
  7. from twisted.trial import unittest
  8. class ServicesConfTests(unittest.TestCase):
  9. """
  10. Tests for L{inetdconf.ServicesConf}
  11. """
  12. servicesFilename1 = None
  13. servicesFilename2 = None
  14. def setUp(self):
  15. self.servicesFilename1 = self.mktemp()
  16. with open(self.servicesFilename1, "w") as f:
  17. f.write("""
  18. # This is a comment
  19. http 80/tcp www www-http # WorldWideWeb HTTP
  20. http 80/udp www www-http
  21. http 80/sctp
  22. """)
  23. self.servicesFilename2 = self.mktemp()
  24. with open(self.servicesFilename2, "w") as f:
  25. f.write("""
  26. https 443/tcp # http protocol over TLS/SSL
  27. """)
  28. def test_parseDefaultFilename(self):
  29. """
  30. Services are parsed from default filename.
  31. """
  32. conf = inetdconf.ServicesConf()
  33. conf.defaultFilename = self.servicesFilename1
  34. conf.parseFile()
  35. self.assertEqual(conf.services, {
  36. ("http", "tcp"): 80,
  37. ("http", "udp"): 80,
  38. ("http", "sctp"): 80,
  39. ("www", "tcp"): 80,
  40. ("www", "udp"): 80,
  41. ("www-http", "tcp"): 80,
  42. ("www-http", "udp"): 80,
  43. })
  44. def test_parseFile(self):
  45. """
  46. Services are parsed from given C{file}.
  47. """
  48. conf = inetdconf.ServicesConf()
  49. with open(self.servicesFilename2) as f:
  50. conf.parseFile(f)
  51. self.assertEqual(conf.services, {
  52. ("https", "tcp"): 443,
  53. })