summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-05-18 13:08:52 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-05-18 13:08:52 (GMT)
commitca7fecb0389466ef1b995e69c92ea076d4c52498 (patch)
tree87e5a67d26512ef1936ed765b14fd3e42d2ec75d /Lib
parent0a29e898cd9f8ca49008baba8e739422fd9276a8 (diff)
downloadcpython-ca7fecb0389466ef1b995e69c92ea076d4c52498.zip
cpython-ca7fecb0389466ef1b995e69c92ea076d4c52498.tar.gz
cpython-ca7fecb0389466ef1b995e69c92ea076d4c52498.tar.bz2
Issue #24102: Fixed exception type checking in standard error handlers.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_codeccallbacks.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_codeccallbacks.py b/Lib/test/test_codeccallbacks.py
index cacdfae..1327f11 100644
--- a/Lib/test/test_codeccallbacks.py
+++ b/Lib/test/test_codeccallbacks.py
@@ -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()