mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Issue #24102: Fixed exception type checking in standard error handlers.
This commit is contained in:
parent
0a29e898cd
commit
ca7fecb038
3 changed files with 43 additions and 24 deletions
|
@ -961,6 +961,29 @@ 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.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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue