mirror of
https://github.com/python/cpython.git
synced 2025-07-31 07:04:42 +00:00
Issue #5170: Fixed Unicode output bug in logging and added test case. This is a regression which did not occur in 2.5.
This commit is contained in:
parent
9e58a37252
commit
b20af944d2
3 changed files with 38 additions and 10 deletions
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2001-2004 by Vinay Sajip. All Rights Reserved.
|
||||
# Copyright 2001-2009 by Vinay Sajip. All Rights Reserved.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose and without fee is hereby granted,
|
||||
|
@ -18,13 +18,14 @@
|
|||
|
||||
"""Test harness for the logging module. Run all tests.
|
||||
|
||||
Copyright (C) 2001-2008 Vinay Sajip. All Rights Reserved.
|
||||
Copyright (C) 2001-2009 Vinay Sajip. All Rights Reserved.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import logging.handlers
|
||||
import logging.config
|
||||
|
||||
import codecs
|
||||
import copy
|
||||
import cPickle
|
||||
import cStringIO
|
||||
|
@ -860,6 +861,7 @@ class MemoryTest(BaseTest):
|
|||
('foo', 'DEBUG', '3'),
|
||||
])
|
||||
|
||||
|
||||
class EncodingTest(BaseTest):
|
||||
def test_encoding_plain_file(self):
|
||||
# In Python 2.x, a plain file object is treated as having no encoding.
|
||||
|
@ -886,6 +888,27 @@ class EncodingTest(BaseTest):
|
|||
if os.path.isfile(fn):
|
||||
os.remove(fn)
|
||||
|
||||
def test_encoding_cyrillic_unicode(self):
|
||||
log = logging.getLogger("test")
|
||||
#Get a message in Unicode: Do svidanya in Cyrillic (meaning goodbye)
|
||||
message = u'\u0434\u043e \u0441\u0432\u0438\u0434\u0430\u043d\u0438\u044f'
|
||||
#Ensure it's written in a Cyrillic encoding
|
||||
writer_class = codecs.getwriter('cp1251')
|
||||
stream = cStringIO.StringIO()
|
||||
writer = writer_class(stream, 'strict')
|
||||
handler = logging.StreamHandler(writer)
|
||||
log.addHandler(handler)
|
||||
try:
|
||||
log.warning(message)
|
||||
finally:
|
||||
log.removeHandler(handler)
|
||||
handler.close()
|
||||
# check we wrote exactly those bytes, ignoring trailing \n etc
|
||||
s = stream.getvalue()
|
||||
#Compare against what the data should be when encoded in CP-1251
|
||||
self.assertEqual(s, '\xe4\xee \xf1\xe2\xe8\xe4\xe0\xed\xe8\xff\n')
|
||||
|
||||
|
||||
class WarningsTest(BaseTest):
|
||||
def test_warnings(self):
|
||||
logging.captureWarnings(True)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue