summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_codecs.py
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2005-10-06 20:29:57 (GMT)
committerWalter Dörwald <walter@livinglogic.de>2005-10-06 20:29:57 (GMT)
commitd1c1e10f70212464415fdf2ab0bed4b5d32fdf32 (patch)
tree82db5a596a24d75e3caf0cd8054e2a68fe837332 /Lib/test/test_codecs.py
parent331649acc7479f6e10cf6f6d01118d90f58ae600 (diff)
downloadcpython-d1c1e10f70212464415fdf2ab0bed4b5d32fdf32.zip
cpython-d1c1e10f70212464415fdf2ab0bed4b5d32fdf32.tar.gz
cpython-d1c1e10f70212464415fdf2ab0bed4b5d32fdf32.tar.bz2
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.
Diffstat (limited to 'Lib/test/test_codecs.py')
-rw-r--r--Lib/test/test_codecs.py37
1 files changed, 36 insertions, 1 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index a4d58c6..74ad83b 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -924,6 +924,40 @@ class BasicStrTest(unittest.TestCase):
(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 @@ def test_main():
StreamReaderTest,
Str2StrTest,
BasicUnicodeTest,
- BasicStrTest
+ BasicStrTest,
+ CharmapTest
)