Skip to content

Commit ea15925

Browse files
Евгений БлиновЕвгений Блинов
authored andcommitted
windows adaptation for 1 test
1 parent c8bb011 commit ea15925

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

suby/proxy_module.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,28 @@ def __call__(
5050

5151
logger.info(f'The beginning of the execution of the command "{arguments_string_representation}".')
5252

53-
with Popen(list(converted_arguments), stdout=PIPE, stderr=PIPE, bufsize=1, universal_newlines=True) as process:
54-
stderr_reading_thread = self.run_stderr_thread(process, stderr_buffer, result, catch_output, stderr_callback)
55-
if not isinstance(token, DefaultToken):
56-
killing_thread = self.run_killing_thread(process, token, result)
57-
58-
for line in process.stdout: # type: ignore[union-attr]
59-
stdout_buffer.append(line)
60-
if not catch_output:
61-
stdout_callback(line)
62-
63-
stderr_reading_thread.join()
64-
if not isinstance(token, DefaultToken):
65-
killing_thread.join()
53+
try:
54+
with Popen(list(converted_arguments), stdout=PIPE, stderr=PIPE, bufsize=1, universal_newlines=True) as process:
55+
stderr_reading_thread = self.run_stderr_thread(process, stderr_buffer, result, catch_output, stderr_callback)
56+
if not isinstance(token, DefaultToken):
57+
killing_thread = self.run_killing_thread(process, token, result)
58+
59+
for line in process.stdout: # type: ignore[union-attr]
60+
stdout_buffer.append(line)
61+
if not catch_output:
62+
stdout_callback(line)
63+
64+
stderr_reading_thread.join()
65+
if not isinstance(token, DefaultToken):
66+
killing_thread.join()
67+
68+
except FileNotFoundError as e:
69+
if not catch_exceptions:
70+
message = f'Error when executing the command "{arguments_string_representation}".'
71+
logger.error(message)
72+
raise RunningCommandError(message, result) from e
73+
return result
74+
6675

6776
self.fill_result(stdout_buffer, stderr_buffer, process.returncode, result)
6877

tests/units/test_proxy_module.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ def test_multiple_args_without_split(command):
523523
assert result.returncode == 0
524524

525525

526+
@pytest.mark.skipif(platform.system() == 'Windows', reason='On windows the split mode is default')
526527
@pytest.mark.parametrize(
527528
['command', 'exception_message'],
528529
[
@@ -536,6 +537,20 @@ def test_wrong_command(command, exception_message):
536537
suby(*command)
537538

538539

540+
@pytest.mark.skipif(platform.system() != 'Windows', reason='On windows the split mode is default')
541+
@pytest.mark.parametrize(
542+
['command', 'exception_message'],
543+
[
544+
((Path(sys.executable), '-c "'), 'The expression "-c "" cannot be parsed.'),
545+
((sys.executable, '-c "'), 'The expression "-c "" cannot be parsed.'),
546+
(('python -c "',), 'The expression "python -c "" cannot be parsed.'),
547+
]
548+
)
549+
def test_wrong_command_windows(command, exception_message):
550+
with pytest.raises(WrongCommandError, match=full_match(exception_message)):
551+
suby(*command)
552+
553+
539554
@pytest.mark.skipif(platform.system() == 'Windows', reason='On windows the split mode is default')
540555
def test_envs_for_subprocess_are_same_as_parent():
541556
subprocess_env = json.loads(suby('python -c "import os, json; print(json.dumps(dict(os.environ)))"').stdout)

0 commit comments

Comments
 (0)