From: Walter Dörwald Date: Fri, 6 Sep 2002 17:21:40 +0000 (+0000) Subject: Add a test case that checks that the proper exception is raises X-Git-Tag: v2.3c1~4196 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9ab7dd4d5b616cd9486d3a73a5e8320f8c913a1a;p=thirdparty%2FPython%2Fcpython.git Add a test case that checks that the proper exception is raises when the replacement from an encoding error callback is itself unencodable. --- diff --git a/Lib/test/test_codeccallbacks.py b/Lib/test/test_codeccallbacks.py index 1650965a99a7..8ae3b1121025 100644 --- a/Lib/test/test_codeccallbacks.py +++ b/Lib/test/test_codeccallbacks.py @@ -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))