Skip to content

Commit

Permalink
Use local server for an unit test for lazy wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
McSinyx committed Jul 15, 2020
1 parent db21799 commit da574fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Binary file added tests/data/packages/mypy-0.782-py3-none-any.whl
Binary file not shown.
18 changes: 13 additions & 5 deletions tests/unit/test_network_lazy_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
dist_from_wheel_url,
)
from pip._internal.network.session import PipSession
from tests.lib.requests_mocks import MockResponse
from tests.lib.server import file_response

MYPY_0_782_WHL = (
'https://files.pythonhosted.org/packages/9d/65/'
Expand All @@ -28,6 +28,16 @@ def session():
return PipSession()


@fixture
def mypy_whl_no_range(mock_server, shared_data):
mypy_whl = shared_data.packages / 'mypy-0.782-py3-none-any.whl'
mock_server.set_responses([file_response(mypy_whl)])
mock_server.start()
base_address = 'http://{}:{}'.format(mock_server.host, mock_server.port)
yield "{}/{}".format(base_address, 'mypy-0.782-py3-none-any.whl')
mock_server.stop()


@mark.network
def test_dist_from_wheel_url(session):
"""Test if the acquired distribution contain correct information."""
Expand All @@ -38,12 +48,10 @@ def test_dist_from_wheel_url(session):
assert set(dist.requires(dist.extras)) == MYPY_0_782_REQS


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


@mark.network
Expand Down

0 comments on commit da574fb

Please sign in to comment.