[pypy-svn] r48662 - in pypy/branch/more-unicode-improvements/pypy/module/_codecs: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Tue Nov 13 19:30:19 CET 2007


Author: cfbolz
Date: Tue Nov 13 19:30:18 2007
New Revision: 48662

Modified:
   pypy/branch/more-unicode-improvements/pypy/module/_codecs/interp_codecs.py
   pypy/branch/more-unicode-improvements/pypy/module/_codecs/test/test_codecs.py
Log:
oops, raise an app-level, not an interplevel error


Modified: pypy/branch/more-unicode-improvements/pypy/module/_codecs/interp_codecs.py
==============================================================================
--- pypy/branch/more-unicode-improvements/pypy/module/_codecs/interp_codecs.py	(original)
+++ pypy/branch/more-unicode-improvements/pypy/module/_codecs/interp_codecs.py	Tue Nov 13 19:30:18 2007
@@ -169,7 +169,9 @@
         w_res = space.call_function(w_decoder, w_obj, space.wrap(errors))
         if (not space.is_true(space.isinstance(w_res, space.w_tuple))
             or space.int_w(space.len(w_res)) != 2):
-            raise TypeError("encoder must return a tuple (object, integer)")
+            raise OperationError(
+                space.w_TypeError,
+                space.wrap("encoder must return a tuple (object, integer)"))
         return space.getitem(w_res, space.wrap(0))
     else:
         assert 0, "XXX, what to do here?"

Modified: pypy/branch/more-unicode-improvements/pypy/module/_codecs/test/test_codecs.py
==============================================================================
--- pypy/branch/more-unicode-improvements/pypy/module/_codecs/test/test_codecs.py	(original)
+++ pypy/branch/more-unicode-improvements/pypy/module/_codecs/test/test_codecs.py	Tue Nov 13 19:30:18 2007
@@ -261,6 +261,20 @@
         assert '\\253'.decode('string_escape') == chr(0253)
         assert '\\312'.decode('string_escape') == chr(0312)
 
+
     def test_decode_utf8_different_case(self):
         constant = u"a"
         assert constant.encode("utf-8") == constant.encode("UTF-8")
+
+    def test_codec_wrong_result(self):
+        import _codecs
+        def search_function(encoding):
+            def f(input, errors="strict"):
+                return 42
+            print encoding
+            if encoding == 'test.mytestenc':
+                return (f, f, None, None)
+            return None
+        _codecs.register(search_function)
+        raises(TypeError, "hello".decode, "test.mytestenc")
+        raises(TypeError, u"hello".encode, "test.mytestenc")



More information about the Pypy-commit mailing list