[Python-checkins] python/dist/src/Lib/test test_codecs.py, 1.26, 1.27
doerwalter@users.sourceforge.net
doerwalter at users.sourceforge.net
Thu Oct 6 22:30:00 CEST 2005
Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6122/Lib/test
Modified Files:
test_codecs.py
Log Message:
Part of SF patch #1313939: Speedup charmap decoding by extending
PyUnicode_DecodeCharmap() the accept a unicode string as the mapping
argument which is used as a mapping table.
This code isn't used by any of the codecs yet.
Index: test_codecs.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_codecs.py,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- test_codecs.py 30 Aug 2005 10:23:13 -0000 1.26
+++ test_codecs.py 6 Oct 2005 20:29:57 -0000 1.27
@@ -924,6 +924,40 @@
(chars, size) = codecs.getdecoder(encoding)(bytes)
self.assertEqual(chars, s, "%r != %r (encoding=%r)" % (chars, s, encoding))
+class CharmapTest(unittest.TestCase):
+ def test_decode_with_string_map(self):
+ self.assertEquals(
+ codecs.charmap_decode("\x00\x01\x02", "strict", u"abc"),
+ (u"abc", 3)
+ )
+
+ self.assertEquals(
+ codecs.charmap_decode("\x00\x01\x02", "replace", u"ab"),
+ (u"ab\ufffd", 3)
+ )
+
+ self.assertEquals(
+ codecs.charmap_decode("\x00\x01\x02", "replace", u"ab\ufffe"),
+ (u"ab\ufffd", 3)
+ )
+
+ self.assertEquals(
+ codecs.charmap_decode("\x00\x01\x02", "ignore", u"ab"),
+ (u"ab", 3)
+ )
+
+ self.assertEquals(
+ codecs.charmap_decode("\x00\x01\x02", "ignore", u"ab\ufffe"),
+ (u"ab", 3)
+ )
+
+ allbytes = "".join(chr(i) for i in xrange(256))
+ self.assertEquals(
+ codecs.charmap_decode(allbytes, "ignore", u""),
+ (u"", len(allbytes))
+ )
+
+
def test_main():
test_support.run_unittest(
UTF16Test,
@@ -940,7 +974,8 @@
StreamReaderTest,
Str2StrTest,
BasicUnicodeTest,
- BasicStrTest
+ BasicStrTest,
+ CharmapTest
)
More information about the Python-checkins
mailing list