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

Method test_decode

Lib/test/test_capi/test_codecs.py:60–76  ·  view source on GitHub ↗

Test PyUnicode_Decode()

(self)

Source from the content-addressed store, hash-verified

58 self.assertRaises(SystemError, fromencodedobject, NULL, 'ascii')
59
60 def test_decode(self):
61 """Test PyUnicode_Decode()"""
62 decode = _testlimitedcapi.unicode_decode
63
64 self.assertEqual(decode(b'[\xe2\x82\xac]', 'utf-8'), '[\u20ac]')
65 self.assertEqual(decode(b'[\xa4]', 'iso8859-15'), '[\u20ac]')
66 self.assertEqual(decode(b'[\xa4]', 'iso8859-15', 'strict'), '[\u20ac]')
67 self.assertRaises(UnicodeDecodeError, decode, b'[\xa4]', 'utf-8')
68 self.assertEqual(decode(b'[\xa4]', 'utf-8', 'replace'), '[\ufffd]')
69
70 self.assertEqual(decode(b'[\xe2\x82\xac]', NULL), '[\u20ac]')
71 self.assertEqual(decode(b'[\xa4]', NULL, 'replace'), '[\ufffd]')
72
73 self.assertRaises(LookupError, decode, b'\xa4', 'foo')
74 self.assertRaises(LookupError, decode, b'\xa4', 'utf-8', 'foo')
75 # TODO: Test PyUnicode_Decode() with NULL as data and
76 # negative size.
77
78 def test_asencodedstring(self):
79 """Test PyUnicode_AsEncodedString()"""

Callers

nothing calls this directly

Calls 3

decodeFunction · 0.50
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected