diff options
| author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2009-02-08 19:14:41 (GMT) |
|---|---|---|
| committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2009-02-08 19:14:41 (GMT) |
| commit | 9c78658670ed97c49a474e7b6d334dc0cd3083c8 (patch) | |
| tree | e55136ebb3e624636ddaa79fa2c2cc3cdebcbfd0 /Lib/test/test_logging.py | |
| parent | dd0989e7df0fa92a612dafd1180519a5d573b83a (diff) | |
| download | cpython-9c78658670ed97c49a474e7b6d334dc0cd3083c8.zip cpython-9c78658670ed97c49a474e7b6d334dc0cd3083c8.tar.gz cpython-9c78658670ed97c49a474e7b6d334dc0cd3083c8.tar.bz2 | |
Issue #5170: Fixed Unicode output bug in logging and added test case. This is a regression which did not occur in 2.5.
Diffstat (limited to 'Lib/test/test_logging.py')
| -rw-r--r-- | Lib/test/test_logging.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index e837d41..c48012e 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -859,6 +859,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. @@ -885,6 +886,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') + + # Set the locale to the platform-dependent default. I have no idea # why the test does this, but in any case we save the current locale # first and restore it at the end. |
