test_levels.py 875 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. Test cases for L{twisted.logger._levels}.
  5. """
  6. from twisted.trial import unittest
  7. from .._levels import InvalidLogLevelError
  8. from .._levels import LogLevel
  9. class LogLevelTests(unittest.TestCase):
  10. """
  11. Tests for L{LogLevel}.
  12. """
  13. def test_levelWithName(self):
  14. """
  15. Look up log level by name.
  16. """
  17. for level in LogLevel.iterconstants():
  18. self.assertIs(LogLevel.levelWithName(level.name), level)
  19. def test_levelWithInvalidName(self):
  20. """
  21. You can't make up log level names.
  22. """
  23. bogus = "*bogus*"
  24. try:
  25. LogLevel.levelWithName(bogus)
  26. except InvalidLogLevelError as e:
  27. self.assertIs(e.level, bogus)
  28. else:
  29. self.fail("Expected InvalidLogLevelError.")