(self)
| 204 | "utf-8", "test.relaxedutf8") |
| 205 | |
| 206 | def test_charmapencode(self): |
| 207 | # For charmap encodings the replacement string will be |
| 208 | # mapped through the encoding again. This means, that |
| 209 | # to be able to use e.g. the "replace" handler, the |
| 210 | # charmap has to have a mapping for "?". |
| 211 | charmap = dict((ord(c), bytes(2*c.upper(), 'ascii')) for c in "abcdefgh") |
| 212 | sin = "abc" |
| 213 | sout = b"AABBCC" |
| 214 | self.assertEqual(codecs.charmap_encode(sin, "strict", charmap)[0], sout) |
| 215 | |
| 216 | sin = "abcA" |
| 217 | self.assertRaises(UnicodeError, codecs.charmap_encode, sin, "strict", charmap) |
| 218 | |
| 219 | charmap[ord("?")] = b"XYZ" |
| 220 | sin = "abcDEF" |
| 221 | sout = b"AABBCCXYZXYZXYZ" |
| 222 | self.assertEqual(codecs.charmap_encode(sin, "replace", charmap)[0], sout) |
| 223 | |
| 224 | charmap[ord("?")] = "XYZ" # wrong type in mapping |
| 225 | self.assertRaises(TypeError, codecs.charmap_encode, sin, "replace", charmap) |
| 226 | |
| 227 | def test_callbacks(self): |
| 228 | def handler1(exc): |
nothing calls this directly
no test coverage detected