@@ -1235,6 +1235,31 @@ class FakeUnicodeError(Exception):
1235
1235
with self .assertRaises ((TypeError , FakeUnicodeError )):
1236
1236
handler (FakeUnicodeError ())
1237
1237
1238
+ def test_reject_unregister_native_error_policy (self ):
1239
+ for policy in [
1240
+ 'strict' , 'ignore' , 'replace' , 'backslashreplace' , 'namereplace' ,
1241
+ 'xmlcharrefreplace' , 'surrogateescape' , 'surrogatepass' ,
1242
+ ]:
1243
+ with self .subTest (f'reject native { policy !r} un-registration' ):
1244
+ self .assertRaises (ValueError , codecs .unregister_error , policy )
1245
+
1246
+ def test_unregister_custom_error_policy (self ):
1247
+ def custom_handler (exc ):
1248
+ raise exc
1249
+
1250
+ custom_name = f'test.test_unregister_error.custom.{ id (self )} '
1251
+ self .assertRaises (LookupError , codecs .lookup_error , custom_name )
1252
+ codecs .register_error (custom_name , custom_handler )
1253
+ self .assertIs (codecs .lookup_error (custom_name ), custom_handler )
1254
+ self .assertTrue (codecs .unregister_error (custom_name ))
1255
+ self .assertRaises (LookupError , codecs .lookup_error , custom_name )
1256
+
1257
+ def test_unregister_custom_unknown_error_policy (self ):
1258
+ unknown_name = f'test.test_unregister_error.custom.{ id (self )} .unknown'
1259
+ self .assertRaises (LookupError , codecs .lookup_error , unknown_name )
1260
+ self .assertFalse (codecs .unregister_error (unknown_name ))
1261
+ self .assertRaises (LookupError , codecs .lookup_error , unknown_name )
1262
+
1238
1263
1239
1264
if __name__ == "__main__" :
1240
1265
unittest .main ()
0 commit comments