-
-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(test_wrap_stdio): add wrap_stdio tests
- Loading branch information
Showing
2 changed files
with
56 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,9 +10,7 @@ | |
|
||
def wrap_stdio(): | ||
_wrap_stdio() | ||
return None | ||
|
||
|
||
def unwrap_stdio(): | ||
_unwrap_stdio() | ||
return None |
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,56 @@ | ||
import sys | ||
|
||
from commitizen import wrap_stdio, wrap_stdio_linux, wrap_stdio_unix, wrap_stdio_windows | ||
|
||
|
||
def test_warp_stdio_exists(): | ||
assert hasattr(wrap_stdio_windows, "sys") | ||
assert hasattr(wrap_stdio_linux, "sys") | ||
assert hasattr(wrap_stdio_unix, "sys") | ||
|
||
|
||
if sys.platform == "win32": # pragma: no cover | ||
pass | ||
elif sys.platform == "linux": | ||
from commitizen.wrap_stdio_linux import WrapStdioLinux | ||
|
||
def test_wrap_stdio_linux(mocker): | ||
|
||
tmp_stdin = sys.stdin | ||
tmp_stdout = sys.stdout | ||
tmp_stderr = sys.stderr | ||
|
||
mocker.patch("os.open") | ||
readerwriter_mock = mocker.mock_open(read_data="data") | ||
mocker.patch("builtins.open", readerwriter_mock, create=True) | ||
|
||
mocker.patch.object(sys.stdin, "fileno", return_value=0) | ||
mocker.patch.object(sys.stdout, "fileno", return_value=1) | ||
mocker.patch.object(sys.stdout, "fileno", return_value=2) | ||
|
||
wrap_stdio.wrap_stdio() | ||
|
||
assert sys.stdin != tmp_stdin | ||
assert isinstance(sys.stdin, WrapStdioLinux) | ||
assert sys.stdin.encoding == "UTF-8" | ||
assert sys.stdin.read() == "data" | ||
|
||
assert sys.stdout != tmp_stdout | ||
assert isinstance(sys.stdout, WrapStdioLinux) | ||
sys.stdout.write("stdout") | ||
readerwriter_mock().write.assert_called_with("stdout") | ||
|
||
assert sys.stderr != tmp_stderr | ||
assert isinstance(sys.stderr, WrapStdioLinux) | ||
sys.stdout.write("stderr") | ||
readerwriter_mock().write.assert_called_with("stderr") | ||
|
||
wrap_stdio.unwrap_stdio() | ||
|
||
assert sys.stdin == tmp_stdin | ||
assert sys.stdout == tmp_stdout | ||
assert sys.stderr == tmp_stderr | ||
|
||
|
||
else: | ||
pass |