summaryrefslogtreecommitdiff
path: root/Lib/test/support.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2013-07-11 12:29:31 -0400
committerR David Murray <rdmurray@bitdance.com>2013-07-11 12:29:31 -0400
commite173d0123171adc1b5145ef7613364e14ccbd945 (patch)
treeafc2f18da0354bcb87387a208624ee3f082749a6 /Lib/test/support.py
parenta155d40ed50b7bf77338a80ad1793cb1ea8538bc (diff)
parent5a33f813483325ab3e13596814c3eade6e0bb518 (diff)
downloadcpython-git-e173d0123171adc1b5145ef7613364e14ccbd945.tar.gz
Merge #17987: properly document support.captured_xxx.
Diffstat (limited to 'Lib/test/support.py')
-rw-r--r--Lib/test/support.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/Lib/test/support.py b/Lib/test/support.py
index d26e10cfc7..f6f5060d72 100644
--- a/Lib/test/support.py
+++ b/Lib/test/support.py
@@ -1186,16 +1186,31 @@ def captured_output(stream_name):
def captured_stdout():
"""Capture the output of sys.stdout:
- with captured_stdout() as s:
+ with captured_stdout() as stdout:
print("hello")
- self.assertEqual(s.getvalue(), "hello")
+ self.assertEqual(stdout.getvalue(), "hello\n")
"""
return captured_output("stdout")
def captured_stderr():
+ """Capture the output of sys.stderr:
+
+ with captured_stderr() as stderr:
+ print("hello", file=sys.stderr)
+ self.assertEqual(stderr.getvalue(), "hello\n")
+ """
return captured_output("stderr")
def captured_stdin():
+ """Capture the input to sys.stdin:
+
+ with captured_stdin() as stdin:
+ stdin.write('hello\n')
+ stdin.seek(0)
+ # call test code that consumes from sys.stdin
+ captured = input()
+ self.assertEqual(captured, "hello")
+ """
return captured_output("stdin")