From: Walter Dörwald Date: Sun, 29 Oct 2006 23:02:27 +0000 (+0000) Subject: Add tests for incremental codecs with an errors X-Git-Tag: v2.6a1~2474 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=98c70acf473781b653ab145b553320c5e0c7351b;p=python Add tests for incremental codecs with an errors argument. --- diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index 5c82d3f8be..57edd26e7e 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")