Skip to content

Commit

Permalink
split test into two
Browse files Browse the repository at this point in the history
  • Loading branch information
popravich committed Oct 2, 2018
1 parent 5295d8b commit 290e3d5
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions tests/unit/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from pip._internal.download import PipSession
from pip._internal.index import (
HTMLPage, Link, PackageFinder, _determine_base_url, egg_info_matches,
Link, PackageFinder, _determine_base_url, _get_html_page, egg_info_matches,
)


Expand Down Expand Up @@ -194,21 +194,26 @@ def test_egg_info_matches(egg_info, search_name, expected):
assert version == expected


@pytest.mark.parametrize(
('exception', 'message'),
[
(requests.HTTPError, 'Http error'),
(requests.exceptions.RetryError, 'Retry error'),
],
)
def test_request_retries(exception, message, caplog):
def test_request_http_error(caplog):
caplog.set_level(logging.DEBUG)
link = Link('http://localhost')
session = Mock(PipSession)
session.get.return_value = resp = Mock()
resp.raise_for_status.side_effect = exception(message)
assert HTMLPage.get_page(link, session=session) is None
resp.raise_for_status.side_effect = requests.HTTPError('Http error')
assert _get_html_page(link, session=session) is None
assert (
'Could not fetch URL http://localhost: Http error - skipping'
in caplog.text
)


def test_request_retries(caplog):
caplog.set_level(logging.DEBUG)
link = Link('http://localhost')
session = Mock(PipSession)
session.get.side_effect = requests.exceptions.RetryError('Retry error')
assert _get_html_page(link, session=session) is None
assert (
'Could not fetch URL http://localhost: %s - skipping' % message
'Could not fetch URL http://localhost: Retry error - skipping'
in caplog.text
)

0 comments on commit 290e3d5

Please sign in to comment.