[Python-checkins] r75710 - python/branches/py3k/Lib/test/test_xmlrpc.py

r.david.murray python-checkins at python.org
Mon Oct 26 09:24:15 CET 2009


Author: r.david.murray
Date: Mon Oct 26 09:24:14 2009
New Revision: 75710

Log:
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.


Modified:
   python/branches/py3k/Lib/test/test_xmlrpc.py

Modified: python/branches/py3k/Lib/test/test_xmlrpc.py
==============================================================================
--- python/branches/py3k/Lib/test/test_xmlrpc.py	(original)
+++ python/branches/py3k/Lib/test/test_xmlrpc.py	Mon Oct 26 09:24:14 2009
@@ -10,6 +10,8 @@
 import socket
 import os
 import re
+import io
+import contextlib
 from test import support
 
 alist = [{'astring': 'foo at bar.baz.spam',
@@ -713,6 +715,21 @@
         else:
             self.fail('ProtocolError not raised')
 
+
+ at 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 @@
             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 @@
         """
 
         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)


More information about the Python-checkins mailing list