mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Add a test case that checks that the proper exception is raises
when the replacement from an encoding error callback is itself unencodable.
This commit is contained in:
parent
5ccaf8f129
commit
9ab7dd4d5b
1 changed files with 15 additions and 0 deletions
|
@ -474,6 +474,21 @@ class CodecCallbackTest(unittest.TestCase):
|
||||||
codecs.lookup_error("backslashreplace")
|
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():
|
def test_main():
|
||||||
suite = unittest.TestSuite()
|
suite = unittest.TestSuite()
|
||||||
suite.addTest(unittest.makeSuite(CodecCallbackTest))
|
suite.addTest(unittest.makeSuite(CodecCallbackTest))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue