Merge pull request #2288 from dnephin/warning_about_vars
Add console color to warnings and errors so they are more obvious
This commit is contained in:
commit
c439e056a0
8 changed files with 111 additions and 17 deletions
35
tests/unit/cli/formatter_test.py
Normal file
35
tests/unit/cli/formatter_test.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
|
||||
from compose.cli import colors
|
||||
from compose.cli.formatter import ConsoleWarningFormatter
|
||||
from tests import unittest
|
||||
|
||||
|
||||
MESSAGE = 'this is the message'
|
||||
|
||||
|
||||
def makeLogRecord(level):
|
||||
return logging.LogRecord('name', level, 'pathame', 0, MESSAGE, (), None)
|
||||
|
||||
|
||||
class ConsoleWarningFormatterTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.formatter = ConsoleWarningFormatter()
|
||||
|
||||
def test_format_warn(self):
|
||||
output = self.formatter.format(makeLogRecord(logging.WARN))
|
||||
expected = colors.yellow('WARNING') + ': '
|
||||
assert output == expected + MESSAGE
|
||||
|
||||
def test_format_error(self):
|
||||
output = self.formatter.format(makeLogRecord(logging.ERROR))
|
||||
expected = colors.red('ERROR') + ': '
|
||||
assert output == expected + MESSAGE
|
||||
|
||||
def test_format_info(self):
|
||||
output = self.formatter.format(makeLogRecord(logging.INFO))
|
||||
assert output == MESSAGE
|
||||
|
|
@ -1,11 +1,15 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import logging
|
||||
|
||||
from compose import container
|
||||
from compose.cli.errors import UserError
|
||||
from compose.cli.formatter import ConsoleWarningFormatter
|
||||
from compose.cli.log_printer import LogPrinter
|
||||
from compose.cli.main import attach_to_logs
|
||||
from compose.cli.main import build_log_printer
|
||||
from compose.cli.main import convergence_strategy_from_opts
|
||||
from compose.cli.main import setup_console_handler
|
||||
from compose.project import Project
|
||||
from compose.service import ConvergenceStrategy
|
||||
from tests import mock
|
||||
|
|
@ -60,6 +64,31 @@ class CLIMainTestCase(unittest.TestCase):
|
|||
timeout=timeout)
|
||||
|
||||
|
||||
class SetupConsoleHandlerTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.stream = mock.Mock()
|
||||
self.stream.isatty.return_value = True
|
||||
self.handler = logging.StreamHandler(stream=self.stream)
|
||||
|
||||
def test_with_tty_verbose(self):
|
||||
setup_console_handler(self.handler, True)
|
||||
assert type(self.handler.formatter) == ConsoleWarningFormatter
|
||||
assert '%(name)s' in self.handler.formatter._fmt
|
||||
assert '%(funcName)s' in self.handler.formatter._fmt
|
||||
|
||||
def test_with_tty_not_verbose(self):
|
||||
setup_console_handler(self.handler, False)
|
||||
assert type(self.handler.formatter) == ConsoleWarningFormatter
|
||||
assert '%(name)s' not in self.handler.formatter._fmt
|
||||
assert '%(funcName)s' not in self.handler.formatter._fmt
|
||||
|
||||
def test_with_not_a_tty(self):
|
||||
self.stream.isatty.return_value = False
|
||||
setup_console_handler(self.handler, False)
|
||||
assert type(self.handler.formatter) == logging.Formatter
|
||||
|
||||
|
||||
class ConvergeStrategyFromOptsTestCase(unittest.TestCase):
|
||||
|
||||
def test_invalid_opts(self):
|
||||
|
|
|
|||
|
|
@ -380,7 +380,7 @@ class ConfigTest(unittest.TestCase):
|
|||
|
||||
@mock.patch('compose.config.validation.log')
|
||||
def test_logs_warning_for_boolean_in_environment(self, mock_logging):
|
||||
expected_warning_msg = "Warning: There is a boolean value in the 'environment' key."
|
||||
expected_warning_msg = "There is a boolean value in the 'environment' key."
|
||||
config.load(
|
||||
build_config_details(
|
||||
{'web': {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue