-
Notifications
You must be signed in to change notification settings - Fork 2
decode partial stdout/stderr in run_path TimeoutExpired branch #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,6 +70,30 @@ def test_exit_code_captured(self, tmp_path): | |
| ) | ||
| assert result.exit_code == 42 | ||
|
|
||
| def test_timeout_returns_str_stdout_stderr(self, tmp_path): | ||
| """When the subprocess exceeds the timeout, partial output is | ||
| returned as decoded str (matching the success path) rather than | ||
| the raw bytes that subprocess.TimeoutExpired carries by default. | ||
| """ | ||
| result = run_path( | ||
| [ | ||
| sys.executable, | ||
| "-u", | ||
| "-c", | ||
| "import time; print('partial line'); time.sleep(5)", | ||
| ], | ||
| use_stdin=False, | ||
| cwd=str(tmp_path), | ||
| timeout=1, | ||
| ) | ||
| # exit_code is None on timeout (process was killed) | ||
| assert result.exit_code is None | ||
| # stdout/stderr must be str, not bytes, regardless of whether | ||
| # the subprocess had produced any output before being killed | ||
| assert isinstance(result.stdout, str) | ||
| assert isinstance(result.stderr, str) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📍 python/tests/test_runner.py:92 [verified] |
||
| assert "partial line" in result.stdout | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📍 python/tests/test_runner.py:73 [verified] |
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📍 python/tests/test_runner.py:73 [verified] |
||
| def test_with_env(self, tmp_path): | ||
| import os | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -133,7 +133,13 @@ def run_path( | |
| timeout=timeout, | ||
| ) | ||
| except subprocess.TimeoutExpired as e: | ||
| return RunResult(e.stdout or "", e.stderr or "", None) | ||
| # subprocess.run with encoding='utf-8' returns decoded str on the | ||
| # normal completion path, but TimeoutExpired still carries the | ||
| # raw bytes captured from the pipe before decoding — produce | ||
| # str here so RunResult is uniformly typed. | ||
| partial_out = e.stdout.decode("utf-8", errors="replace") if e.stdout else "" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📍 python/vscode_common_python_lsp/runner.py:139 [verified] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📍 python/vscode_common_python_lsp/runner.py:135 [verified] |
||
| partial_err = e.stderr.decode("utf-8", errors="replace") if e.stderr else "" | ||
| return RunResult(partial_out, partial_err, None) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📍 python/vscode_common_python_lsp/runner.py:136 [verified] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📍 python/vscode_common_python_lsp/runner.py:136 [verified] |
||
| return RunResult(result.stdout, result.stderr, result.returncode) | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📍 python/tests/test_runner.py:94
Review-rule violation (
tests-no-partial-asserts). The subprocess output is deterministic (print('partial line')with-uyields exactly"partial line\n", and universal-newline translation normalizes any\r\n), and none of the rule's non-determinism exceptions (timestamps, random IDs, PIDs) apply. Replaceassert "partial line" in result.stdoutwithassert result.stdout == "partial line\n"for an exact assertion.[verified]