]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Add a test case that checks that the proper exception is raises
authorWalter Dörwald <walter@livinglogic.de>
Fri, 6 Sep 2002 17:21:40 +0000 (17:21 +0000)
committerWalter Dörwald <walter@livinglogic.de>
Fri, 6 Sep 2002 17:21:40 +0000 (17:21 +0000)
when the replacement from an encoding error callback is itself
unencodable.

Lib/test/test_codeccallbacks.py

index 1650965a99a76c14c6d25fb3d1ef917c43d0b3f7..8ae3b1121025e8d689b7a74e43a21ee0195a5f90 100644 (file)
@@ -474,6 +474,21 @@ class CodecCallbackTest(unittest.TestCase):
             codecs.lookup_error("backslashreplace")
         )
 
+    def test_unencodablereplacement(self):
+        def unencrepl(exc):
+            if isinstance(exc, UnicodeEncodeError):
+                return (u"\u4242", exc.end)
+            else:
+                raise TypeError("don't know how to handle %r" % exc)
+        codecs.register_error("test.unencreplhandler", unencrepl)
+        for enc in ("ascii", "iso-8859-1", "iso-8859-15"):
+            self.assertRaises(
+                UnicodeEncodeError,
+                u"\u4242".encode,
+                enc,
+                "test.unencreplhandler"
+            )
+
 def test_main():
     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(CodecCallbackTest))