Skip to content

Commit

Permalink
Parameterize key layout tests with wheel style.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsirois committed Dec 13, 2023
1 parent 1ee1fe5 commit 9b78f10
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 28 deletions.
10 changes: 10 additions & 0 deletions testing/pep_427.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from pex.pep_427 import InstallableType


def get_installable_type_flag(installable_type):
# type: (InstallableType.Value) -> str
return (
"--no-pre-install-wheels"
if installable_type is InstallableType.WHEEL_FILE
else "--pre-install-wheels"
)
111 changes: 102 additions & 9 deletions tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from pex.interpreter import PythonInterpreter
from pex.layout import Layout
from pex.network_configuration import NetworkConfiguration
from pex.pep_427 import InstallableType
from pex.pex_info import PexInfo
from pex.requirements import LogicalLine, PyPIRequirement, parse_requirement_file
from pex.typing import TYPE_CHECKING, cast
Expand All @@ -49,6 +50,7 @@
run_simple_pex_test,
temporary_content,
)
from testing.pep_427 import get_installable_type_flag

if TYPE_CHECKING:
from typing import Any, Callable, ContextManager, Iterator, List, Optional, Tuple
Expand Down Expand Up @@ -795,19 +797,67 @@ def test_pex_resource_bundling():
assert stdout == b"hello\n"


def test_entry_point_verification_3rdparty(tmpdir):
# type: (Any) -> None
@pytest.mark.parametrize(
"layout", [pytest.param(layout, id=layout.value) for layout in Layout.values()]
)
@pytest.mark.parametrize(
"installable_type",
[
pytest.param(installable_type, id=installable_type.value)
for installable_type in InstallableType.values()
],
)
def test_entry_point_verification_3rdparty(
tmpdir, # type: Any
layout, # type: Layout.Value
installable_type, # type: InstallableType.Value
):
# type: (...) -> None
pex_out_path = os.path.join(str(tmpdir), "pex.pex")
run_pex_command(
args=["ansicolors==1.1.8", "-e", "colors:red", "-o", pex_out_path, "--validate-entry-point"]
args=[
"ansicolors==1.1.8",
"-e",
"colors:red",
"--layout",
layout.value,
get_installable_type_flag(installable_type),
"-o",
pex_out_path,
"--validate-entry-point",
]
).assert_success()


def test_invalid_entry_point_verification_3rdparty(tmpdir):
# type: (Any) -> None
@pytest.mark.parametrize(
"layout", [pytest.param(layout, id=layout.value) for layout in Layout.values()]
)
@pytest.mark.parametrize(
"installable_type",
[
pytest.param(installable_type, id=installable_type.value)
for installable_type in InstallableType.values()
],
)
def test_invalid_entry_point_verification_3rdparty(
tmpdir, # type: Any
layout, # type: Layout.Value
installable_type, # type: InstallableType.Value
):
# type: (...) -> None
pex_out_path = os.path.join(str(tmpdir), "pex.pex")
run_pex_command(
args=["ansicolors==1.1.8", "-e", "colors:bad", "-o", pex_out_path, "--validate-entry-point"]
args=[
"ansicolors==1.1.8",
"-e",
"colors:bad",
"--layout",
layout.value,
get_installable_type_flag(installable_type),
"-o",
pex_out_path,
"--validate-entry-point",
]
).assert_failure()


Expand Down Expand Up @@ -1521,15 +1571,25 @@ def run_isort_pex(pex_python=None):
@pytest.mark.parametrize(
"layout", [pytest.param(layout, id=layout.value) for layout in Layout.values()]
)
@pytest.mark.parametrize(
"installable_type",
[
pytest.param(installable_type, id=installable_type.value)
for installable_type in InstallableType.values()
],
)
def test_seed(
isort_pex_args, # type: Tuple[str, List[str]]
execution_mode_args, # type: List[str]
layout, # type: Layout.Value
installable_type, # type: InstallableType.Value
):
# type: (...) -> None
pex_file, args = isort_pex_args
results = run_pex_command(
args=args + execution_mode_args + ["--layout", layout.value, "--seed"]
args=args
+ execution_mode_args
+ ["--layout", layout.value, get_installable_type_flag(installable_type), "--seed"]
)
results.assert_success()

