mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Merge #17987: properly document support.captured_xxx.
This commit is contained in:
commit
e173d01231
4 changed files with 47 additions and 16 deletions
|
@ -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")
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue