[py-svn] py-trunk commit e387b83b6267: fix unicode issues (port of pypy/py repo changeset r72526 by Armin)

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Tue Apr 27 12:23:59 CEST 2010


# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview
# User holger krekel <holger at merlinux.eu>
# Date 1272363793 -7200
# Node ID e387b83b6267b3fd7e44b59b899299e528ce6733
# Parent  b6403d15ec5cd3ff9cb73663d6583b269c61c3e8
fix unicode issues (port of pypy/py repo changeset r72526 by Armin)

--- 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))

--- a/testing/code/test_code.py
+++ b/testing/code/test_code.py
@@ -192,3 +192,10 @@ def test_builtin_patch_unpatch(monkeypat
     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)

--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,10 +2,11 @@ Changes between 1.2.1 and 1.2.2 (release
 ==================================================
 
 - 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



More information about the pytest-commit mailing list