Expand All @@ -1548,6 +1608,13 @@ def test_seed(
@pytest.mark.parametrize(
"layout", [pytest.param(layout, id=layout.value) for layout in Layout.values()]
)
@pytest.mark.parametrize(
"installable_type",
[
pytest.param(installable_type, id=installable_type.value)
for installable_type in InstallableType.values()
],
)
@pytest.mark.parametrize(
"seeded_execute_args",
[pytest.param(["python", "pex"], id="Python"), pytest.param(["pex"], id="Direct")],
Expand All @@ -1556,14 +1623,23 @@ def test_seed_verbose(
isort_pex_args, # type: Tuple[str, List[str]]
execution_mode_args, # type: List[str]
layout, # type: Layout.Value
installable_type, # type: InstallableType.Value
seeded_execute_args, # type: List[str]
tmpdir, # type: Any
):
# type: (...) -> None
pex_root = str(tmpdir)
pex_file, args = isort_pex_args
results = run_pex_command(
args=args + execution_mode_args + ["--layout", layout.value, "--seed", "verbose"],
args=args
+ execution_mode_args
+ [
"--layout",
layout.value,
get_installable_type_flag(installable_type),
"--seed",
"verbose",
],
env=make_env(PEX_ROOT=pex_root, PEX_PYTHON_PATH=sys.executable),
)
results.assert_success()
Expand Down Expand Up @@ -1853,18 +1929,35 @@ def test_require_hashes(tmpdir):
@pytest.mark.parametrize(
"layout", [pytest.param(layout, id=layout.value) for layout in Layout.values()]
)
@pytest.mark.parametrize(
"installable_type",
[
pytest.param(installable_type, id=installable_type.value)
for installable_type in InstallableType.values()
],
)
def test_binary_scripts(
tmpdir, # type: Any
execution_mode_args, # type: List[str]
layout, # type: Layout.Value
installable_type, # type: InstallableType.Value
):
# type: (...) -> None

# The py-spy distribution has a `py-spy` "script" that is a native executable that we should
# not try to parse as a traditional script but should still be able to execute.
py_spy_pex = os.path.join(str(tmpdir), "py-spy.pex")
run_pex_command(
args=["py-spy==0.3.8", "-c", "py-spy", "-o", py_spy_pex, "--layout", layout.value]
args=[
"py-spy==0.3.8",
"-c",
"py-spy",
"-o",
py_spy_pex,
"--layout",
layout.value,
get_installable_type_flag(installable_type),
]
+ execution_mode_args
).assert_success()
output = subprocess.check_output(args=[sys.executable, py_spy_pex, "-V"])
Expand Down
42 changes: 40 additions & 2 deletions tests/integration/test_issue_1879.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import pytest

from pex.layout import Layout
from pex.pep_427 import InstallableType
from pex.pex_info import PexInfo
from pex.typing import TYPE_CHECKING
from testing import run_pex_command
from testing.pep_427 import get_installable_type_flag

if TYPE_CHECKING:
from typing import Any
Expand All @@ -20,25 +22,61 @@
# So, we get "test_overwrite[zipapp-loose]" which indicates a test of the transition from
# zipapp (layout1) to loose (layout2) and "test_overwrite[packed-packed]" to indicate an overwrite
# of the packed layout by another packed layout, etc.
@pytest.mark.parametrize(
"installable_type2",
[
pytest.param(installable_type, id=installable_type.value)
for installable_type in InstallableType.values()
],
)
@pytest.mark.parametrize(
"layout2", [pytest.param(layout, id=layout.value) for layout in Layout.values()]
)
@pytest.mark.parametrize(
"installable_type1",
[
pytest.param(installable_type, id=installable_type.value)
for installable_type in InstallableType.values()
],
)
@pytest.mark.parametrize(
"layout1", [pytest.param(layout, id=layout.value) for layout in Layout.values()]
)
def test_overwrite(
tmpdir, # type: Any
layout1, # type: Layout.Value
installable_type1, # type: InstallableType.Value
layout2, # type: Layout.Value
installable_type2, # type: InstallableType.Value
):
# type: (...) -> None

pex = os.path.join(str(tmpdir), "pex")

run_pex_command(args=["-e", "one", "-o", pex, "--layout", layout1.value]).assert_success()
run_pex_command(
args=[
"-e",
"one",
"-o",
pex,
"--layout",
layout1.value,
get_installable_type_flag(installable_type1),
]
).assert_success()
assert layout1 is Layout.identify(pex)
assert "one" == PexInfo.from_pex(pex).entry_point

run_pex_command(args=["-e", "two", "-o", pex, "--layout", layout2.value]).assert_success()
run_pex_command(
args=[
"-e",
"two",
"-o",
pex,
"--layout",
layout2.value,
get_installable_type_flag(installable_type2),
]
).assert_success()
assert layout2 is Layout.identify(pex)
assert "two" == PexInfo.from_pex(pex).entry_point
11 changes: 11 additions & 0 deletions tests/integration/test_issue_2023.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
from colors import colors

from pex.layout import Layout
from pex.pep_427 import InstallableType
from pex.typing import TYPE_CHECKING
from testing import run_pex_command
from testing.pep_427 import get_installable_type_flag

if TYPE_CHECKING:
from typing import Any, List
Expand All @@ -21,6 +23,13 @@
@pytest.mark.parametrize(
"layout", [pytest.param(layout, id=layout.value) for layout in Layout.values()]
)
@pytest.mark.parametrize(
"installable_type",
[
pytest.param(installable_type, id=installable_type.value)
for installable_type in InstallableType.values()
],
)
@pytest.mark.parametrize(
"execution_mode_args",
[
Expand All @@ -32,6 +41,7 @@
def test_unpack_robustness(
tmpdir, # type: Any
layout, # type: Layout.Value
installable_type, # type: InstallableType.Value
execution_mode_args, # type: List[str]
):
# type: (...) -> None
Expand All @@ -58,6 +68,7 @@ def test_unpack_robustness(
exe,
"--layout",
layout.value,
get_installable_type_flag(installable_type),
"-o",
pex,
]
Expand Down
11 changes: 11 additions & 0 deletions tests/integration/test_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

from pex.common import safe_open, safe_rmtree
from pex.layout import Layout
from pex.pep_427 import InstallableType
from pex.typing import TYPE_CHECKING
from testing import run_pex_command
from testing.pep_427 import get_installable_type_flag

if TYPE_CHECKING:
from typing import Any, List
Expand All @@ -22,10 +24,18 @@
@pytest.mark.parametrize(
"layout", [pytest.param(layout, id=layout.value) for layout in Layout.values()]
)
@pytest.mark.parametrize(
"installable_type",
[
pytest.param(installable_type, id=installable_type.value)
for installable_type in InstallableType.values()
],
)
def test_resiliency(
tmpdir, # type: Any
execution_mode_args, # type: List[str]
layout, # type: Layout.Value
installable_type, # type: InstallableType.Value
):
# type: (...) -> None
src_dir = os.path.join(str(tmpdir), "src")
Expand All @@ -50,6 +60,7 @@ def test_resiliency(
pex_app,
"--layout",
layout.value,
get_installable_type_flag(installable_type),
]
+ execution_mode_args
).assert_success()
Expand Down
Loading

0 comments on commit 9b78f10

Please sign in to comment.