From f6a04b92d213e60031708da6ef4c74c940913a0f Mon Sep 17 00:00:00 2001 From: holger krekel Date: Tue, 27 Apr 2010 12:23:13 +0200 Subject: [PATCH] fix unicode issues (port of pypy/py repo changeset r72526 by Armin) --HG-- branch : trunk --- CHANGELOG | 3 ++- py/_code/code.py | 5 ++++- testing/code/test_code.py | 7 +++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2f373122b..7f1232366 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,10 +2,11 @@ Changes between 1.2.1 and 1.2.2 (release pending) ================================================== - new mechanism to allow plugins to register new hooks +- fixes for handling of unicode exception values - added links to the new capturelog and coverage plugins - (issue87) fix unboundlocal error in assertionold code - (issue86) improve documentation for looponfailing -- fix jython/win32 issues +- fixes for making jython/win32 work more properly - ship distribute_setup.py version 0.6.10 diff --git a/py/_code/code.py b/py/_code/code.py index ee054fc2e..7cfec853b 100644 --- a/py/_code/code.py +++ b/py/_code/code.py @@ -581,7 +581,10 @@ class TerminalRepr: def __str__(self): tw = py.io.TerminalWriter(stringio=True) self.toterminal(tw) - return tw.stringio.getvalue().strip() + s = tw.stringio.getvalue().strip() + if sys.version_info[0] < 3: + s = s.encode('utf-8') + return s def __repr__(self): return "<%s instance at %0x>" %(self.__class__, id(self)) diff --git a/testing/code/test_code.py b/testing/code/test_code.py index f9f478aa9..583fc7852 100644 --- a/testing/code/test_code.py +++ b/testing/code/test_code.py @@ -192,3 +192,10 @@ def test_builtin_patch_unpatch(monkeypatch): assert cpy_builtin.AssertionError is Sub assert cpy_builtin.compile == mycompile + +def test_unicode_handling(testdir): + value = py.builtin._totext('\xc4\x85\xc4\x87\n', 'utf-8').encode('utf8') + def f(): + raise Exception(value) + excinfo = py.test.raises(Exception, f) + s = str(excinfo)