| 1 |
from briefcase.console import LogLevel |
| 2 |
|
| 3 |
|
| 4 |
def test_output(mock_sub, streaming_process, sleep_zero, capsys): |
| 5 |
"""Process output is printed.""" |
| 6 |
streamer = mock_sub.stream_output_non_blocking("testing", streaming_process) |
| 7 |
streamer.join() |
| 8 |
|
| 9 |
# fmt: off |
| 10 |
assert capsys.readouterr().out == ( |
| 11 |
"output line 1\n" |
| 12 |
"\n" |
| 13 |
"output line 3\n" |
| 14 |
) |
| 15 |
# fmt: on |
| 16 |
|
| 17 |
|
| 18 |
def test_output_debug(mock_sub, streaming_process, sleep_zero, capsys): |
| 19 |
"""Process output is printed; no debug output for only |
| 20 |
stream_output_non_blocking.""" |
| 21 |
mock_sub.tools.console.verbosity = LogLevel.DEBUG |
| 22 |
|
| 23 |
streamer = mock_sub.stream_output_non_blocking("testing", streaming_process) |
| 24 |
streamer.join() |
| 25 |
|
| 26 |
# fmt: off |
| 27 |
assert capsys.readouterr().out == ( |
| 28 |
"output line 1\n" |
| 29 |
"\n" |
| 30 |
"output line 3\n" |
| 31 |
) |
| 32 |
# fmt: on |
| 33 |
|
| 34 |
|
| 35 |
def test_captured_output(mock_sub, streaming_process, sleep_zero, capsys): |
| 36 |
"""Process output is captured and available later.""" |
| 37 |
streamer = mock_sub.stream_output_non_blocking( |
| 38 |
"testing", |
| 39 |
streaming_process, |
| 40 |
capture_output=True, |
| 41 |
) |
| 42 |
streamer.join() |
| 43 |
|
| 44 |
assert capsys.readouterr().out == "" |
| 45 |
# fmt: off |
| 46 |
assert streamer.captured_output == ( |
| 47 |
"output line 1\n" |
| 48 |
"\n" |
| 49 |
"output line 3\n" |
| 50 |
) |
| 51 |
# fmt: on |
| 52 |
|
| 53 |
|
| 54 |
def test_filter_func(mock_sub, streaming_process, sleep_zero, capsys): |
| 55 |
"""Process output can be filtered with a filter func.""" |
| 56 |
|
| 57 |
def filter_func(line): |
| 58 |
"""Filter out lines without text.""" |
| 59 |
if line == "": |
| 60 |
return |
| 61 |
yield line |
| 62 |
|
| 63 |
streamer = mock_sub.stream_output_non_blocking( |
| 64 |
"testing", |
| 65 |
streaming_process, |
| 66 |
filter_func=filter_func, |
| 67 |
) |
| 68 |
streamer.join() |
| 69 |
|
| 70 |
# fmt: off |
| 71 |
assert capsys.readouterr().out == ( |
| 72 |
"output line 1\n" |
| 73 |
"output line 3\n" |
| 74 |
) |
| 75 |
# fmt: on |