Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8b0a2ab

Browse files
committed
Add failing 2.6 test
1 parent 460582d commit 8b0a2ab

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

tests/logging_handler_test.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import __builtin__
2+
import mock
3+
import pytest
4+
5+
from pre_commit import color
6+
from pre_commit.logging_handler import LoggingHandler
7+
8+
9+
@pytest.yield_fixture
10+
def print_mock():
11+
with mock.patch.object(__builtin__, 'print', autospec=True) as print_mock:
12+
yield print_mock
13+
14+
15+
class FakeLogRecord(object):
16+
def __init__(self, message, levelname, levelno):
17+
self.message = message
18+
self.levelname = levelname
19+
self.levelno = levelno
20+
21+
def getMessage(self):
22+
return self.message
23+
24+
25+
def test_logging_handler_color(print_mock):
26+
handler = LoggingHandler(True)
27+
handler.emit(FakeLogRecord('hi', 'WARNING', 30))
28+
print_mock.assert_called_once_with(
29+
color.YELLOW + '[WARNING]' + color.NORMAL + ' hi',
30+
)
31+
32+
33+
def test_logging_handler_no_color(print_mock):
34+
handler = LoggingHandler(False)
35+
handler.emit(FakeLogRecord('hi', 'WARNING', 30))
36+
print_mock.assert_called_once_with(
37+
'[WARNING] hi',
38+
)

0 commit comments

Comments
 (0)