Skip to content

Commit 80a9075

Browse files
Евгений БлиновЕвгений Блинов
authored andcommitted
nonsplitting mode now is default (only for windows)
1 parent ee52da9 commit 80a9075

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

suby/proxy_module.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@ def __call__(
2727
stdout_callback: Callable[[str], Any] = stdout_with_flush,
2828
stderr_callback: Callable[[str], Any] = stderr_with_flush,
2929
timeout: Optional[Union[int, float]] = None,
30-
split: bool = True,
30+
split: bool = platform.system() == 'Windows',
3131
token: AbstractToken = DefaultToken(),
3232
) -> SubprocessResult:
3333
"""
3434
About reading from strout and stderr: https://stackoverflow.com/a/28319191/14522393
3535
"""
36+
if platform.system() == 'Windows' and not split:
37+
raise OSError('Windows arguments should be splitted.')
38+
3639
if timeout is not None and isinstance(token, DefaultToken):
3740
token = TimeoutToken(timeout)
3841
elif timeout is not None:
@@ -117,7 +120,6 @@ def split_argument(argument: str) -> List[str]:
117120
# https://stackoverflow.com/a/35900070/14522393
118121
if platform.system() == 'Windows':
119122
return [argument] # pragma: no cover
120-
#return [argument]
121123
return shlex_split(argument)
122124

123125
def run_killing_thread(self, process: Popen, token: AbstractToken, result: SubprocessResult) -> Thread: # type: ignore[type-arg]

tests/documentation/test_quick_start.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
import os
2+
import sys
13
from io import StringIO
4+
import platform
25
from contextlib import redirect_stdout, redirect_stderr
36

47
import suby
8+
import pytest
59

610

7-
def test_run_hello_world():
11+
@pytest.mark.skipif(platform.system() == 'Windows', reason='Windows and not windows have different rules of escaping characters.')
12+
def test_run_hello_world_not_for_windows():
813
stderr_buffer = StringIO()
914
stdout_buffer = StringIO()
1015

@@ -18,3 +23,21 @@ def test_run_hello_world():
1823
assert result.stderr == ''
1924
assert result.returncode == 0
2025
assert not result.killed_by_token
26+
27+
28+
@pytest.mark.skipif(platform.system() != 'Windows', reason='Windows and not windows have different rules of escaping characters.')
29+
def test_run_hello_world_windows():
30+
31+
stderr_buffer = StringIO()
32+
stdout_buffer = StringIO()
33+
34+
with redirect_stdout(stdout_buffer), redirect_stderr(stderr_buffer):
35+
result = suby('python', '-c', 'print("hello, world!")')
36+
37+
assert stderr_buffer.getvalue() == ''
38+
assert stdout_buffer.getvalue() == 'hello, world!\n'
39+
40+
assert result.stdout == 'hello, world!\n'
41+
assert result.stderr == ''
42+
assert result.returncode == 0
43+
assert not result.killed_by_token

0 commit comments

Comments
 (0)