MCPcopy Index your code
hub / github.com/RustPython/RustPython / check_decode_strings

Method check_decode_strings

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

Source from the content-addressed store, hash-verified

3789 return _testinternalcapi.DecodeLocaleEx(encoded, 0, errors)
3790
3791 def check_decode_strings(self, errors):
3792 is_utf8 = (self.ENCODING == "utf-8")
3793 if is_utf8:
3794 encode_errors = 'surrogateescape'
3795 else:
3796 encode_errors = 'strict'
3797
3798 strings = list(self.BYTES_STRINGS)
3799 for text in self.STRINGS:
3800 try:
3801 encoded = text.encode(self.ENCODING, encode_errors)
3802 if encoded not in strings:
3803 strings.append(encoded)
3804 except UnicodeEncodeError:
3805 encoded = None
3806
3807 if is_utf8:
3808 encoded2 = text.encode(self.ENCODING, 'surrogatepass')
3809 if encoded2 != encoded:
3810 strings.append(encoded2)
3811
3812 for encoded in strings:
3813 with self.subTest(encoded=encoded):
3814 try:
3815 expected = encoded.decode(self.ENCODING, errors)
3816 except UnicodeDecodeError:
3817 with self.assertRaises(RuntimeError) as cm:
3818 self.decode(encoded, errors)
3819 errmsg = str(cm.exception)
3820 self.assertStartsWith(errmsg, "decode error: ")
3821 else:
3822 decoded = self.decode(encoded, errors)
3823 self.assertEqual(decoded, expected)
3824
3825 def test_decode_strict(self):
3826 self.check_decode_strings("strict")

Callers 3

test_decode_strictMethod · 0.95

Calls 9

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

Tested by

no test coverage detected