diff options
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) |