summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2002-09-06 17:21:40 (GMT)
committerWalter Dörwald <walter@livinglogic.de>2002-09-06 17:21:40 (GMT)
commit9ab7dd4d5b616cd9486d3a73a5e8320f8c913a1a (patch)
tree79051e790f3d006956634d90c34178cfe1705882 /Lib
parent5ccaf8f1298628bea5a4c7442413f2901914f1bc (diff)
downloadcpython-9ab7dd4d5b616cd9486d3a73a5e8320f8c913a1a.zip
cpython-9ab7dd4d5b616cd9486d3a73a5e8320f8c913a1a.tar.gz
cpython-9ab7dd4d5b616cd9486d3a73a5e8320f8c913a1a.tar.bz2
Add a test case that checks that the proper exception is raises
when the replacement from an encoding error callback is itself unencodable.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_codeccallbacks.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_codeccallbacks.py b/Lib/test/test_codeccallbacks.py
index 1650965..8ae3b11 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))