summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2009-10-26 08:24:14 (GMT)
committerR. David Murray <rdmurray@bitdance.com>2009-10-26 08:24:14 (GMT)
commit0548ce088de6a382d0a4ea8789f106696176937d (patch)
treeb586308c4eae984662c6e13691f011b579a79d68 /Lib/test
parentcc16d16adde974a14be962cf9a6a5665f90ff664 (diff)
downloadcpython-0548ce088de6a382d0a4ea8789f106696176937d.zip
cpython-0548ce088de6a382d0a4ea8789f106696176937d.tar.gz
cpython-0548ce088de6a382d0a4ea8789f106696176937d.tar.bz2
Make the XMLRCP CGIHandlerTestCase pass like it did before the change of
the test to use StringIO instead of a temp file. There may or may not be an underlying problem here, so this patch makes the test function as originally designed until a determination can be made as to whether or not there is an underlying bug here. See issue 7165 for discussion.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_xmlrpc.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py
index 1542cd4..bd00ab1 100644
--- a/Lib/test/test_xmlrpc.py
+++ b/Lib/test/test_xmlrpc.py
@@ -10,6 +10,8 @@ import http.client
import socket
import os
import re
+import io
+import contextlib
from test import support
alist = [{'astring': 'foo@bar.baz.spam',
@@ -713,6 +715,21 @@ class FailingServerTestCase(unittest.TestCase):
else:
self.fail('ProtocolError not raised')
+
+@contextlib.contextmanager
+def captured_stdout(encoding='utf-8'):
+ """A variation on support.captured_stdout() which gives a text stream
+ having a `buffer` attribute.
+ """
+ import io
+ orig_stdout = sys.stdout
+ sys.stdout = io.TextIOWrapper(io.BytesIO(), encoding=encoding)
+ try:
+ yield sys.stdout
+ finally:
+ sys.stdout = orig_stdout
+
+
class CGIHandlerTestCase(unittest.TestCase):
def setUp(self):
self.cgi = xmlrpc.server.CGIXMLRPCRequestHandler()
@@ -725,7 +742,7 @@ class CGIHandlerTestCase(unittest.TestCase):
env['REQUEST_METHOD'] = 'GET'
# if the method is GET and no request_text is given, it runs handle_get
# get sysout output
- with support.captured_stdout() as data_out:
+ with captured_stdout(encoding=self.cgi.encoding) as data_out:
self.cgi.handle_request()
# parse Status header
@@ -754,7 +771,7 @@ class CGIHandlerTestCase(unittest.TestCase):
"""
with support.EnvironmentVarGuard() as env, \
- support.captured_stdout() as data_out, \
+ captured_stdout(encoding=self.cgi.encoding) as data_out, \
support.captured_stdin() as data_in:
data_in.write(data)
data_in.seek(0)