2 from pybind11_tests
import iostream
as m
5 from contextlib
import contextmanager
9 from io
import StringIO
13 from cStringIO
import StringIO
15 from StringIO
import StringIO
19 from contextlib
import redirect_stdout
30 from contextlib
import redirect_stderr
41 msg =
"I've been redirected to Python, I hope!" 42 m.captured_output(msg)
43 stdout, stderr = capsys.readouterr()
47 m.captured_output_default(msg)
48 stdout, stderr = capsys.readouterr()
53 stdout, stderr = capsys.readouterr()
60 msg =
"I've been redirected to Python, I hope!" 61 msg = msg * (1024 //
len(msg) + 1)
63 m.captured_output_default(msg)
64 stdout, stderr = capsys.readouterr()
70 msg =
"I've been redirected to Python, I hope!" 72 stdout, stderr = capsys.readouterr()
79 m.captured_output(
"a")
80 m.captured_output(
"b")
81 assert capture ==
"ab" 88 with m.ostream_redirect():
89 m.noisy_function(msg, flush=
False)
90 stdout, stderr = capfd.readouterr()
93 m.noisy_function(msg2, flush=
True)
94 stdout, stderr = capfd.readouterr()
95 assert stdout == msg + msg2
97 m.noisy_function(msg, flush=
False)
99 stdout, stderr = capfd.readouterr()
104 msg =
"Something that should not show up in log" 108 stdout, stderr = capfd.readouterr()
111 assert stream.getvalue() ==
'' 115 m.captured_output(msg)
116 stdout, stderr = capfd.readouterr()
119 assert stream.getvalue() == msg
123 msg =
"Something that should not show up in log" 127 stdout, stderr = capfd.readouterr()
130 assert stream.getvalue() ==
'' 135 stdout, stderr = capfd.readouterr()
138 assert stream.getvalue() == msg
144 m.captured_output(
"a")
146 m.captured_output(
"c")
148 stdout, stderr = capfd.readouterr()
149 assert stdout ==
'bd' 150 assert stream.getvalue() ==
'ac' 154 m.captured_dual(
"a",
"b")
155 stdout, stderr = capsys.readouterr()
161 msg =
"Should not be in log!" 165 stdout, stderr = capfd.readouterr()
167 assert stream.getvalue() ==
'' 171 with m.ostream_redirect():
173 stdout, stderr = capfd.readouterr()
175 assert stream.getvalue() == msg
180 stdout, stderr = capfd.readouterr()
182 assert stream.getvalue() ==
'' 191 with m.ostream_redirect(stdout=
False):
194 stdout, stderr = capfd.readouterr()
197 assert stream.getvalue() == msg2
208 with m.ostream_redirect():
211 stdout, stderr = capfd.readouterr()
214 assert stream.getvalue() == msg
215 assert stream2.getvalue() == msg2
def redirect_stderr(target)
def test_guard_capture(capsys)
def test_captured(capsys)
def test_captured_large_string(capsys)
def test_series_captured(capture)
def test_not_captured(capfd)
def test_redirect_both(capfd)
def test_redirect_err(capfd)
def test_multi_captured(capfd)
def redirect_stdout(target)