diff options
author | Bénédikt Tran <10796600+picnixz@users.noreply.github.com> | 2024-09-29 00:25:23 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-29 00:25:23 (GMT) |
commit | c00964ecd508ba6ae43498017d5a3873844a058a (patch) | |
tree | 5a31d8510a4e248d98bc60f473b6b95116263f21 /Lib/test/test_codeccallbacks.py | |
parent | 04c837d9d8a474777ef9c1412fbba14f0682366c (diff) | |
download | cpython-c00964ecd508ba6ae43498017d5a3873844a058a.zip cpython-c00964ecd508ba6ae43498017d5a3873844a058a.tar.gz cpython-c00964ecd508ba6ae43498017d5a3873844a058a.tar.bz2 |
gh-124665: Add `_PyCodec_UnregisterError` and `_codecs._unregister_error` (#124677)
Diffstat (limited to 'Lib/test/test_codeccallbacks.py')
-rw-r--r-- | Lib/test/test_codeccallbacks.py | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/Lib/test/test_codeccallbacks.py b/Lib/test/test_codeccallbacks.py index 4991330..86e5e5c 100644 --- a/Lib/test/test_codeccallbacks.py +++ b/Lib/test/test_codeccallbacks.py @@ -1,3 +1,4 @@ +from _codecs import _unregister_error as _codecs_unregister_error import codecs import html.entities import itertools @@ -1210,7 +1211,6 @@ class CodecCallbackTest(unittest.TestCase): '\ufffd\x00\x00' ) - def test_fake_error_class(self): handlers = [ codecs.strict_errors, @@ -1235,6 +1235,31 @@ class CodecCallbackTest(unittest.TestCase): with self.assertRaises((TypeError, FakeUnicodeError)): handler(FakeUnicodeError()) + def test_reject_unregister_builtin_error_handler(self): + for name in [ + 'strict', 'ignore', 'replace', 'backslashreplace', 'namereplace', + 'xmlcharrefreplace', 'surrogateescape', 'surrogatepass', + ]: + with self.subTest(name): + self.assertRaises(ValueError, _codecs_unregister_error, name) + + def test_unregister_custom_error_handler(self): + def custom_handler(exc): + raise exc + + custom_name = 'test.test_unregister_custom_error_handler' + self.assertRaises(LookupError, codecs.lookup_error, custom_name) + codecs.register_error(custom_name, custom_handler) + self.assertIs(codecs.lookup_error(custom_name), custom_handler) + self.assertTrue(_codecs_unregister_error(custom_name)) + self.assertRaises(LookupError, codecs.lookup_error, custom_name) + + def test_unregister_custom_unknown_error_handler(self): + unknown_name = 'test.test_unregister_custom_unknown_error_handler' + self.assertRaises(LookupError, codecs.lookup_error, unknown_name) + self.assertFalse(_codecs_unregister_error(unknown_name)) + self.assertRaises(LookupError, codecs.lookup_error, unknown_name) + if __name__ == "__main__": unittest.main() |