[Python-checkins] cpython (merge 3.2 -> default): #7960: merge with 3.2.
ezio.melotti
python-checkins at python.org
Sat May 14 07:44:27 CEST 2011
http://hg.python.org/cpython/rev/7517add4aec9
changeset: 70091:7517add4aec9
parent: 70087:afdc06f2552f
parent: 70090:18a192ae6db9
user: Ezio Melotti <ezio.melotti at gmail.com>
date: Sat May 14 08:44:12 2011 +0300
summary:
#7960: merge with 3.2.
files:
Lib/test/support.py | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/Lib/test/support.py b/Lib/test/support.py
--- a/Lib/test/support.py
+++ b/Lib/test/support.py
@@ -887,14 +887,8 @@
@contextlib.contextmanager
def captured_output(stream_name):
- """Run the 'with' statement body using a StringIO object in place of a
- specific attribute on the sys module.
- Example use (with 'stream_name=stdout')::
-
- with captured_stdout() as s:
- print("hello")
- assert s.getvalue() == "hello"
- """
+ """Return a context manager used by captured_stdout and captured_stdin
+ that temporarily replaces the sys stream *stream_name* with a StringIO."""
import io
orig_stdout = getattr(sys, stream_name)
setattr(sys, stream_name, io.StringIO())
@@ -904,6 +898,12 @@
setattr(sys, stream_name, orig_stdout)
def captured_stdout():
+ """Capture the output of sys.stdout:
+
+ with captured_stdout() as s:
+ print("hello")
+ self.assertEqual(s.getvalue(), "hello")
+ """
return captured_output("stdout")
def captured_stderr():
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list