|
| 1 | +from zipfile import BadZipfile |
| 2 | + |
| 3 | +from pip._vendor.pkg_resources import Requirement |
| 4 | +from pytest import fixture, mark, raises |
| 5 | + |
| 6 | +from pip._internal.network.lazy_wheel import dist_from_wheel_url |
| 7 | +from pip._internal.network.session import PipSession |
| 8 | +from tests.lib.requests_mocks import MockResponse |
| 9 | + |
| 10 | +MYPY_0_782_WHL = ( |
| 11 | + 'https://files.pythonhosted.org/packages/9d/65/' |
| 12 | + 'b96e844150ce18b9892b155b780248955ded13a2581d31872e7daa90a503/' |
| 13 | + 'mypy-0.782-py3-none-any.whl' |
| 14 | +) |
| 15 | +MYPY_0_782_REQS = { |
| 16 | + Requirement('typed-ast (<1.5.0,>=1.4.0)'), |
| 17 | + Requirement('typing-extensions (>=3.7.4)'), |
| 18 | + Requirement('mypy-extensions (<0.5.0,>=0.4.3)'), |
| 19 | + Requirement('psutil (>=4.0); extra == "dmypy"'), |
| 20 | +} |
| 21 | + |
| 22 | + |
| 23 | +@fixture |
| 24 | +def session(): |
| 25 | + return PipSession() |
| 26 | + |
| 27 | + |
| 28 | +@mark.network |
| 29 | +def test_dist_from_wheel_url(session): |
| 30 | + """Test if the acquired distribution contain correct information.""" |
| 31 | + dist = dist_from_wheel_url('mypy', MYPY_0_782_WHL, session) |
| 32 | + assert dist.key == 'mypy' |
| 33 | + assert dist.version == '0.782' |
| 34 | + assert dist.extras == ['dmypy'] |
| 35 | + assert set(dist.requires(dist.extras)) == MYPY_0_782_REQS |
| 36 | + |
| 37 | + |
| 38 | +@mark.network |
| 39 | +def test_dist_from_wheel_url_no_range(session, monkeypatch): |
| 40 | + """Test handling when HTTP range requests are not supported.""" |
| 41 | + monkeypatch.setattr(session, 'head', lambda *a, **kw: MockResponse(b'')) |
| 42 | + with raises(RuntimeError): |
| 43 | + dist_from_wheel_url('mypy', MYPY_0_782_WHL, session) |
| 44 | + |
| 45 | + |
| 46 | +@mark.network |
| 47 | +def test_dist_from_wheel_url_not_zip(session): |
| 48 | + """Test handling with the given URL does not point to a ZIP.""" |
| 49 | + with raises(BadZipfile): |
| 50 | + dist_from_wheel_url('python', 'https://www.python.org/', session) |
0 commit comments