1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
import logbook
from .utils import capturing_stderr_context
def test_default_format_unicode(logger):
with capturing_stderr_context() as stream:
logger.warn("\u2603")
assert "WARNING: testlogger: \u2603" in stream.getvalue()
def test_default_format_encoded(logger):
with capturing_stderr_context() as stream:
# it's a string but it's in the right encoding so don't barf
logger.warn("\u2603")
assert "WARNING: testlogger: \u2603" in stream.getvalue()
def test_default_format_bad_encoding(logger):
with capturing_stderr_context() as stream:
# it's a string, is wrong, but just dump it in the logger,
# don't try to decode/encode it
logger.warn("Русский".encode("koi8-r"))
expected = "WARNING: testlogger: b'\\xf2\\xd5\\xd3\\xd3\\xcb\\xc9\\xca'"
assert expected in stream.getvalue()
def test_custom_unicode_format_unicode(logger):
format_string = "[{record.level_name}] {record.channel}: {record.message}"
with capturing_stderr_context() as stream:
with logbook.StderrHandler(format_string=format_string):
logger.warn("\u2603")
assert "[WARNING] testlogger: \u2603" in stream.getvalue()
def test_custom_string_format_unicode(logger):
format_string = "[{record.level_name}] {record.channel}: {record.message}"
with capturing_stderr_context() as stream:
with logbook.StderrHandler(format_string=format_string):
logger.warn("\u2603")
assert "[WARNING] testlogger: \u2603" in stream.getvalue()
def test_unicode_message_encoded_params(logger):
with capturing_stderr_context() as stream:
logger.warn("\u2603 {0}", "\u2603".encode())
assert "WARNING: testlogger: \u2603 b'\\xe2\\x98\\x83'" in stream.getvalue()
def test_encoded_message_unicode_params(logger):
with capturing_stderr_context() as stream:
logger.warn("\u2603 {0}".encode(), "\u2603")
assert "WARNING: testlogger: \u2603 \u2603" in stream.getvalue()
|