diff options
author | R David Murray <rdmurray@bitdance.com> | 2013-07-11 12:28:40 -0400 |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2013-07-11 12:28:40 -0400 |
commit | 5a33f813483325ab3e13596814c3eade6e0bb518 (patch) | |
tree | 81f815e9ff3830ff8b81757054f47e5956398138 /Lib/test/support.py | |
parent | dfde2151ede820873324705403af3176093b5ef5 (diff) | |
download | cpython-git-5a33f813483325ab3e13596814c3eade6e0bb518.tar.gz |
#17987: properly document support.captured_xxx.
Patch by Dmi Baranov.
Diffstat (limited to 'Lib/test/support.py')
-rw-r--r-- | Lib/test/support.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/Lib/test/support.py b/Lib/test/support.py index 8db90a2a8c..7ab5ff7d31 100644 --- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -1184,16 +1184,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") |