mirror of
https://github.com/docker/compose.git
synced 2025-04-08 17:05:13 +02:00
Closes: #6890 Some remarks, - `# coding ... utf-8` statements are not needed - isdigit on strings instead of a try-catch. - Default opening mode is read, so we can do `open()` without the `'r'` everywhere - Removed inheritinng from `object` class, it isn't necessary in python3. - `super(ClassName, self)` can now be replaced with `super()` - Use of itertools and `chain` on a couple places dealing with sets. - Used the operator module instead of lambdas when warranted `itemgetter(0)` instead of `lambda x: x[0]` `attrgetter('name')` instead of `lambda x: x.name` - `sorted` returns a list, so no need to use `list(sorted(...))` - Removed `dict()` using dictionary comprehensions whenever possible - Attempted to remove python3.2 support Signed-off-by: alexrecuenco <alejandrogonzalezrecuenco@gmail.com>
50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
import logging
|
|
|
|
from compose.cli import colors
|
|
from compose.cli.formatter import ConsoleWarningFormatter
|
|
from tests import unittest
|
|
|
|
|
|
MESSAGE = 'this is the message'
|
|
|
|
|
|
def make_log_record(level, message=None):
|
|
return logging.LogRecord('name', level, 'pathame', 0, message or MESSAGE, (), None)
|
|
|
|
|
|
class ConsoleWarningFormatterTestCase(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
self.formatter = ConsoleWarningFormatter()
|
|
|
|
def test_format_warn(self):
|
|
output = self.formatter.format(make_log_record(logging.WARN))
|
|
expected = colors.yellow('WARNING') + ': '
|
|
assert output == expected + MESSAGE
|
|
|
|
def test_format_error(self):
|
|
output = self.formatter.format(make_log_record(logging.ERROR))
|
|
expected = colors.red('ERROR') + ': '
|
|
assert output == expected + MESSAGE
|
|
|
|
def test_format_info(self):
|
|
output = self.formatter.format(make_log_record(logging.INFO))
|
|
assert output == MESSAGE
|
|
|
|
def test_format_unicode_info(self):
|
|
message = b'\xec\xa0\x95\xec\x88\x98\xec\xa0\x95'
|
|
output = self.formatter.format(make_log_record(logging.INFO, message))
|
|
assert output == message.decode('utf-8')
|
|
|
|
def test_format_unicode_warn(self):
|
|
message = b'\xec\xa0\x95\xec\x88\x98\xec\xa0\x95'
|
|
output = self.formatter.format(make_log_record(logging.WARN, message))
|
|
expected = colors.yellow('WARNING') + ': '
|
|
assert output == '{}{}'.format(expected, message.decode('utf-8'))
|
|
|
|
def test_format_unicode_error(self):
|
|
message = b'\xec\xa0\x95\xec\x88\x98\xec\xa0\x95'
|
|
output = self.formatter.format(make_log_record(logging.ERROR, message))
|
|
expected = colors.red('ERROR') + ': '
|
|
assert output == '{}{}'.format(expected, message.decode('utf-8'))
|