mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Issue #24102: Fixed exception type checking in standard error handlers.
This commit is contained in:
commit
c0937f79ec
3 changed files with 47 additions and 27 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue