formatter_test.py 1007 B

1234567891011121314151617181920212223242526272829303132333435
  1. from __future__ import absolute_import
  2. from __future__ import unicode_literals
  3. import logging
  4. from compose.cli import colors
  5. from compose.cli.formatter import ConsoleWarningFormatter
  6. from tests import unittest
  7. MESSAGE = 'this is the message'
  8. def makeLogRecord(level):
  9. return logging.LogRecord('name', level, 'pathame', 0, MESSAGE, (), None)
  10. class ConsoleWarningFormatterTestCase(unittest.TestCase):
  11. def setUp(self):
  12. self.formatter = ConsoleWarningFormatter()
  13. def test_format_warn(self):
  14. output = self.formatter.format(makeLogRecord(logging.WARN))
  15. expected = colors.yellow('WARNING') + ': '
  16. assert output == expected + MESSAGE
  17. def test_format_error(self):
  18. output = self.formatter.format(makeLogRecord(logging.ERROR))
  19. expected = colors.red('ERROR') + ': '
  20. assert output == expected + MESSAGE
  21. def test_format_info(self):
  22. output = self.formatter.format(makeLogRecord(logging.INFO))
  23. assert output == MESSAGE