-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add regular file output when input is collected but not piped.
- Loading branch information
Showing
3 changed files
with
75 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import subprocess | ||
from unittest.mock import MagicMock, call, patch | ||
from duct import prepare_outputs | ||
|
||
|
||
def test_prepare_outputs_all_stdout(): | ||
output_prefix = "test_outputs" | ||
with patch("duct.TeeStream") as mock_tee_stream, patch( | ||
"builtins.open", new_callable=MagicMock | ||
) as mock_open: | ||
mock_tee_stream.return_value.start = MagicMock() | ||
stdout, stderr = prepare_outputs("all", "stdout", output_prefix) | ||
mock_tee_stream.assert_called_with(f"{output_prefix}/stdout.txt") | ||
assert stdout == mock_tee_stream.return_value | ||
assert stderr == mock_open.return_value | ||
|
||
|
||
def test_prepare_outputs_all_stderr(): | ||
output_prefix = "test_outputs" | ||
with patch("duct.TeeStream") as mock_tee_stream, patch( | ||
"builtins.open", new_callable=MagicMock | ||
) as mock_open: | ||
mock_tee_stream.return_value.start = MagicMock() | ||
stdout, stderr = prepare_outputs("all", "stderr", output_prefix) | ||
mock_tee_stream.assert_called_with(f"{output_prefix}/stderr.txt") | ||
assert stdout == mock_open.return_value | ||
assert stderr == mock_tee_stream.return_value | ||
|
||
|
||
def test_prepare_outputs_all_none(): | ||
output_prefix = "test_outputs" | ||
with patch("builtins.open", new_callable=MagicMock) as mock_open: | ||
stdout, stderr = prepare_outputs("all", "none", output_prefix) | ||
calls = [ | ||
call(f"{output_prefix}/stdout.txt"), | ||
call(f"{output_prefix}/stderr.txt"), | ||
] | ||
mock_open.assert_has_calls(calls, any_order=True) | ||
assert stdout == mock_open.return_value | ||
assert stderr == mock_open.return_value | ||
|
||
|
||
def test_prepare_outputs_none_stdout(): | ||
output_prefix = "test_outputs" | ||
stdout, stderr = prepare_outputs("none", "stdout", output_prefix) | ||
assert stdout == subprocess.PIPE | ||
assert stderr == subprocess.DEVNULL | ||
|
||
|
||
def test_prepare_outputs_none_stderr(): | ||
output_prefix = "test_outputs" | ||
stdout, stderr = prepare_outputs("none", "stderr", output_prefix) | ||
assert stderr == subprocess.PIPE | ||
assert stdout == subprocess.DEVNULL | ||
|
||
|
||
def test_prepare_outputs_all_all(): | ||
output_prefix = "test_outputs" | ||
with patch("duct.TeeStream") as mock_tee_stream: | ||
mock_tee_stream.return_value.start = MagicMock() | ||
stdout, stderr = prepare_outputs("all", "all", output_prefix) | ||
assert stdout == mock_tee_stream.return_value | ||
assert stderr == mock_tee_stream.return_value | ||
calls = [ | ||
call(f"{output_prefix}/stdout.txt"), | ||
call(f"{output_prefix}/stderr.txt"), | ||
] | ||
mock_tee_stream.assert_has_calls(calls, any_order=True) |