diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-05-18 16:10:40 +0300 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-05-18 16:10:40 +0300 |
commit | c0937f79ec12fb46938416004fd1fd002ae75a12 (patch) | |
tree | 388599c3c5ebed30075666b789503ea845b20cda /Lib/test/test_codeccallbacks.py | |
parent | f4e6030542eaf684a384f27a741d877c05b17b33 (diff) | |
parent | ca7fecb0389466ef1b995e69c92ea076d4c52498 (diff) | |
download | cpython-git-c0937f79ec12fb46938416004fd1fd002ae75a12.tar.gz |
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 | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_codeccallbacks.py b/Lib/test/test_codeccallbacks.py index 4cfb88e99b..ee1e28a763 100644 --- a/Lib/test/test_codeccallbacks.py +++ b/Lib/test/test_codeccallbacks.py @@ -1046,6 +1046,30 @@ class CodecCallbackTest(unittest.TestCase): with self.assertRaises(TypeError): data.decode(encoding, "test.replacing") + def test_fake_error_class(self): + handlers = [ + codecs.strict_errors, + codecs.ignore_errors, + codecs.replace_errors, + codecs.backslashreplace_errors, + codecs.namereplace_errors, + codecs.xmlcharrefreplace_errors, + codecs.lookup_error('surrogateescape'), + codecs.lookup_error('surrogatepass'), + ] + for cls in UnicodeEncodeError, UnicodeDecodeError, UnicodeTranslateError: + class FakeUnicodeError(str): + __class__ = cls + for handler in handlers: + with self.subTest(handler=handler, error_class=cls): + self.assertRaises(TypeError, handler, FakeUnicodeError()) + class FakeUnicodeError(Exception): + __class__ = cls + for handler in handlers: + with self.subTest(handler=handler, error_class=cls): + with self.assertRaises((TypeError, FakeUnicodeError)): + handler(FakeUnicodeError()) + if __name__ == "__main__": unittest.main() |