[pypy-commit] pypy stdlib-2.7.8: Fixed test_exceptions.py

alex_gaynor noreply at buildbot.pypy.org
Sat Aug 23 07:22:29 CEST 2014


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: stdlib-2.7.8
Changeset: r72992:bd46b6d4447e
Date: 2014-08-22 22:22 -0700
http://bitbucket.org/pypy/pypy/changeset/bd46b6d4447e/

Log:	Fixed test_exceptions.py

diff --git a/pypy/module/exceptions/interp_exceptions.py b/pypy/module/exceptions/interp_exceptions.py
--- a/pypy/module/exceptions/interp_exceptions.py
+++ b/pypy/module/exceptions/interp_exceptions.py
@@ -278,10 +278,10 @@
 
 class W_UnicodeTranslateError(W_UnicodeError):
     """Unicode translation error."""
-    object = None
-    start = None
-    end = None
-    reason = None
+    w_object = None
+    w_start = None
+    w_end = None
+    w_reason = None
 
     def descr_init(self, space, w_object, w_start, w_end, w_reason):
         # typechecking
@@ -299,6 +299,8 @@
 
     def descr_str(self, space):
         return space.appexec([space.wrap(self)], r"""(self):
+            if self.object is None:
+                return ""
             if self.end == self.start + 1:
                 badchar = ord(self.object[self.start])
                 if badchar <= 0xff:
@@ -642,6 +644,8 @@
 
     def descr_str(self, space):
         return space.appexec([self], """(self):
+            if self.object is None:
+                return ""
             if self.end == self.start + 1:
                 return "'%s' codec can't decode byte 0x%02x in position %d: %s"%(
                     self.encoding,
@@ -730,6 +734,8 @@
 
     def descr_str(self, space):
         return space.appexec([self], r"""(self):
+            if self.object is None:
+                return ""
             if self.end == self.start + 1:
                 badchar = ord(self.object[self.start])
                 if badchar <= 0xff:
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
@@ -253,3 +253,7 @@
         assert fw.z == 1
         assert fw.xyz == (1, 2)
 
+    def test_unicode_error_uninitialized_str(self):
+        assert str(UnicodeEncodeError.__new__(UnicodeEncodeError)) == ""
+        assert str(UnicodeDecodeError.__new__(UnicodeDecodeError)) == ""
+        assert str(UnicodeTranslateError.__new__(UnicodeTranslateError)) == ""


More information about the pypy-commit mailing list