Skip to content

Commit 25a25a0

Browse files
committed
Test network.lazy_wheel.dist_from_wheel_url
1 parent e1438d0 commit 25a25a0

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

tests/lib/requests_mocks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def __init__(self, contents):
2828
self.status_code = 200
2929
self.connection = None
3030
self.url = None
31-
self.headers = {}
31+
self.headers = {'Content-Length': len(contents)}
3232
self.history = []
3333

3434
def raise_for_status(self):

tests/unit/test_network_lazy_wheel.py

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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

Comments
 (0)