Skip to content

Commit

Permalink
Removing testing modules from prod code.
Browse files Browse the repository at this point in the history
Although these were harmless, removing them was made natural with the
introduction of a dedicated test runner script which will be expanded to
include spinning up a `devpi-server` in coming work to bring down
integration test times.
  • Loading branch information
jsirois committed Jul 25, 2023
1 parent 7d6ecdd commit ebe91d0
Show file tree
Hide file tree
Showing 154 changed files with 379 additions and 355 deletions.
3 changes: 0 additions & 3 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,5 @@ ignore_missing_imports = True
[mypy-pytest]
ignore_missing_imports = True

[mypy-pkginfo]
ignore_missing_imports = True

[mypy-pkg_resources]
ignore_missing_imports = True
3 changes: 2 additions & 1 deletion pex/resolve/resolver_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from __future__ import absolute_import

import itertools
import os

from pex.auth import PasswordEntry
from pex.enum import Enum
Expand All @@ -24,7 +25,7 @@
from pex.third_party import attr


PYPI = "https://pypi.org/simple"
PYPI = os.environ.get("_PEX_TEST_DEFAULT_INDEX", "https://pypi.org/simple")


class ResolverVersion(Enum["ResolverVersion.Value"]):
Expand Down
1 change: 1 addition & 0 deletions pex/venv/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,7 @@ def sys_executable_paths():
# an exception for here and not warn about in CI runs.
"_PEX_TEST_PYENV_ROOT",
"_PEX_PIP_VERSION",
"_PEX_TEST_PROJECT_DIR",
# This is used by Pex's Pip to inject runtime patches dynamically.
"_PEX_PIP_RUNTIME_PATCHES_PACKAGE",
# These are used by Pex's Pip venv to provide foreign platform support and work
Expand Down
4 changes: 2 additions & 2 deletions scripts/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ def run_black(*args: str) -> None:
dest=sys.stdout,
) as out_fd:
subprocess.run(
args=["black", "--color", *args, "pex", "scripts", "tests"],
args=["black", "--color", *args, "pex", "scripts", "testing", "tests"],
stdout=out_fd,
stderr=subprocess.STDOUT,
check=True,
)


def run_isort(*args: str) -> None:
subprocess.run(args=["isort", *args, "pex", "scripts", "tests"], check=True)
subprocess.run(args=["isort", *args, "pex", "scripts", "testing", "tests"], check=True)


def main(check: bool = False) -> None:
Expand Down
22 changes: 0 additions & 22 deletions scripts/print_env.py

This file was deleted.

5 changes: 4 additions & 1 deletion scripts/typecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ def main() -> None:
run_mypy("3.8", files=sorted(find_files_to_check(include=["scripts"])), subject="scripts")

source_and_tests = sorted(
find_files_to_check(include=["pex", "tests"], exclude=["pex/vendor/_vendored"])
find_files_to_check(
include=["pex", "testing", "tests"],
exclude=[os.path.join("pex", "vendor", "_vendored")],
)
)
for python_version in ("3.12", "3.11", "3.5", "2.7"):
run_mypy(python_version, files=source_and_tests)
Expand Down
7 changes: 4 additions & 3 deletions pex/testing.py → testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,7 @@ def run_command_with_jitter(

def pex_project_dir():
# type: () -> str
return str(
subprocess.check_output(["git", "rev-parse", "--show-toplevel"]).decode("ascii").strip()
)
try:
return os.environ["_PEX_TEST_PROJECT_DIR"]
except KeyError:
sys.exit("Pex tests must be run via tox.")
73 changes: 73 additions & 0 deletions testing/bin/run_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env python
# Copyright 2023 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from __future__ import print_function

import os
import re
import subprocess
import sys
from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser

# Ensure the repo root is on the `sys.path` (for access to the pex and testing packages).
os.environ["_PEX_TEST_PROJECT_DIR"] = str(
subprocess.check_output(["git", "rev-parse", "--show-toplevel"]).decode("ascii").strip()
)
sys.path.insert(0, os.environ["_PEX_TEST_PROJECT_DIR"])

from testing import make_env, pex_project_dir


def typechecking():
# type: () -> bool
try:
import typing

return typing.TYPE_CHECKING
except ImportError:
return False


if typechecking():
from typing import Iterator, Tuple


def iter_test_control_env_vars():
# type: () -> Iterator[Tuple[str, str]]
for var, value in sorted(os.environ.items()):
if re.search(r"(PEX|PYTHON)", var) and var != "PYTHONHASHSEED":
yield var, value


def main():
# type: () -> int
parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter)
parser.add_argument(
"--",
dest="passthrough_args",
metavar="ARG",
nargs="*",
help="All arguments following -- are passed to pytest.",
)
options, passthrough_args = parser.parse_known_args()

