[pypy-commit] pypy py3k: implement space.str() in terms of space.unicode_w. This fixes the two previously failing tests added in this commit

antocuni noreply at buildbot.pypy.org
Sat Sep 1 14:40:46 CEST 2012


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: py3k
Changeset: r57067:bc50c60a51e4
Date: 2012-09-01 14:39 +0200
http://bitbucket.org/pypy/pypy/changeset/bc50c60a51e4/

Log:	implement space.str() in terms of space.unicode_w. This fixes the
	two previously failing tests added in this commit

diff --git a/pypy/module/exceptions/test/test_exc.py b/pypy/module/exceptions/test/test_exc.py
--- a/pypy/module/exceptions/test/test_exc.py
+++ b/pypy/module/exceptions/test/test_exc.py
@@ -1,3 +1,4 @@
+# -*- encoding: utf-8 -*-
 
 from pypy.conftest import gettestobjspace
 
@@ -120,6 +121,10 @@
         assert SystemExit("x").code == "x"
         assert SystemExit(1, 2).code == (1, 2)
 
+    def test_str_unicode(self):
+        e = ValueError('àèì')
+        assert str(e) == 'àèì'
+
     def test_unicode_decode_error(self):
         ud = UnicodeDecodeError("x", b"y", 1, 5, "bah")
         assert ud.encoding == 'x'
diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -665,7 +665,7 @@
             if space.is_true(space.isinstance(w_result, space.w_str)):
                 return w_result
             try:
-                result = space.str_w(w_result)
+                result = space.unicode_w(w_result)
             except OperationError, e:
                 if not e.match(space, space.w_TypeError):
                     raise
diff --git a/pypy/objspace/test/test_descroperation.py b/pypy/objspace/test/test_descroperation.py
--- a/pypy/objspace/test/test_descroperation.py
+++ b/pypy/objspace/test/test_descroperation.py
@@ -1,4 +1,4 @@
-
+# -*- encoding: utf-8 -*-
 
 class Test_DescrOperation:
 
@@ -288,6 +288,18 @@
             answer = 42
             raises(TypeError, operate, A())
 
+    def test_string_results_unicode(self):
+        class A(object):
+            def __str__(self):
+                return 'àèì'
+            def __repr__(self):
+                return 'àèì'
+
+        for operate in (str, repr):
+            x = operate(A())
+            assert x == 'àèì'
+            assert type(x) is str
+            
     def test_missing_getattribute(self):
         class X(object): pass
 


More information about the pypy-commit mailing list