diff --git a/python/tests/test_boot.py b/python/tests/test_boot.py index c5fb3d1..bbc23db 100644 --- a/python/tests/test_boot.py +++ b/python/tests/test_boot.py @@ -16,9 +16,10 @@ from testing.compare import ProcessResult # noqa: F401 -def test_basic(tmpdir): - # type: (Any) -> None - +def create_cowsay_pex( + tmpdir, # type: Any + *pex_args, # type: str +): pex = os.path.join(str(tmpdir), "cowsay.pex") pex_root = os.path.join(str(tmpdir), "pex-root") subprocess.check_call( @@ -32,19 +33,54 @@ def test_basic(tmpdir): "--runtime-pex-root", pex_root, ] + + list(pex_args) ) + return pex + + +def assert_result( + result, # type: ProcessResult + _is_traditional_pex, # type: bool +): + # type: (...) -> None + result.assert_success() + assert "| Moo! |" in result.stdout + + +def read_shebang(pex): + # type: (str) -> Text + + with open(pex, "rb") as fp: + return fp.readline().decode("utf-8") + + +def test_basic(tmpdir): + # type: (Any) -> None + + pex = create_cowsay_pex(tmpdir) + expected_shebang = read_shebang(pex) + assert expected_shebang.startswith("#!/usr/bin/env ") + + injected_pex = compare( + pex, + args=["Moo!"], + env=dict(PEXRC_ROOT=os.path.join(str(tmpdir), "pexrc-root")), + test_result=assert_result, + ) + assert expected_shebang == read_shebang(injected_pex) + + +def test_sh_boot(tmpdir): + # type: (Any) -> None - def test_result( - result, # type: ProcessResult - _is_traditional_pex, # type: bool - ): - # type: (...) -> None - result.assert_success() - assert "| Moo! |" in result.stdout + pex = create_cowsay_pex(tmpdir, "--sh-boot") + expected_shebang = read_shebang(pex) + assert expected_shebang == "#!/bin/sh\n" - compare( + injected_pex = compare( pex, args=["Moo!"], env=dict(PEXRC_ROOT=os.path.join(str(tmpdir), "pexrc-root")), - test_result=test_result, + test_result=assert_result, ) + assert expected_shebang == read_shebang(injected_pex) diff --git a/python/tests/test_python_args.py b/python/tests/test_python_args.py index 64ed46d..251f5e8 100644 --- a/python/tests/test_python_args.py +++ b/python/tests/test_python_args.py @@ -1,7 +1,7 @@ # Copyright 2026 Pex project contributors. # SPDX-License-Identifier: Apache-2.0 -from __future__ import absolute_import, print_function +from __future__ import absolute_import import os.path import subprocess @@ -29,13 +29,15 @@ def test_python_args_forwarded(tmpdir): fp.write( dedent( """\ + from __future__ import print_function + import sys import colors assert False, colors.red("Failed") - print(colors.green("Worked: {}".format(" ".join(sys.argv[1:])))) + print(colors.green("Worked: {}".format(" ".join(sys.argv[1:]))), end="") """ ) ) @@ -59,7 +61,7 @@ def test_result( ): # type: (...) -> None result.assert_success() - assert colors.green("Worked: Slartibartfast Ford") == result.stdout.strip() + assert colors.green("Worked: Slartibartfast Ford") == result.stdout injected_pex = compare( pex,