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

Method test_charmapencode

Lib/test/test_codeccallbacks.py:206–225  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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):

Callers

nothing calls this directly

Calls 4

ordFunction · 0.85
upperMethod · 0.45
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected