|
7 | 7 | from contextlib import contextmanager
|
8 | 8 | from pathlib import Path
|
9 | 9 | from subprocess import check_call
|
10 |
| -from typing import TYPE_CHECKING, Callable, Iterator |
| 10 | +from typing import TYPE_CHECKING, Callable, Iterator, Sequence |
11 | 11 | from unittest import mock
|
12 | 12 | from zipfile import ZipFile
|
13 | 13 |
|
|
16 | 16 | from packaging.requirements import Requirement
|
17 | 17 |
|
18 | 18 | if TYPE_CHECKING:
|
| 19 | + from build import DistributionType |
19 | 20 | from devpi_process import Index, IndexServer
|
20 | 21 |
|
21 | 22 | from tox.pytest import MonkeyPatch, TempPathFactory, ToxProjectCreator
|
@@ -102,22 +103,38 @@ def tox_wheels(tox_wheel: Path, tmp_path_factory: TempPathFactory) -> list[Path]
|
102 | 103 |
|
103 | 104 |
|
104 | 105 | @pytest.fixture(scope="session")
|
105 |
| -def pypi_index_self(pypi_server: IndexServer, tox_wheels: list[Path], demo_pkg_inline_wheel: Path) -> Index: |
106 |
| - with elapsed("start devpi and create index"): # takes around 1s |
| 106 | +def local_pypi_indexes( |
| 107 | + pypi_server: IndexServer, tox_wheels: list[Path], demo_pkg_inline_wheel: Path |
| 108 | +) -> tuple[Index, Index]: |
| 109 | + with elapsed("start devpi and create indexes"): # takes around 1s |
| 110 | + pypi_server.create_index("mirror", "type=mirror", "mirror_url=https://pypi.org/simple/") |
| 111 | + mirrored_index = pypi_server.create_index("magic", f"bases={pypi_server.user}/mirror") |
107 | 112 | self_index = pypi_server.create_index("self", "volatile=False")
|
108 | 113 | with elapsed("upload tox and its wheels to devpi"): # takes around 3.2s on build
|
| 114 | + mirrored_index.upload(*tox_wheels, demo_pkg_inline_wheel) |
109 | 115 | self_index.upload(*tox_wheels, demo_pkg_inline_wheel)
|
110 |
| - return self_index |
| 116 | + return mirrored_index, self_index |
111 | 117 |
|
112 | 118 |
|
113 |
| -@pytest.fixture |
114 |
| -def _pypi_index_self(pypi_index_self: Index, monkeypatch: MonkeyPatch) -> None: |
115 |
| - pypi_index_self.use() |
116 |
| - monkeypatch.setenv("PIP_INDEX_URL", pypi_index_self.url) |
| 119 | +def _use_pypi_index(pypi_index: Index, monkeypatch: MonkeyPatch) -> None: |
| 120 | + pypi_index.use() |
| 121 | + monkeypatch.setenv("PIP_INDEX_URL", pypi_index.url) |
117 | 122 | monkeypatch.setenv("PIP_RETRIES", str(2))
|
118 | 123 | monkeypatch.setenv("PIP_TIMEOUT", str(5))
|
119 | 124 |
|
120 | 125 |
|
| 126 | +@pytest.fixture |
| 127 | +def _pypi_index_mirrored(local_pypi_indexes: tuple[Index, Index], monkeypatch: MonkeyPatch) -> None: |
| 128 | + pypi_index_mirrored, _ = local_pypi_indexes |
| 129 | + _use_pypi_index(pypi_index_mirrored, monkeypatch) |
| 130 | + |
| 131 | + |
| 132 | +@pytest.fixture |
| 133 | +def _pypi_index_self(local_pypi_indexes: tuple[Index, Index], monkeypatch: MonkeyPatch) -> None: |
| 134 | + _, pypi_index_self = local_pypi_indexes |
| 135 | + _use_pypi_index(pypi_index_self, monkeypatch) |
| 136 | + |
| 137 | + |
121 | 138 | def test_provision_requires_nok(tox_project: ToxProjectCreator) -> None:
|
122 | 139 | ini = "[tox]\nrequires = pkg-does-not-exist\n setuptools==1\nskipsdist=true\n"
|
123 | 140 | outcome = tox_project({"tox.ini": ini}).run("c", "-e", "py")
|
@@ -254,3 +271,33 @@ def test_provision_default_arguments_exists(tox_project: ToxProjectCreator, subc
|
254 | 271 | outcome = project.run(subcommand)
|
255 | 272 | for argument in ["result_json", "hash_seed", "discover", "list_dependencies"]:
|
256 | 273 | assert hasattr(outcome.state.conf.options, argument)
|
| 274 | + |
| 275 | + |
| 276 | +@pytest.mark.integration |
| 277 | +@pytest.mark.usefixtures("_pypi_index_mirrored") |
| 278 | +def test_provision_install_pkg_pep517( |
| 279 | + tmp_path_factory: TempPathFactory, |
| 280 | + tox_project: ToxProjectCreator, |
| 281 | + pkg_builder: Callable[[Path, Path, Sequence[DistributionType], bool], Path], |
| 282 | +) -> None: |
| 283 | + example = tmp_path_factory.mktemp("example") |
| 284 | + skeleton = """ |
| 285 | + [build-system] |
| 286 | + requires = ["setuptools"] |
| 287 | + build-backend = "setuptools.build_meta" |
| 288 | + [project] |
| 289 | + name = "skeleton" |
| 290 | + version = "0.1.1337" |
| 291 | + """ |
| 292 | + (example / "pyproject.toml").write_text(skeleton) |
| 293 | + sdist = pkg_builder(example / "dist", example, ["sdist"], False) |
| 294 | + |
| 295 | + tox_ini = r""" |
| 296 | + [tox] |
| 297 | + requires = demo-pkg-inline |
| 298 | + [testenv] |
| 299 | + commands = python -c "print(42)" |
| 300 | + """ |
| 301 | + project = tox_project({"tox.ini": tox_ini}, base=example) |
| 302 | + result = project.run("r", "-e", "py", "--installpkg", str(sdist), "--notest") |
| 303 | + result.assert_success() |
0 commit comments