From 8b0a2abaf9c942f2fd49827e898700de54fdb8af Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Mon, 7 Apr 2014 16:59:20 -0700 Subject: [PATCH 1/2] Add failing 2.6 test --- tests/logging_handler_test.py | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/logging_handler_test.py diff --git a/tests/logging_handler_test.py b/tests/logging_handler_test.py new file mode 100644 index 00000000..d2fed418 --- /dev/null +++ b/tests/logging_handler_test.py @@ -0,0 +1,38 @@ +import __builtin__ +import mock +import pytest + +from pre_commit import color +from pre_commit.logging_handler import LoggingHandler + + +@pytest.yield_fixture +def print_mock(): + with mock.patch.object(__builtin__, 'print', autospec=True) as print_mock: + yield print_mock + + +class FakeLogRecord(object): + def __init__(self, message, levelname, levelno): + self.message = message + self.levelname = levelname + self.levelno = levelno + + def getMessage(self): + return self.message + + +def test_logging_handler_color(print_mock): + handler = LoggingHandler(True) + handler.emit(FakeLogRecord('hi', 'WARNING', 30)) + print_mock.assert_called_once_with( + color.YELLOW + '[WARNING]' + color.NORMAL + ' hi', + ) + + +def test_logging_handler_no_color(print_mock): + handler = LoggingHandler(False) + handler.emit(FakeLogRecord('hi', 'WARNING', 30)) + print_mock.assert_called_once_with( + '[WARNING] hi', + ) From 7a8dcb0ca91d0f2d55b8ad1d432b036870c12ea2 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Mon, 7 Apr 2014 17:04:21 -0700 Subject: [PATCH 2/2] Python 2.6 compatibility for LoggingHandler. Closes #66. --- pre_commit/logging_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pre_commit/logging_handler.py b/pre_commit/logging_handler.py index 11736d1b..70b61e73 100644 --- a/pre_commit/logging_handler.py +++ b/pre_commit/logging_handler.py @@ -16,7 +16,7 @@ LOG_LEVEL_COLORS = { class LoggingHandler(logging.Handler): def __init__(self, use_color): - super(LoggingHandler, self).__init__() + logging.Handler.__init__(self) self.use_color = use_color def emit(self, record):