(self)
| 645 | encode('a', NULL, 'strict') |
| 646 | |
| 647 | def test_codec_decode(self): |
| 648 | decode = _testcapi.codec_decode |
| 649 | |
| 650 | s = 'a\xa1\u4f60\U0001f600' |
| 651 | b = s.encode() |
| 652 | |
| 653 | self.assertEqual(decode(b, 'utf-8', 'strict'), s) |
| 654 | self.assertEqual(decode(b, 'utf-8', NULL), s) |
| 655 | self.assertEqual(decode(b, 'latin1', 'strict'), b.decode('latin1')) |
| 656 | self.assertRaises(UnicodeDecodeError, decode, b, 'ascii', 'strict') |
| 657 | self.assertRaises(UnicodeDecodeError, decode, b, 'ascii', NULL) |
| 658 | self.assertEqual(decode(b, 'ascii', 'replace'), 'a' + '\ufffd'*9) |
| 659 | |
| 660 | # _codecs.decode() only reports an unknown error handling name when |
| 661 | # the corresponding error handling function is used; this difers |
| 662 | # from PyUnicode_Decode() which checks that both the encoding and |
| 663 | # the error handling name are recognized before even attempting to |
| 664 | # call the decoder. |
| 665 | self.assertEqual(decode(b'', 'utf-8', 'unknown-error-handler'), '') |
| 666 | self.assertEqual(decode(b'a', 'utf-8', 'unknown-error-handler'), 'a') |
| 667 | |
| 668 | self.assertRaises(TypeError, decode, NULL, 'ascii', 'strict') |
| 669 | with self.assertRaisesRegex(TypeError, BAD_ARGUMENT): |
| 670 | decode(b, NULL, 'strict') |
| 671 | |
| 672 | def test_codec_encoder(self): |
| 673 | codec_encoder = _testcapi.codec_encoder |
nothing calls this directly
no test coverage detected