summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2006-10-29 23:02:27 (GMT)
committerWalter Dörwald <walter@livinglogic.de>2006-10-29 23:02:27 (GMT)
commit98c70acf473781b653ab145b553320c5e0c7351b (patch)
tree3ce0204906f3dbe10b52f949723b561009df375d
parent92911bfc6a7d501569031cd3e2b4ecc4ac273bd1 (diff)
downloadcpython-98c70acf473781b653ab145b553320c5e0c7351b.zip
cpython-98c70acf473781b653ab145b553320c5e0c7351b.tar.gz
cpython-98c70acf473781b653ab145b553320c5e0c7351b.tar.bz2
Add tests for incremental codecs with an errors
argument.
-rw-r--r--Lib/test/test_codecs.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index 5c82d3f..57edd26 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -1064,6 +1064,12 @@ broken_unicode_with_streams = [
]
broken_incremental_coders = broken_unicode_with_streams[:]
+# The following encodings only support "strict" mode
+only_strict_mode = [
+ "idna",
+ "zlib_codec",
+]
+
try:
import bz2
except ImportError:
@@ -1153,6 +1159,24 @@ class BasicUnicodeTest(unittest.TestCase):
result = u"".join(codecs.iterdecode(codecs.iterencode(u"", encoding), encoding))
self.assertEqual(result, u"")
+ if encoding not in only_strict_mode:
+ # check incremental decoder/encoder with errors argument
+ try:
+ encoder = codecs.getincrementalencoder(encoding)("ignore")
+ cencoder = _testcapi.codec_incrementalencoder(encoding, "ignore")
+ except LookupError: # no IncrementalEncoder
+ pass
+ else:
+ encodedresult = "".join(encoder.encode(c) for c in s)
+ decoder = codecs.getincrementaldecoder(encoding)("ignore")
+ decodedresult = u"".join(decoder.decode(c) for c in encodedresult)
+ self.assertEqual(decodedresult, s, "%r != %r (encoding=%r)" % (decodedresult, s, encoding))
+
+ encodedresult = "".join(cencoder.encode(c) for c in s)
+ cdecoder = _testcapi.codec_incrementaldecoder(encoding, "ignore")
+ decodedresult = u"".join(cdecoder.decode(c) for c in encodedresult)
+ self.assertEqual(decodedresult, s, "%r != %r (encoding=%r)" % (decodedresult, s, encoding))
+
def test_seek(self):
# all codecs should be able to encode these
s = u"%s\n%s\n" % (100*u"abc123", 100*u"def456")