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

Method check_encode

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

Source from the content-addressed store, hash-verified

3329 raw.decode, f'cp{cp}', errors)
3330
3331 def check_encode(self, cp, tests):
3332 for text, errors, expected, *rest in tests:
3333 if rest:
3334 altexpected, = rest
3335 else:
3336 altexpected = expected
3337 if expected is not None:
3338 try:
3339 encoded = codecs.code_page_encode(cp, text, errors)
3340 except UnicodeEncodeError as err:
3341 self.fail('Unable to encode %a to "cp%s" with '
3342 'errors=%r: %s' % (text, cp, errors, err))
3343 self.assertEqual(encoded[0], expected,
3344 '%a.encode("cp%s", %r)=%a != %a'
3345 % (text, cp, errors, encoded[0], expected))
3346 self.assertEqual(encoded[1], len(text))
3347
3348 encoded = text.encode(f'cp{cp}', errors)
3349 self.assertEqual(encoded, altexpected,
3350 '%a.encode("cp%s", %r)=%a != %a'
3351 % (text, cp, errors, encoded, altexpected))
3352 else:
3353 self.assertRaises(UnicodeEncodeError,
3354 codecs.code_page_encode, cp, text, errors)
3355 self.assertRaises(UnicodeEncodeError,
3356 text.encode, f'cp{cp}', errors)
3357
3358 def test_cp932(self):
3359 self.check_encode(932, (

Callers 6

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

Calls 4

failMethod · 0.45
assertEqualMethod · 0.45
encodeMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected