-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(python): bin script python support, test argument passing (#3762)
Corrects multiple issues with running `bin` scripts from python. These were discovered in the context of this `projen` issue: projen/projen#2103 - Corrects broken argument marshaling to binary scripts introduced in #3694 - Exposes exit code and stderr from script execution instead of failing silently Additionally, adds more robust test coverage of passing arguments to `bin` scripts. --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
- Loading branch information
Showing
8 changed files
with
108 additions
and
22 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
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,38 @@ | ||
import platform | ||
import subprocess | ||
import sys | ||
import pytest | ||
|
||
|
||
class TestInvokeBinScript: | ||
@pytest.mark.skipif( | ||
platform.system() == "Windows", | ||
reason="jsii-pacmak does not generate windows scripts", | ||
) | ||
def test_invoke_script(self) -> None: | ||
result = run_script("calc") | ||
|
||
assert result.returncode == 0 | ||
assert result.stdout == b"Hello World!\n\n" | ||
assert result.stderr == b"" | ||
|
||
@pytest.mark.skipif( | ||
platform.system() == "Windows", | ||
reason="jsii-pacmak does not generate windows scripts", | ||
) | ||
def test_invoke_script_with_args(self) -> None: | ||
result = run_script("calc", "arg1", "arg2") | ||
|
||
assert result.returncode == 0 | ||
assert result.stdout == b"Hello World!\n arguments: arg1, arg2\n\n" | ||
assert result.stderr == b"" | ||
|
||
|
||
def run_script(script_name: str, *args: str) -> subprocess.CompletedProcess: | ||
if platform.system() == "Windows": | ||
# currently not used, the calling semantics have not been defined for bin scripts on windows | ||
script_path = f".env\\Scripts\\{script_name}" | ||
return subprocess.run([sys.executable, script_path, *args], capture_output=True) | ||
else: | ||
script_path = f".env/bin/{script_name}" | ||
return subprocess.run([script_path, *args], capture_output=True) |
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
3 changes: 2 additions & 1 deletion
3
packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.js.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.