|
| 1 | +from __future__ import absolute_import, unicode_literals |
| 2 | + |
| 3 | +import os |
1 | 4 | import shutil
|
2 | 5 | import subprocess
|
3 | 6 | import sys
|
4 | 7 |
|
5 | 8 | import py
|
6 | 9 | import pytest
|
| 10 | +from pathlib2 import Path |
| 11 | +from six.moves.urllib.parse import urljoin |
| 12 | +from six.moves.urllib.request import pathname2url |
7 | 13 |
|
8 | 14 | from tox.exception import BadRequirement, MissingRequirement
|
9 | 15 |
|
@@ -141,3 +147,92 @@ def test_provision_cli_args_not_ignored_if_provision_false(cmd, initproj):
|
141 | 147 | initproj("test-0.1", {"tox.ini": "[tox]"})
|
142 | 148 | result = cmd("-a", "--option", "b")
|
143 | 149 | result.assert_fail(is_run_test_env=False)
|
| 150 | + |
| 151 | + |
| 152 | +@pytest.fixture(scope="session") |
| 153 | +def wheel(tmp_path_factory): |
| 154 | + """create a wheel for a project""" |
| 155 | + state = {"at": 0} |
| 156 | + |
| 157 | + def _wheel(path): |
| 158 | + state["at"] += 1 |
| 159 | + dest_path = tmp_path_factory.mktemp("wheel-{}-".format(state["at"])) |
| 160 | + env = os.environ.copy() |
| 161 | + try: |
| 162 | + subprocess.check_output( |
| 163 | + [ |
| 164 | + sys.executable, |
| 165 | + "-m", |
| 166 | + "pip", |
| 167 | + "wheel", |
| 168 | + "-w", |
| 169 | + str(dest_path), |
| 170 | + "--no-deps", |
| 171 | + str(path), |
| 172 | + ], |
| 173 | + universal_newlines=True, |
| 174 | + stderr=subprocess.STDOUT, |
| 175 | + env=env, |
| 176 | + ) |
| 177 | + except subprocess.CalledProcessError as exception: |
| 178 | + assert not exception.returncode, exception.output |
| 179 | + |
| 180 | + wheels = list(dest_path.glob("*.whl")) |
| 181 | + assert len(wheels) == 1 |
| 182 | + wheel = wheels[0] |
| 183 | + return wheel |
| 184 | + |
| 185 | + return _wheel |
| 186 | + |
| 187 | + |
| 188 | +THIS_PROJECT_ROOT = Path(__file__).resolve().parents[3] |
| 189 | + |
| 190 | + |
| 191 | +@pytest.fixture(scope="session") |
| 192 | +def tox_wheel(wheel): |
| 193 | + return wheel(THIS_PROJECT_ROOT) |
| 194 | + |
| 195 | + |
| 196 | +@pytest.fixture(scope="session") |
| 197 | +def magic_non_canonical_wheel(wheel, tmp_path_factory): |
| 198 | + magic_proj = tmp_path_factory.mktemp("magic") |
| 199 | + (magic_proj / "setup.py").write_text( |
| 200 | + "from setuptools import setup\nsetup(name='com.magic.this-is-fun')" |
| 201 | + ) |
| 202 | + return wheel(magic_proj) |
| 203 | + |
| 204 | + |
| 205 | +def test_provision_non_canonical_dep( |
| 206 | + cmd, initproj, monkeypatch, tox_wheel, magic_non_canonical_wheel |
| 207 | +): |
| 208 | + initproj( |
| 209 | + "w-0.1", |
| 210 | + { |
| 211 | + "tox.ini": """ |
| 212 | + [tox] |
| 213 | + envlist = py |
| 214 | + requires = |
| 215 | + com.magic.this-is-fun |
| 216 | + tox == {} |
| 217 | + [testenv:.tox] |
| 218 | + passenv = * |
| 219 | + """.format( |
| 220 | + tox_wheel.name.split("-")[1] |
| 221 | + ) |
| 222 | + }, |
| 223 | + ) |
| 224 | + find_links = " ".join( |
| 225 | + space_path2url(d) for d in (tox_wheel.parent, magic_non_canonical_wheel.parent) |
| 226 | + ) |
| 227 | + |
| 228 | + monkeypatch.setenv(str("PIP_FIND_LINKS"), str(find_links)) |
| 229 | + |
| 230 | + result = cmd("-a", "-v", "-v") |
| 231 | + result.assert_success(is_run_test_env=False) |
| 232 | + |
| 233 | + |
| 234 | +def space_path2url(path): |
| 235 | + at_path = str(path) |
| 236 | + if " " not in at_path: |
| 237 | + return at_path |
| 238 | + return urljoin("file:", pathname2url(os.path.abspath(at_path))) |
0 commit comments