summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-05-09 23:47:07 (GMT)
committerGuido van Rossum <guido@python.org>2007-05-09 23:47:07 (GMT)
commit5c4501af57b22bb2f651b49a4bc49ccc5045c686 (patch)
treeef1d4e0abea413a7666a89ef6d1aee40c5edccb3 /Lib
parent62b887156134a2f62011dc5603f8646e5ffbe501 (diff)
downloadcpython-5c4501af57b22bb2f651b49a4bc49ccc5045c686.zip
cpython-5c4501af57b22bb2f651b49a4bc49ccc5045c686.tar.gz
cpython-5c4501af57b22bb2f651b49a4bc49ccc5045c686.tar.bz2
Don't insist on cStringIO.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_codecs.py39
1 files changed, 20 insertions, 19 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index 69f941d..9634099 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -1,7 +1,8 @@
from test import test_support
import unittest
import codecs
-import sys, cStringIO, _testcapi
+import sys, _testcapi
+from StringIO import StringIO
class Queue(object):
"""
@@ -103,7 +104,7 @@ class ReadTest(unittest.TestCase, MixInCheckStateHandling):
def test_readline(self):
def getreader(input):
- stream = cStringIO.StringIO(input.encode(self.encoding))
+ stream = StringIO(input.encode(self.encoding))
return codecs.getreader(self.encoding)(stream)
def readalllines(input, keepends=True, size=None):
@@ -215,7 +216,7 @@ class ReadTest(unittest.TestCase, MixInCheckStateHandling):
' break\r\n',
' \r\n',
]
- stream = cStringIO.StringIO("".join(s).encode(self.encoding))
+ stream = StringIO("".join(s).encode(self.encoding))
reader = codecs.getreader(self.encoding)(stream)
for (i, line) in enumerate(reader):
self.assertEqual(line, s[i])
@@ -253,7 +254,7 @@ class ReadTest(unittest.TestCase, MixInCheckStateHandling):
s3 = "next line.\r\n"
s = (s1+s2+s3).encode(self.encoding)
- stream = cStringIO.StringIO(s)
+ stream = StringIO(s)
reader = codecs.getreader(self.encoding)(stream)
self.assertEqual(reader.readline(), s1)
self.assertEqual(reader.readline(), s2)
@@ -268,7 +269,7 @@ class ReadTest(unittest.TestCase, MixInCheckStateHandling):
s5 = "againokay.\r\n"
s = (s1+s2+s3+s4+s5).encode(self.encoding)
- stream = cStringIO.StringIO(s)
+ stream = StringIO(s)
reader = codecs.getreader(self.encoding)(stream)
self.assertEqual(reader.readline(), s1)
self.assertEqual(reader.readline(), s2)
@@ -286,7 +287,7 @@ class UTF16Test(ReadTest):
def test_only_one_bom(self):
_,_,reader,writer = codecs.lookup(self.encoding)
# encode some stream
- s = cStringIO.StringIO()
+ s = StringIO()
f = writer(s)
f.write("spam")
f.write("spam")
@@ -294,16 +295,16 @@ class UTF16Test(ReadTest):
# check whether there is exactly one BOM in it
self.assert_(d == self.spamle or d == self.spambe)
# try to read it back
- s = cStringIO.StringIO(d)
+ s = StringIO(d)
f = reader(s)
self.assertEquals(f.read(), "spamspam")
def test_badbom(self):
- s = cStringIO.StringIO(b"\xff\xff")
+ s = StringIO(b"\xff\xff")
f = codecs.getreader(self.encoding)(s)
self.assertRaises(UnicodeError, f.read)
- s = cStringIO.StringIO(b"\xff\xff\xff\xff")
+ s = StringIO(b"\xff\xff\xff\xff")
f = codecs.getreader(self.encoding)(s)
self.assertRaises(UnicodeError, f.read)
@@ -492,7 +493,7 @@ class EscapeDecodeTest(unittest.TestCase):
class RecodingTest(unittest.TestCase):
def test_recoding(self):
- f = cStringIO.StringIO()
+ f = StringIO()
f2 = codecs.EncodedFile(f, "unicode_internal", "utf-8")
f2.write("a")
f2.close()
@@ -856,7 +857,7 @@ class IDNACodecTest(unittest.TestCase):
self.assertEquals("pyth\xf6n.org.".encode("idna"), "xn--pythn-mua.org.")
def test_stream(self):
- r = codecs.getreader("idna")(cStringIO.StringIO(b"abc"))
+ r = codecs.getreader("idna")(StringIO(b"abc"))
r.read(3)
self.assertEquals(r.read(), "")
@@ -964,7 +965,7 @@ class StreamReaderTest(unittest.TestCase):
def setUp(self):
self.reader = codecs.getreader('utf-8')
- self.stream = cStringIO.StringIO(b'\xed\x95\x9c\n\xea\xb8\x80')
+ self.stream = StringIO(b'\xed\x95\x9c\n\xea\xb8\x80')
def test_readlines(self):
f = self.reader(self.stream)
@@ -973,11 +974,11 @@ class StreamReaderTest(unittest.TestCase):
class EncodedFileTest(unittest.TestCase):
def test_basic(self):
- f = cStringIO.StringIO(b'\xed\x95\x9c\n\xea\xb8\x80')
+ f = StringIO(b'\xed\x95\x9c\n\xea\xb8\x80')
ef = codecs.EncodedFile(f, 'utf-16-le', 'utf-8')
self.assertEquals(ef.read(), b'\\\xd5\n\x00\x00\xae')
- f = cStringIO.StringIO()
+ f = StringIO()
ef = codecs.EncodedFile(f, 'utf-8', 'latin1')
ef.write(b'\xc3\xbc')
self.assertEquals(f.getvalue(), b'\xfc')
@@ -986,14 +987,14 @@ class Str2StrTest(unittest.TestCase):
def test_read(self):
sin = "\x80".encode("base64_codec")
- reader = codecs.getreader("base64_codec")(cStringIO.StringIO(sin))
+ reader = codecs.getreader("base64_codec")(StringIO(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")(cStringIO.StringIO(sin))
+ reader = codecs.getreader("base64_codec")(StringIO(sin))
sout = reader.readline()
self.assertEqual(sout, "\x80")
self.assert_(isinstance(sout, str))
@@ -1250,7 +1251,7 @@ class BasicUnicodeTest(unittest.TestCase, MixInCheckStateHandling):
continue
if encoding in broken_unicode_with_streams:
continue
- reader = codecs.getreader(encoding)(cStringIO.StringIO(s.encode(encoding)))
+ reader = codecs.getreader(encoding)(StringIO(s.encode(encoding)))
for t in range(5):
# Test that calling seek resets the internal codec state and buffers
reader.seek(0, 0)
@@ -1327,12 +1328,12 @@ class CharmapTest(unittest.TestCase):
class WithStmtTest(unittest.TestCase):
def test_encodedfile(self):
- f = cStringIO.StringIO(b"\xc3\xbc")
+ f = StringIO(b"\xc3\xbc")
with codecs.EncodedFile(f, "latin-1", "utf-8") as ef:
self.assertEquals(ef.read(), b"\xfc")
def test_streamreaderwriter(self):
- f = cStringIO.StringIO(b"\xc3\xbc")
+ f = StringIO(b"\xc3\xbc")
info = codecs.lookup("utf-8")
with codecs.StreamReaderWriter(f, info.streamreader,
info.streamwriter, 'strict') as srw: