[pypy-commit] pypy codec_errorhandler: add failing codec errorhandler test

mattip pypy.commits at gmail.com
Sat Sep 7 07:58:56 EDT 2019


Author: Matti Picus <matti.picus at gmail.com>
Branch: codec_errorhandler
Changeset: r97396:a6ee1c3084ed
Date: 2019-09-06 08:06 +0200
http://bitbucket.org/pypy/pypy/changeset/a6ee1c3084ed/

Log:	add failing codec errorhandler test

diff --git a/pypy/module/_codecs/test/test_codecs.py b/pypy/module/_codecs/test/test_codecs.py
--- a/pypy/module/_codecs/test/test_codecs.py
+++ b/pypy/module/_codecs/test/test_codecs.py
@@ -1006,6 +1006,22 @@
                                    1, 1 + n, "ouch")
             ) == (s[:1], 1 + n)
 
+    def test_replace_with_long(self):
+        #bpo-32583
+        import codecs
+        def replace_with_long(exc):
+            if isinstance(exc, UnicodeDecodeError):
+                exc.object = b"\x00" * 8
+                return ('\ufffd', exc.start)
+            else:
+                raise TypeError("don't know how to handle %r" % exc)
+        codecs.register_error("test.rep_w_long", replace_with_long)
+
+        ret = b'\x00'.decode('utf-16', 'test.rep_w_long')
+        assert ret == '\ufffd\x00\x00\x00\x00'
+        ret = b'\x00'.decode('utf-32', 'test.rep_w_long')
+        assert ret == '\ufffd\x00\x00'
+
     def test_badhandler(self):
         import codecs
         results = ( 42, u"foo", (1,2,3), (u"foo", 1, 3), (u"foo", None), (u"foo",), ("foo", 1, 3), ("foo", None), ("foo",) )


More information about the pypy-commit mailing list