1 from contextlib
import redirect_stderr, redirect_stdout
2 from io
import StringIO
4 from pybind11_tests
import iostream
as m
8 msg =
"I've been redirected to Python, I hope!" 10 stdout, stderr = capsys.readouterr()
14 m.captured_output_default(msg)
15 stdout, stderr = capsys.readouterr()
20 stdout, stderr = capsys.readouterr()
27 msg =
"I've been redirected to Python, I hope!" 28 msg = msg * (1024 //
len(msg) + 1)
30 m.captured_output_default(msg)
31 stdout, stderr = capsys.readouterr()
38 msg =
"" + msg * (1024 //
len(msg) + 1)
40 m.captured_output_default(msg)
41 stdout, stderr = capsys.readouterr()
48 msg =
"1" + msg * (1024 //
len(msg) + 1)
50 m.captured_output_default(msg)
51 stdout, stderr = capsys.readouterr()
58 msg =
"" + msg * (1024 //
len(msg) + 1)
60 m.captured_output_default(msg)
61 stdout, stderr = capsys.readouterr()
68 msg =
"1" + msg * (1024 //
len(msg) + 1)
70 m.captured_output_default(msg)
71 stdout, stderr = capsys.readouterr()
78 msg =
"12" + msg * (1024 //
len(msg) + 1)
80 m.captured_output_default(msg)
81 stdout, stderr = capsys.readouterr()
88 msg =
"" + msg * (1024 //
len(msg) + 1)
90 m.captured_output_default(msg)
91 stdout, stderr = capsys.readouterr()
98 msg =
"1" + msg * (1024 //
len(msg) + 1)
100 m.captured_output_default(msg)
101 stdout, stderr = capsys.readouterr()
108 msg =
"12" + msg * (1024 //
len(msg) + 1)
110 m.captured_output_default(msg)
111 stdout, stderr = capsys.readouterr()
118 msg =
"123" + msg * (1024 //
len(msg) + 1)
120 m.captured_output_default(msg)
121 stdout, stderr = capsys.readouterr()
127 msg =
"I've been redirected to Python, I hope!" 129 stdout, stderr = capsys.readouterr()
136 m.captured_output(
"a")
137 m.captured_output(
"b")
138 assert capture ==
"ab" 142 msg =
"(not flushed)" 145 with m.ostream_redirect():
146 m.noisy_function(msg, flush=
False)
147 stdout, stderr = capfd.readouterr()
150 m.noisy_function(msg2, flush=
True)
151 stdout, stderr = capfd.readouterr()
152 assert stdout == msg + msg2
154 m.noisy_function(msg, flush=
False)
156 stdout, stderr = capfd.readouterr()
161 msg =
"Something that should not show up in log" 163 with redirect_stdout(stream):
165 stdout, stderr = capfd.readouterr()
168 assert stream.getvalue() ==
"" 171 with redirect_stdout(stream):
172 m.captured_output(msg)
173 stdout, stderr = capfd.readouterr()
176 assert stream.getvalue() == msg
180 msg =
"Something that should not show up in log" 182 with redirect_stderr(stream):
184 stdout, stderr = capfd.readouterr()
187 assert stream.getvalue() ==
"" 190 with redirect_stderr(stream):
192 stdout, stderr = capfd.readouterr()
195 assert stream.getvalue() == msg
200 with redirect_stdout(stream):
201 m.captured_output(
"a")
203 m.captured_output(
"c")
205 stdout, stderr = capfd.readouterr()
206 assert stdout ==
"bd" 207 assert stream.getvalue() ==
"ac" 211 m.captured_dual(
"a",
"b")
212 stdout, stderr = capsys.readouterr()
218 msg =
"Should not be in log!" 220 with redirect_stdout(stream):
222 stdout, stderr = capfd.readouterr()
224 assert stream.getvalue() ==
"" 227 with redirect_stdout(stream):
228 with m.ostream_redirect():
230 stdout, stderr = capfd.readouterr()
232 assert stream.getvalue() == msg
235 with redirect_stdout(stream):
237 stdout, stderr = capfd.readouterr()
239 assert stream.getvalue() ==
"" 247 with redirect_stderr(stream):
248 with m.ostream_redirect(stdout=
False):
251 stdout, stderr = capfd.readouterr()
254 assert stream.getvalue() == msg2
263 with redirect_stdout(stream):
264 with redirect_stderr(stream2):
265 with m.ostream_redirect():
268 stdout, stderr = capfd.readouterr()
271 assert stream.getvalue() == msg
272 assert stream2.getvalue() == msg2
276 with m.ostream_redirect(stdout=
True, stderr=
False):
282 threads.append(m.TestThread())
def test_guard_capture(capsys)
def test_captured(capsys)
def test_captured_large_string(capsys)
def test_series_captured(capture)
def test_captured_utf8_3byte_offset2(capsys)
def test_captured_utf8_3byte_offset1(capsys)
def test_not_captured(capfd)
def test_captured_utf8_4byte_offset3(capsys)
def test_captured_utf8_2byte_offset1(capsys)
def test_captured_utf8_4byte_offset1(capsys)
def test_captured_utf8_2byte_offset0(capsys)
def test_captured_utf8_3byte_offset0(capsys)
def test_captured_utf8_4byte_offset0(capsys)
def test_captured_utf8_4byte_offset2(capsys)
def test_redirect_both(capfd)
Double_ range(const Point2_ &p, const Point2_ &q)
def test_redirect_err(capfd)
def test_multi_captured(capfd)
size_t len(handle h)
Get the length of a Python object.