| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
import os |
| 4 |
import sys |
| 5 |
from typing import TYPE_CHECKING, cast |
| 6 |
|
| 7 |
import pytest |
| 8 |
|
| 9 |
from tox.tox_env.python.package import WheelPackage |
| 10 |
from tox.tox_env.python.virtual_env.package.pyproject import Pep517VirtualEnvPackager |
| 11 |
|
| 12 |
if TYPE_CHECKING: |
| 13 |
from pathlib import Path |
| 14 |
|
| 15 |
from tox.pytest import ToxProjectCreator |
| 16 |
from tox.tox_env.runner import RunToxEnv |
| 17 |
|
| 18 |
|
| 19 |
@pytest.mark.slow |
| 20 |
@pytest.mark.integration |
| 21 |
def test_setuptools_package( |
| 22 |
tox_project: ToxProjectCreator, |
| 23 |
demo_pkg_setuptools: Path, |
| 24 |
enable_pip_pypi_access: str | None, # noqa: ARG001 |
| 25 |
) -> None: |
| 26 |
tox_ini = """ |
| 27 |
[testenv] |
| 28 |
package = wheel |
| 29 |
commands_pre = python -c 'import sys; print("start", sys.executable)' |
| 30 |
commands = python -c 'from demo_pkg_setuptools import do; do()' |
| 31 |
commands_post = python -c 'import sys; print("end", sys.executable)' |
| 32 |
""" |
| 33 |
project = tox_project({"tox.ini": tox_ini}, base=demo_pkg_setuptools) |
| 34 |
|
| 35 |
outcome = project.run("r", "-e", "py") |
| 36 |
|
| 37 |
outcome.assert_success() |
| 38 |
assert f"\ngreetings from demo_pkg_setuptools{os.linesep}" in outcome.out |
| 39 |
tox_env = cast("RunToxEnv", outcome.state.envs["py"]) |
| 40 |
|
| 41 |
(package_env,) = list(tox_env.package_envs) |
| 42 |
assert isinstance(package_env, Pep517VirtualEnvPackager) |
| 43 |
packages = package_env.perform_packaging(tox_env.conf) |
| 44 |
assert len(packages) == 1 |
| 45 |
package = packages[0] |
| 46 |
assert isinstance(package, WheelPackage) |
| 47 |
assert str(package) == str(package.path) |
| 48 |
assert package.path.name == f"demo_pkg_setuptools-1.2.3-py{sys.version_info.major}-none-any.whl" |
| 49 |
|
| 50 |
result = outcome.out.split("\n") |
| 51 |
py_messages = [i for i in result if "py: " in i] |
| 52 |
assert len(py_messages) == 5, "\n".join(py_messages) # 1 install wheel + 3 command + 1 final report |
| 53 |
|
| 54 |
package_messages = [i for i in result if ".pkg: " in i] |
| 55 |
# 1 optional hooks + 1 install requires + 1 build meta + 1 build isolated |
| 56 |
assert len(package_messages) == 4, "\n".join(package_messages) |