|
5 | 5 | import textwrap
|
6 | 6 |
|
7 | 7 | import pytest
|
8 |
| -from mock import patch |
| 8 | +from mock import Mock, patch |
| 9 | +from pip._vendor import pkg_resources |
9 | 10 | from pip._vendor.packaging.requirements import Requirement
|
10 | 11 |
|
11 | 12 | from pip._internal.exceptions import UnsupportedWheel
|
|
22 | 23 | from pip._internal.utils.compat import WINDOWS
|
23 | 24 | from pip._internal.utils.misc import hash_file
|
24 | 25 | from pip._internal.utils.unpacking import unpack_file
|
25 |
| -from tests.lib import DATA_DIR, assert_paths_equal |
| 26 | +from tests.lib import DATA_DIR, assert_paths_equal, skip_if_python2 |
26 | 27 |
|
27 | 28 |
|
28 | 29 | def call_get_legacy_build_wheel_path(caplog, names):
|
@@ -191,14 +192,76 @@ def test_get_csv_rows_for_installed__long_lines(tmpdir, caplog):
|
191 | 192 |
|
192 | 193 | def test_wheel_version(tmpdir, data):
|
193 | 194 | future_wheel = 'futurewheel-1.9-py2.py3-none-any.whl'
|
194 |
| - broken_wheel = 'brokenwheel-1.0-py2.py3-none-any.whl' |
195 | 195 | future_version = (1, 9)
|
196 | 196 |
|
197 | 197 | unpack_file(data.packages.joinpath(future_wheel), tmpdir + 'future')
|
198 |
| - unpack_file(data.packages.joinpath(broken_wheel), tmpdir + 'broken') |
199 | 198 |
|
200 | 199 | assert wheel.wheel_version(tmpdir + 'future') == future_version
|
201 |
| - assert not wheel.wheel_version(tmpdir + 'broken') |
| 200 | + |
| 201 | + |
| 202 | +def test_wheel_version_fails_on_error(monkeypatch): |
| 203 | + err = RuntimeError("example") |
| 204 | + monkeypatch.setattr(pkg_resources, "find_on_path", Mock(side_effect=err)) |
| 205 | + with pytest.raises(UnsupportedWheel) as e: |
| 206 | + wheel.wheel_version(".") |
| 207 | + assert repr(err) in str(e.value) |
| 208 | + |
| 209 | + |
| 210 | +def test_wheel_version_fails_no_dists(tmpdir): |
| 211 | + with pytest.raises(UnsupportedWheel) as e: |
| 212 | + wheel.wheel_version(str(tmpdir)) |
| 213 | + assert "no contained distribution found" in str(e.value) |
| 214 | + |
| 215 | + |
| 216 | +def test_wheel_version_fails_missing_wheel(tmpdir): |
| 217 | + dist_info_dir = tmpdir / "simple-0.1.0.dist-info" |
| 218 | + dist_info_dir.mkdir() |
| 219 | + dist_info_dir.joinpath("METADATA").touch() |
| 220 | + |
| 221 | + with pytest.raises(UnsupportedWheel) as e: |
| 222 | + wheel.wheel_version(str(tmpdir)) |
| 223 | + assert "could not read WHEEL file" in str(e.value) |
| 224 | + |
| 225 | + |
| 226 | +@skip_if_python2 |
| 227 | +def test_wheel_version_fails_on_bad_encoding(tmpdir): |
| 228 | + dist_info_dir = tmpdir / "simple-0.1.0.dist-info" |
| 229 | + dist_info_dir.mkdir() |
| 230 | + dist_info_dir.joinpath("METADATA").touch() |
| 231 | + dist_info_dir.joinpath("WHEEL").write_bytes(b"\xff") |
| 232 | + |
| 233 | + with pytest.raises(UnsupportedWheel) as e: |
| 234 | + wheel.wheel_version(str(tmpdir)) |
| 235 | + assert "error decoding WHEEL" in str(e.value) |
| 236 | + |
| 237 | + |
| 238 | +def test_wheel_version_fails_on_no_wheel_version(tmpdir): |
| 239 | + dist_info_dir = tmpdir / "simple-0.1.0.dist-info" |
| 240 | + dist_info_dir.mkdir() |
| 241 | + dist_info_dir.joinpath("METADATA").touch() |
| 242 | + dist_info_dir.joinpath("WHEEL").touch() |
| 243 | + |
| 244 | + with pytest.raises(UnsupportedWheel) as e: |
| 245 | + wheel.wheel_version(str(tmpdir)) |
| 246 | + assert "missing Wheel-Version" in str(e.value) |
| 247 | + |
| 248 | + |
| 249 | +@pytest.mark.parametrize("version", [ |
| 250 | + ("",), |
| 251 | + ("1.b",), |
| 252 | + ("1.",), |
| 253 | +]) |
| 254 | +def test_wheel_version_fails_on_bad_wheel_version(tmpdir, version): |
| 255 | + dist_info_dir = tmpdir / "simple-0.1.0.dist-info" |
| 256 | + dist_info_dir.mkdir() |
| 257 | + dist_info_dir.joinpath("METADATA").touch() |
| 258 | + dist_info_dir.joinpath("WHEEL").write_text( |
| 259 | + "Wheel-Version: {}".format(version) |
| 260 | + ) |
| 261 | + |
| 262 | + with pytest.raises(UnsupportedWheel) as e: |
| 263 | + wheel.wheel_version(str(tmpdir)) |
| 264 | + assert "invalid Wheel-Version" in str(e.value) |
202 | 265 |
|
203 | 266 |
|
204 | 267 | def test_check_compatibility():
|
|
0 commit comments