mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Add failing 2.6 test
This commit is contained in:
parent
460582dacd
commit
8b0a2abaf9
1 changed files with 38 additions and 0 deletions
38
tests/logging_handler_test.py
Normal file
38
tests/logging_handler_test.py
Normal file
|
|
@ -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',
|
||||||
|
)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue