diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-05-18 13:08:38 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-05-18 13:08:38 (GMT) |
commit | 14e10a19f783d1f896e74d563fe3ef17e7cd8435 (patch) | |
tree | 6e4149b44193467cc48fb3bbed86ca1f2ce83695 /Lib/test/test_codeccallbacks.py | |
parent | 51dbc9a4ad272d832dfd5265cc3161cbb658aecb (diff) | |
download | cpython-14e10a19f783d1f896e74d563fe3ef17e7cd8435.zip cpython-14e10a19f783d1f896e74d563fe3ef17e7cd8435.tar.gz cpython-14e10a19f783d1f896e74d563fe3ef17e7cd8435.tar.bz2 |
Issue #24102: Fixed exception type checking in standard error handlers.
Diffstat (limited to 'Lib/test/test_codeccallbacks.py')
-rw-r--r-- | Lib/test/test_codeccallbacks.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_codeccallbacks.py b/Lib/test/test_codeccallbacks.py index b9cd9c2..c11affd 100644 --- a/Lib/test/test_codeccallbacks.py +++ b/Lib/test/test_codeccallbacks.py @@ -836,6 +836,26 @@ class CodecCallbackTest(unittest.TestCase): text = u'abc<def>ghi'*n text.translate(charmap) + def test_fake_error_class(self): + handlers = [ + codecs.strict_errors, + codecs.ignore_errors, + codecs.replace_errors, + codecs.backslashreplace_errors, + codecs.xmlcharrefreplace_errors, + ] + for cls in UnicodeEncodeError, UnicodeDecodeError, UnicodeTranslateError: + class FakeUnicodeError(str): + __class__ = cls + for handler in handlers: + self.assertRaises(TypeError, handler, FakeUnicodeError()) + class FakeUnicodeError(Exception): + __class__ = cls + for handler in handlers: + with self.assertRaises((TypeError, FakeUnicodeError)): + handler(FakeUnicodeError()) + + def test_main(): test.test_support.run_unittest(CodecCallbackTest) |