Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 48 additions & 12 deletions python/tests/test_boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
8 changes: 5 additions & 3 deletions python/tests/test_python_args.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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="")
"""
)
)
Expand All @@ -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,
Expand Down