summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_uu.py
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/test_uu.py
parent502d89ed1518687861563293cb761d268321fa4a (diff)
downloadcpython-794652dd064590d7188d93d9bf524ae9e1558386.zip
cpython-794652dd064590d7188d93d9bf524ae9e1558386.tar.gz
cpython-794652dd064590d7188d93d9bf524ae9e1558386.tar.bz2
Issue 2918: Merge StringIO and cStringIO.
Diffstat (limited to 'Lib/test/test_uu.py')
-rw-r--r--Lib/test/test_uu.py34
1 files changed, 30 insertions, 4 deletions
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