test_control_env_vars = list(iter_test_control_env_vars())
if test_control_env_vars:
print("Test control environment variables:")
for var, value in test_control_env_vars:
print("{var}={value}".format(var=var, value=value))
else:
print("No test control environment variables set.")

return subprocess.call(
args=["pytest"] + passthrough_args[1:],
cwd=pex_project_dir(),
# N.B.: The pytest console script needs this to see the Pex project dir on the sys.path;
# cwd is not enough.
env=make_env(PYTHONPATH=pex_project_dir()),
)


if __name__ == "__main__":
sys.exit(main())
File renamed without changes.
2 changes: 1 addition & 1 deletion pex/cli/testing.py → testing/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import sys
from typing import Any

from pex.testing import IntegResults
from testing import IntegResults


def run_pex3(
Expand Down
File renamed without changes.
5 changes: 2 additions & 3 deletions tests/build_system/test_pep_517.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
import os.path

from pex.build_system.pep_517 import build_sdist
from pex.build_system.testing import assert_build_sdist
from pex.common import touch
from pex.pip.version import PipVersion
from pex.resolve.configured_resolver import ConfiguredResolver
from pex.result import Error
from pex.targets import LocalInterpreter
from pex.testing import make_project
from pex.typing import TYPE_CHECKING
from pex.version import __version__
from testing import make_project
from testing.build_system import assert_build_sdist

if TYPE_CHECKING:
from typing import Any
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

import pytest

from pex import testing
import testing
from pex.interpreter import PythonInterpreter
from pex.platforms import Platform
from pex.testing import PY27, PY38, PY39, PY310, ensure_python_interpreter
from testing import PY27, PY38, PY39, PY310, ensure_python_interpreter


@pytest.fixture(scope="session")
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/build_system/test_issue_2063.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import pytest

from pex.cli.testing import run_pex3
from pex.typing import TYPE_CHECKING
from testing.cli import run_pex3

if TYPE_CHECKING:
from typing import Any
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/build_system/test_issue_2125.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import pytest

from pex.cli.testing import run_pex3
from pex.typing import TYPE_CHECKING
from testing.cli import run_pex3

if TYPE_CHECKING:
from typing import Any
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/build_system/test_pep_517.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import pytest

from pex.build_system.testing import assert_build_sdist
from pex.testing import PY_VER
from pex.typing import TYPE_CHECKING
from testing import PY_VER
from testing.build_system import assert_build_sdist

if TYPE_CHECKING:
from typing import Any
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/build_system/test_pep_518.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from pex.resolve.configured_resolver import ConfiguredResolver
from pex.resolve.resolver_configuration import PipConfiguration, ReposConfiguration
from pex.targets import LocalInterpreter
from pex.testing import make_env, run_pex_command
from pex.typing import TYPE_CHECKING
from testing import make_env, run_pex_command

if TYPE_CHECKING:
from typing import Any
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cli/commands/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import sys
from textwrap import dedent

from pex.cli.testing import run_pex3
from pex.dist_metadata import Requirement
from pex.pep_440 import Version
from pex.pep_503 import ProjectName
Expand All @@ -20,6 +19,7 @@
from pex.resolve.resolver_configuration import ResolverVersion
from pex.sorted_tuple import SortedTuple
from pex.typing import TYPE_CHECKING
from testing.cli import run_pex3

if TYPE_CHECKING:
from typing import Any, Text
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cli/commands/test_export_subset.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import pytest

from pex import requirements
from pex.cli.testing import run_pex3
from pex.compatibility import to_unicode
from pex.dist_metadata import Requirement
from pex.requirements import LocalProjectRequirement, Source
from pex.typing import TYPE_CHECKING
from testing.cli import run_pex3

if TYPE_CHECKING:
from typing import Any
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/cli/commands/test_interpreter_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import json
import os

from pex.cli.testing import run_pex3
from pex.interpreter import PythonInterpreter
from pex.pep_425 import CompatibilityTags
from pex.pep_508 import MarkerEnvironment
from pex.testing import IntegResults
from pex.typing import TYPE_CHECKING, cast
from testing import IntegResults
from testing.cli import run_pex3

if TYPE_CHECKING:
from typing import Any, Dict, Text
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/cli/commands/test_issue_1413.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

import pytest

from pex.cli.testing import run_pex3
from pex.pep_440 import Version
from pex.pep_503 import ProjectName
from pex.resolve.locked_resolve import LockedRequirement
from pex.resolve.lockfile import json_codec
from pex.resolve.lockfile.model import Lockfile
from pex.resolve.path_mappings import PathMapping, PathMappings
from pex.resolve.resolved_requirement import Pin
from pex.testing import make_env, run_pex_command
from pex.typing import TYPE_CHECKING
from testing import make_env, run_pex_command
from testing.cli import run_pex3

if TYPE_CHECKING:
from typing import Any
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/cli/commands/test_issue_1665.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

import pytest

from pex.cli.testing import run_pex3
from pex.testing import IS_PYPY, run_pex_command
from pex.typing import TYPE_CHECKING
from testing import IS_PYPY, run_pex_command
from testing.cli import run_pex3

if TYPE_CHECKING:
from typing import Any
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/cli/commands/test_issue_1667.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

import pytest

from pex.cli.testing import run_pex3
from pex.interpreter import PythonInterpreter
from pex.testing import run_pex_command
from pex.typing import TYPE_CHECKING
from testing import run_pex_command
from testing.cli import run_pex3

if TYPE_CHECKING:
from typing import Any
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/cli/commands/test_issue_1688.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import os
import subprocess

from pex.cli.testing import run_pex3
from pex.interpreter import PythonInterpreter
from pex.pex_info import PexInfo
from pex.resolve.lockfile import json_codec
from pex.testing import run_pex_command
from pex.typing import TYPE_CHECKING
from testing import run_pex_command
from testing.cli import run_pex3

if TYPE_CHECKING:
from typing import Any
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/cli/commands/test_issue_1711.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

import os

from pex.cli.testing import run_pex3
from pex.compatibility import PY3
from pex.interpreter import PythonInterpreter
from pex.pep_440 import Version
from pex.pep_503 import ProjectName
from pex.resolve.locked_resolve import Artifact, LockedRequirement
from pex.resolve.lockfile import json_codec
from pex.resolve.resolved_requirement import Fingerprint
from pex.testing import IS_PYPY, PY_VER, run_pex_command
from pex.typing import TYPE_CHECKING
from testing import IS_PYPY, PY_VER, run_pex_command
from testing.cli import run_pex3

if TYPE_CHECKING:
from typing import Any
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/cli/commands/test_issue_1734.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import re
import subprocess

from pex.cli.testing import run_pex3
from pex.interpreter import PythonInterpreter
from pex.interpreter_constraints import InterpreterConstraint
from pex.testing import run_pex_command
from pex.typing import TYPE_CHECKING
from testing import run_pex_command
from testing.cli import run_pex3

if TYPE_CHECKING:
from typing import Any
Expand Down
Loading

0 comments on commit ebe91d0

Please sign in to comment.