MCPcopy Index your code
hub / github.com/python/cpython / check_decode_strings

Method check_decode_strings

Lib/test/test_codecs.py:3778–3810  ·  view source on GitHub ↗
(self, errors)

Source from the content-addressed store, hash-verified

3776 return _testinternalcapi.DecodeLocaleEx(encoded, 0, errors)
3777
3778 def check_decode_strings(self, errors):
3779 is_utf8 = (self.ENCODING == "utf-8")
3780 if is_utf8:
3781 encode_errors = 'surrogateescape'
3782 else:
3783 encode_errors = 'strict'
3784
3785 strings = list(self.BYTES_STRINGS)
3786 for text in self.STRINGS:
3787 try:
3788 encoded = text.encode(self.ENCODING, encode_errors)
3789 if encoded not in strings:
3790 strings.append(encoded)
3791 except UnicodeEncodeError:
3792 encoded = None
3793
3794 if is_utf8:
3795 encoded2 = text.encode(self.ENCODING, 'surrogatepass')
3796 if encoded2 != encoded:
3797 strings.append(encoded2)
3798
3799 for encoded in strings:
3800 with self.subTest(encoded=encoded):
3801 try:
3802 expected = encoded.decode(self.ENCODING, errors)
3803 except UnicodeDecodeError:
3804 with self.assertRaises(RuntimeError) as cm:
3805 self.decode(encoded, errors)
3806 errmsg = str(cm.exception)
3807 self.assertStartsWith(errmsg, "decode error: ")
3808 else:
3809 decoded = self.decode(encoded, errors)
3810 self.assertEqual(decoded, expected)
3811
3812 def test_decode_strict(self):
3813 self.check_decode_strings("strict")

Callers 3

test_decode_strictMethod · 0.95

Calls 9

decodeMethod · 0.95
listClass · 0.85
strFunction · 0.85
assertStartsWithMethod · 0.80
encodeMethod · 0.45
appendMethod · 0.45
subTestMethod · 0.45
assertRaisesMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected