summaryrefslogtreecommitdiff
path: root/Lib/test/test_codecs.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_codecs.py')
-rw-r--r--Lib/test/test_codecs.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index 00b5d317c4..8c92556e84 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -3290,9 +3290,9 @@ class LocaleCodecTest(unittest.TestCase):
expected = text.encode(self.ENCODING, errors)
except UnicodeEncodeError:
with self.assertRaises(RuntimeError) as cm:
- self.encode(self.SURROGATES)
+ self.encode(text, errors)
errmsg = str(cm.exception)
- self.assertTrue(errmsg.startswith("encode error: pos=0, reason="), errmsg)
+ self.assertRegex(errmsg, r"encode error: pos=[0-9]+, reason=")
else:
encoded = self.encode(text, errors)
self.assertEqual(encoded, expected)
@@ -3315,6 +3315,11 @@ class LocaleCodecTest(unittest.TestCase):
self.check_encode_strings("surrogatepass")
+ def test_encode_unsupported_error_handler(self):
+ with self.assertRaises(ValueError) as cm:
+ self.encode('', 'backslashreplace')
+ self.assertEqual(str(cm.exception), 'unsupported error handler')
+
def decode(self, encoded, errors="strict"):
return _testcapi.DecodeLocaleEx(encoded, 0, errors)
@@ -3370,6 +3375,11 @@ class LocaleCodecTest(unittest.TestCase):
self.check_decode_strings("surrogatepass")
+ def test_decode_unsupported_error_handler(self):
+ with self.assertRaises(ValueError) as cm:
+ self.decode(b'', 'backslashreplace')
+ self.assertEqual(str(cm.exception), 'unsupported error handler')
+
if __name__ == "__main__":
unittest.main()