@@ -4203,7 +4203,7 @@ def check_decode_strings(self, errors):
42034203 errmsg = f"decode error: pos={ error_pos } "
42044204 self .assertEqual (str (cm .exception ), errmsg )
42054205 else :
4206- if errors == ("strict" , "surrogateescape" ):
4206+ if errors in ("strict" , "surrogateescape" ):
42074207 decoded = self .decode_locale_surrogateescape (encoded )
42084208 self .assertEqual (decoded , expected )
42094209
@@ -4233,6 +4233,24 @@ def test_decode_unsupported_error_handler(self):
42334233 self .decode_locale (b'' , 'backslashreplace' )
42344234 self .assertEqual (str (cm .exception ), 'unsupported error handler' )
42354235
4236+ def test_memory_error (self ):
4237+ # Make sure that MemoryError is handled properly
4238+ with self .assertRaises (MemoryError ):
4239+ with support .inject_memory_error_cm ():
4240+ self .decode_locale (b'short ascii string' , 0 , 'strict' )
4241+
4242+ with self .assertRaises (MemoryError ):
4243+ with support .inject_memory_error_cm ():
4244+ self .decode_locale_surrogateescape (b'short ascii string' )
4245+
4246+ with self .assertRaises (MemoryError ):
4247+ with support .inject_memory_error_cm ():
4248+ self .encode_locale ('short string' , 0 , 'strict' )
4249+
4250+ with self .assertRaises (MemoryError ):
4251+ with support .inject_memory_error_cm ():
4252+ self .encode_locale_surrogateescape ('short string' )
4253+
42364254
42374255class Rot13Test (unittest .TestCase ):
42384256 """Test the educational ROT-13 codec."""
0 commit comments