mirror of
https://github.com/certbot/certbot.git
synced 2026-07-30 18:04:31 +02:00
Merge pull request #367 from kuba/bugs/336
Call record.getMessage() in DialogHandler (fixes #336)
This commit is contained in:
@@ -37,7 +37,7 @@ class DialogHandler(logging.Handler): # pylint: disable=too-few-public-methods
|
|||||||
lines.
|
lines.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
for line in (record.msg % record.args).splitlines():
|
for line in record.getMessage().splitlines():
|
||||||
# check for lines that would wrap
|
# check for lines that would wrap
|
||||||
cur_out = line
|
cur_out = line
|
||||||
while len(cur_out) > self.width:
|
while len(cur_out) > self.width:
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
"""Tests for letsencrypt.client.log."""
|
"""Tests for letsencrypt.client.log."""
|
||||||
|
import logging
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
@@ -15,29 +16,33 @@ class DialogHandlerTest(unittest.TestCase):
|
|||||||
self.handler.PADDING_WIDTH = 4
|
self.handler.PADDING_WIDTH = 4
|
||||||
|
|
||||||
def test_adds_padding(self):
|
def test_adds_padding(self):
|
||||||
self.handler.emit(mock.MagicMock())
|
self.handler.emit(logging.makeLogRecord({}))
|
||||||
self.d.infobox.assert_called_once_with(mock.ANY, 4, 10)
|
self.d.infobox.assert_called_once_with(mock.ANY, 4, 10)
|
||||||
|
|
||||||
def test_args_in_msg_get_replaced(self):
|
def test_args_in_msg_get_replaced(self):
|
||||||
assert len('123456') <= self.handler.width
|
assert len('123456') <= self.handler.width
|
||||||
self.handler.emit(mock.MagicMock(msg='123%s', args=(456,)))
|
self.handler.emit(logging.makeLogRecord(
|
||||||
|
{'msg': '123%s', 'args': (456,)}))
|
||||||
self.d.infobox.assert_called_once_with('123456', mock.ANY, mock.ANY)
|
self.d.infobox.assert_called_once_with('123456', mock.ANY, mock.ANY)
|
||||||
|
|
||||||
def test_wraps_nospace_is_greedy(self):
|
def test_wraps_nospace_is_greedy(self):
|
||||||
assert len('1234567') > self.handler.width
|
assert len('1234567') > self.handler.width
|
||||||
self.handler.emit(mock.MagicMock(msg='1234567'))
|
self.handler.emit(logging.makeLogRecord({'msg': '1234567'}))
|
||||||
self.d.infobox.assert_called_once_with('123456\n7', mock.ANY, mock.ANY)
|
self.d.infobox.assert_called_once_with('123456\n7', mock.ANY, mock.ANY)
|
||||||
|
|
||||||
def test_wraps_at_whitespace(self):
|
def test_wraps_at_whitespace(self):
|
||||||
assert len('123 567') > self.handler.width
|
assert len('123 567') > self.handler.width
|
||||||
self.handler.emit(mock.MagicMock(msg='123 567'))
|
self.handler.emit(logging.makeLogRecord({'msg': '123 567'}))
|
||||||
self.d.infobox.assert_called_once_with('123\n567', mock.ANY, mock.ANY)
|
self.d.infobox.assert_called_once_with('123\n567', mock.ANY, mock.ANY)
|
||||||
|
|
||||||
def test_only_last_lines_are_printed(self):
|
def test_only_last_lines_are_printed(self):
|
||||||
assert len('a\nb\nc'.split()) > self.handler.height
|
assert len('a\nb\nc'.split()) > self.handler.height
|
||||||
self.handler.emit(mock.MagicMock(msg='a\n\nb\nc'))
|
self.handler.emit(logging.makeLogRecord({'msg': 'a\n\nb\nc'}))
|
||||||
self.d.infobox.assert_called_once_with('b\nc', mock.ANY, mock.ANY)
|
self.d.infobox.assert_called_once_with('b\nc', mock.ANY, mock.ANY)
|
||||||
|
|
||||||
|
def test_non_str(self):
|
||||||
|
self.handler.emit(logging.makeLogRecord({'msg': {'foo': 'bar'}}))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user