summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2006-03-18 14:22:26 (GMT)
committerWalter Dörwald <walter@livinglogic.de>2006-03-18 14:22:26 (GMT)
commit9ae019bf5b92d9ac0ee8bb53829f6b5a16d5fab2 (patch)
treec8af173cf4d8789dc42849d1cbcb642bc79aa8ea /Lib
parentba8e180f3be1cd43954c7e87a45488c46f316e51 (diff)
downloadcpython-9ae019bf5b92d9ac0ee8bb53829f6b5a16d5fab2.zip
cpython-9ae019bf5b92d9ac0ee8bb53829f6b5a16d5fab2.tar.gz
cpython-9ae019bf5b92d9ac0ee8bb53829f6b5a16d5fab2.tar.bz2
Add tests for the C APIs PyCodec_IncrementalEncoder() and
PyCodec_IncrementalDecoder().
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_codecs.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index 913aa91..49b534c 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -1,7 +1,7 @@
from test import test_support
import unittest
import codecs
-import sys, StringIO
+import sys, StringIO, _testcapi
class Queue(object):
"""
@@ -1032,9 +1032,11 @@ class BasicUnicodeTest(unittest.TestCase):
decodedresult += reader.read()
self.assertEqual(decodedresult, s, "%r != %r (encoding=%r)" % (decodedresult, s, encoding))
- # check incremental decoder/encoder and iterencode()/iterdecode()
+ # check incremental decoder/encoder (fetched via the Python
+ # and C API) and iterencode()/iterdecode()
try:
encoder = codecs.getincrementalencoder(encoding)()
+ cencoder = _testcapi.codec_incrementalencoder(encoding)
except LookupError: # no IncrementalEncoder
pass
else:
@@ -1048,6 +1050,16 @@ class BasicUnicodeTest(unittest.TestCase):
decodedresult += decoder.decode(c)
self.assertEqual(decodedresult, s, "%r != %r (encoding=%r)" % (decodedresult, s, encoding))
+ # check C API
+ encodedresult = ""
+ for c in s:
+ encodedresult += cencoder.encode(c)
+ cdecoder = _testcapi.codec_incrementaldecoder(encoding)
+ decodedresult = u""
+ for c in encodedresult:
+ decodedresult += cdecoder.decode(c)
+ self.assertEqual(decodedresult, s, "%r != %r (encoding=%r)" % (decodedresult, s, encoding))
+
# check iterencode()/iterdecode()
result = u"".join(codecs.iterdecode(codecs.iterencode(s, encoding), encoding))
self.assertEqual(result, s, "%r != %r (encoding=%r)" % (result, s, encoding))