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

Method check_encode

Lib/test/test_codecs.py:3342–3367  ·  view source on GitHub ↗
(self, cp, tests)

Source from the content-addressed store, hash-verified

3340 raw.decode, f'cp{cp}', errors)
3341
3342 def check_encode(self, cp, tests):
3343 for text, errors, expected, *rest in tests:
3344 if rest:
3345 altexpected, = rest
3346 else:
3347 altexpected = expected
3348 if expected is not None:
3349 try:
3350 encoded = codecs.code_page_encode(cp, text, errors)
3351 except UnicodeEncodeError as err:
3352 self.fail('Unable to encode %a to "cp%s" with '
3353 'errors=%r: %s' % (text, cp, errors, err))
3354 self.assertEqual(encoded[0], expected,
3355 '%a.encode("cp%s", %r)=%a != %a'
3356 % (text, cp, errors, encoded[0], expected))
3357 self.assertEqual(encoded[1], len(text))
3358
3359 encoded = text.encode(f'cp{cp}', errors)
3360 self.assertEqual(encoded, altexpected,
3361 '%a.encode("cp%s", %r)=%a != %a'
3362 % (text, cp, errors, encoded, altexpected))
3363 else:
3364 self.assertRaises(UnicodeEncodeError,
3365 codecs.code_page_encode, cp, text, errors)
3366 self.assertRaises(UnicodeEncodeError,
3367 text.encode, f'cp{cp}', errors)
3368
3369 @unittest.expectedFailure # TODO: RUSTPYTHON
3370 def test_cp932(self):

Callers 6

test_cp932Method · 0.95
test_cp1252Method · 0.95
test_cp708Method · 0.95
test_cp20106Method · 0.95
test_cp_utf7Method · 0.95

Calls 5

lenFunction · 0.85
failMethod · 0.45
assertEqualMethod · 0.45
encodeMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected