summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorAlexandre Vassalotti <alexandre@peadrop.com>2008-06-11 22:58:36 (GMT)
committerAlexandre Vassalotti <alexandre@peadrop.com>2008-06-11 22:58:36 (GMT)
commit794652dd064590d7188d93d9bf524ae9e1558386 (patch)
treea0011f0cfa8fef8fcda771eceadad50e1f95b42d /Lib/test
parent502d89ed1518687861563293cb761d268321fa4a (diff)
downloadcpython-794652dd064590d7188d93d9bf524ae9e1558386.zip
cpython-794652dd064590d7188d93d9bf524ae9e1558386.tar.gz
cpython-794652dd064590d7188d93d9bf524ae9e1558386.tar.bz2
Issue 2918: Merge StringIO and cStringIO.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_memoryio.py10
-rw-r--r--Lib/test/test_minidom.py3
-rw-r--r--Lib/test/test_uu.py34
3 files changed, 38 insertions, 9 deletions
diff --git a/Lib/test/test_memoryio.py b/Lib/test/test_memoryio.py
index 2d91cbd..d1745bc 100644
--- a/Lib/test/test_memoryio.py
+++ b/Lib/test/test_memoryio.py
@@ -10,7 +10,7 @@ import io
import sys
try:
- import _bytesio
+ import _bytesio, _stringio
has_c_implementation = True
except ImportError:
has_c_implementation = False
@@ -373,7 +373,7 @@ class PyBytesIOTest(MemoryTestMixin, unittest.TestCase):
class PyStringIOTest(MemoryTestMixin, unittest.TestCase):
buftype = str
- ioclass = io.StringIO
+ ioclass = io._StringIO
EOF = ""
def test_relative_seek(self):
@@ -404,10 +404,14 @@ if has_c_implementation:
class CBytesIOTest(PyBytesIOTest):
ioclass = io.BytesIO
+ class CStringIOTest(PyStringIOTest):
+ ioclass = io.StringIO
+
+
def test_main():
tests = [PyBytesIOTest, PyStringIOTest]
if has_c_implementation:
- tests.extend([CBytesIOTest])
+ tests.extend([CBytesIOTest, CStringIOTest])
support.run_unittest(*tests)
if __name__ == '__main__':
diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py
index ca1f836..c4c568f 100644
--- a/Lib/test/test_minidom.py
+++ b/Lib/test/test_minidom.py
@@ -3,7 +3,6 @@
import os
import sys
import pickle
-from io import StringIO
from test.support import verbose, run_unittest, TestSkipped
import unittest
@@ -80,7 +79,7 @@ class MinidomTest(unittest.TestCase):
self.confirm(t == s, "looking for %s, found %s" % (repr(s), repr(t)))
def testParseFromFile(self):
- dom = parse(StringIO(open(tstfile).read()))
+ dom = parse(open(tstfile))
dom.unlink()
self.confirm(isinstance(dom, Document))
diff --git a/Lib/test/test_uu.py b/Lib/test/test_uu.py
index 02d0171..d2b6e73 100644
--- a/Lib/test/test_uu.py
+++ b/Lib/test/test_uu.py
@@ -17,6 +17,32 @@ encodedtext = b"""\
M5&AE('-M;V]T:\"US8V%L960@<'ET:&]N(&-R97!T(&]V97(@=&AE('-L965P
(:6YG(&1O9PH """
+# Stolen from io.py
+class FakeIO(io.TextIOWrapper):
+ """Text I/O implementation using an in-memory buffer.
+
+ Can be a used as a drop-in replacement for sys.stdin and sys.stdout.
+ """
+
+ # XXX This is really slow, but fully functional
+
+ def __init__(self, initial_value="", encoding="utf-8",
+ errors="strict", newline="\n"):
+ super(FakeIO, self).__init__(io.BytesIO(),
+ encoding=encoding,
+ errors=errors,
+ newline=newline)
+ if initial_value:
+ if not isinstance(initial_value, str):
+ initial_value = str(initial_value)
+ self.write(initial_value)
+ self.seek(0)
+
+ def getvalue(self):
+ self.flush()
+ return self.buffer.getvalue().decode(self._encoding, self._errors)
+
+
def encodedtextwrapped(mode, filename):
return (bytes("begin %03o %s\n" % (mode, filename), "ascii") +
encodedtext + b"\n \nend\n")
@@ -76,15 +102,15 @@ class UUStdIOTest(unittest.TestCase):
sys.stdout = self.stdout
def test_encode(self):
- sys.stdin = io.StringIO(plaintext.decode("ascii"))
- sys.stdout = io.StringIO()
+ sys.stdin = FakeIO(plaintext.decode("ascii"))
+ sys.stdout = FakeIO()
uu.encode("-", "-", "t1", 0o666)
self.assertEqual(sys.stdout.getvalue(),
encodedtextwrapped(0o666, "t1").decode("ascii"))
def test_decode(self):
- sys.stdin = io.StringIO(encodedtextwrapped(0o666, "t1").decode("ascii"))
- sys.stdout = io.StringIO()
+ sys.stdin = FakeIO(encodedtextwrapped(0o666, "t1").decode("ascii"))
+ sys.stdout = FakeIO()
uu.decode("-", "-")
stdout = sys.stdout
sys.stdout = self.stdout