1 from pybind11_tests
import iostream
as m
4 from contextlib
import contextmanager
8 from io
import StringIO
12 from cStringIO
import StringIO
14 from StringIO
import StringIO
18 from contextlib
import redirect_stdout
29 from contextlib
import redirect_stderr
40 msg =
"I've been redirected to Python, I hope!" 41 m.captured_output(msg)
42 stdout, stderr = capsys.readouterr()
46 m.captured_output_default(msg)
47 stdout, stderr = capsys.readouterr()
52 stdout, stderr = capsys.readouterr()
59 msg =
"I've been redirected to Python, I hope!" 60 msg = msg * (1024 //
len(msg) + 1)
62 m.captured_output_default(msg)
63 stdout, stderr = capsys.readouterr()
69 msg =
"I've been redirected to Python, I hope!" 71 stdout, stderr = capsys.readouterr()
78 m.captured_output(
"a")
79 m.captured_output(
"b")
80 assert capture ==
"ab" 87 with m.ostream_redirect():
88 m.noisy_function(msg, flush=
False)
89 stdout, stderr = capfd.readouterr()
92 m.noisy_function(msg2, flush=
True)
93 stdout, stderr = capfd.readouterr()
94 assert stdout == msg + msg2
96 m.noisy_function(msg, flush=
False)
98 stdout, stderr = capfd.readouterr()
103 msg =
"Something that should not show up in log" 107 stdout, stderr = capfd.readouterr()
110 assert stream.getvalue() ==
'' 114 m.captured_output(msg)
115 stdout, stderr = capfd.readouterr()
118 assert stream.getvalue() == msg
122 msg =
"Something that should not show up in log" 126 stdout, stderr = capfd.readouterr()
129 assert stream.getvalue() ==
'' 134 stdout, stderr = capfd.readouterr()
137 assert stream.getvalue() == msg
143 m.captured_output(
"a")
145 m.captured_output(
"c")
147 stdout, stderr = capfd.readouterr()
148 assert stdout ==
'bd' 149 assert stream.getvalue() ==
'ac' 153 m.captured_dual(
"a",
"b")
154 stdout, stderr = capsys.readouterr()
160 msg =
"Should not be in log!" 164 stdout, stderr = capfd.readouterr()
166 assert stream.getvalue() ==
'' 170 with m.ostream_redirect():
172 stdout, stderr = capfd.readouterr()
174 assert stream.getvalue() == msg
179 stdout, stderr = capfd.readouterr()
181 assert stream.getvalue() ==
'' 190 with m.ostream_redirect(stdout=
False):
193 stdout, stderr = capfd.readouterr()
196 assert stream.getvalue() == msg2
207 with m.ostream_redirect():
210 stdout, stderr = capfd.readouterr()
213 assert stream.getvalue() == msg
214 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)