Skip to content

Commit

Permalink
Test network.lazy_wheel.dist_from_wheel_url
Browse files Browse the repository at this point in the history
  • Loading branch information
McSinyx committed Jun 26, 2020
1 parent e1438d0 commit 25a25a0
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/lib/requests_mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, contents):
self.status_code = 200
self.connection = None
self.url = None
self.headers = {}
self.headers = {'Content-Length': len(contents)}
self.history = []

def raise_for_status(self):
Expand Down
50 changes: 50 additions & 0 deletions tests/unit/test_network_lazy_wheel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from zipfile import BadZipfile

from pip._vendor.pkg_resources import Requirement
from pytest import fixture, mark, raises

from pip._internal.network.lazy_wheel import dist_from_wheel_url
from pip._internal.network.session import PipSession
from tests.lib.requests_mocks import MockResponse

MYPY_0_782_WHL = (
'https://files.pythonhosted.org/packages/9d/65/'
'b96e844150ce18b9892b155b780248955ded13a2581d31872e7daa90a503/'
'mypy-0.782-py3-none-any.whl'
)
MYPY_0_782_REQS = {
Requirement('typed-ast (<1.5.0,>=1.4.0)'),
Requirement('typing-extensions (>=3.7.4)'),
Requirement('mypy-extensions (<0.5.0,>=0.4.3)'),
Requirement('psutil (>=4.0); extra == "dmypy"'),
}


@fixture
def session():
return PipSession()


@mark.network
def test_dist_from_wheel_url(session):
"""Test if the acquired distribution contain correct information."""
dist = dist_from_wheel_url('mypy', MYPY_0_782_WHL, session)
assert dist.key == 'mypy'
assert dist.version == '0.782'
assert dist.extras == ['dmypy']
assert set(dist.requires(dist.extras)) == MYPY_0_782_REQS


@mark.network
def test_dist_from_wheel_url_no_range(session, monkeypatch):
"""Test handling when HTTP range requests are not supported."""
monkeypatch.setattr(session, 'head', lambda *a, **kw: MockResponse(b''))
with raises(RuntimeError):
dist_from_wheel_url('mypy', MYPY_0_782_WHL, session)


@mark.network
def test_dist_from_wheel_url_not_zip(session):
"""Test handling with the given URL does not point to a ZIP."""
with raises(BadZipfile):
dist_from_wheel_url('python', 'https://www.python.org/', session)

0 comments on commit 25a25a0

Please sign in to comment.