Fix io.StringIO: String are stored encoded (using "unicode-internal" as the

encoding) which makes the buffer mutable. Strings are encoded on the way in
and decoded on the way out.

Use io.StringIO in test_codecs.py.

Fix the base64_codec test in test_codecs.py.
This commit is contained in:
Walter Dörwald 2007-05-16 12:47:53 +00:00
parent c9e363c2eb
commit 9d2ac22721
2 changed files with 33 additions and 19 deletions

View file

@ -2,7 +2,6 @@ from test import test_support
import unittest
import codecs
import sys, _testcapi, io
from StringIO import StringIO
class Queue(object):
"""
@ -493,7 +492,7 @@ class EscapeDecodeTest(unittest.TestCase):
class RecodingTest(unittest.TestCase):
def test_recoding(self):
f = StringIO()
f = io.StringIO()
f2 = codecs.EncodedFile(f, "unicode_internal", "utf-8")
f2.write("a")
f2.close()
@ -991,14 +990,14 @@ class Str2StrTest(unittest.TestCase):
def test_read(self):
sin = "\x80".encode("base64_codec")
reader = codecs.getreader("base64_codec")(StringIO(sin))
reader = codecs.getreader("base64_codec")(io.BytesIO(sin))
sout = reader.read()
self.assertEqual(sout, "\x80")
self.assert_(isinstance(sout, str))
def test_readline(self):
sin = "\x80".encode("base64_codec")
reader = codecs.getreader("base64_codec")(StringIO(sin))
reader = codecs.getreader("base64_codec")(io.BytesIO(sin))
sout = reader.readline()
self.assertEqual(sout, "\x80")
self.assert_(isinstance(sout, str))