diff --git a/tests/unit/test_finder.py b/tests/unit/test_finder.py index 7a0035f92f6..715861720b2 100644 --- a/tests/unit/test_finder.py +++ b/tests/unit/test_finder.py @@ -1,8 +1,10 @@ import logging +import os.path import sys import pytest from mock import Mock, patch +from pip._vendor.six.moves.urllib import request as urllib_request from pkg_resources import Distribution, parse_version import pip._internal.pep425tags @@ -552,3 +554,53 @@ def test_find_all_candidates_find_links_and_index(data): versions = finder.find_all_candidates('simple') # first the find-links versions then the page versions assert [str(v.version) for v in versions] == ['3.0', '2.0', '1.0', '1.0'] + + +def test_find_link_path(data): + """A find-links path pointing to an HTML file should be used. + """ + find_links = os.path.join(data.packages3, "dinner", "index.html") + finder = PackageFinder.create([find_links], [], [], session=PipSession()) + req = install_req_from_line('dinner', None) + link = finder.find_requirement(req, False) + assert link.url.endswith("Dinner-2.0.tar.gz") + + +def test_find_link_url(data): + """A find-links URL pointing to an HTML file should be used. + """ + find_links = "{}/dinner/index.html".format(data.find_links3.rstrip("/")) + finder = PackageFinder.create([find_links], [], [], session=PipSession()) + req = install_req_from_line('dinner', None) + link = finder.find_requirement(req, False) + assert link.url.endswith("Dinner-2.0.tar.gz") + + +def test_find_link_url_not_exist(caplog, tmpdir, data): + """A find-links file: URL that does not exist should be ignored. + """ + find_links_exist = "{}/dinner/index.html".format( + data.find_links3.rstrip("/"), + ) + find_links_notexist = "file:///{}".format( + urllib_request.pathname2url(tmpdir.join("doesnotexist")).lstrip("/"), + ) + finder = PackageFinder.create( + [find_links_notexist, find_links_exist], [], [], + session=PipSession(), + ) + req = install_req_from_line('dinner', None) + + with caplog.at_level(logging.WARNING): + link = finder.find_requirement(req, False) + + assert link.url.endswith("Dinner-2.0.tar.gz") + + record_tuple = ( + "pip._internal.index", + logging.WARNING, + "Url '{}' is ignored: it is neither a file nor a directory.".format( + find_links_notexist, + ), + ) + assert record_tuple in caplog.record_tuples diff --git a/tests/unit/test_index.py b/tests/unit/test_index.py index ac1e45073d3..c5bce0bbab9 100644 --- a/tests/unit/test_index.py +++ b/tests/unit/test_index.py @@ -1,5 +1,4 @@ import logging -import os.path import sys import pytest @@ -38,38 +37,6 @@ def test_init__py_version_default(self): assert evaluator._py_version == sys.version[:index] -def test_sort_locations_file_expand_dir(data): - """ - Test that a file:// dir gets listdir run with expand_dir - """ - finder = PackageFinder.create([data.find_links], [], session=PipSession()) - files, urls = finder._sort_locations([data.find_links], expand_dir=True) - assert files and not urls, ( - "files and not urls should have been found at find-links url: %s" % - data.find_links - ) - - -def test_sort_locations_file_not_find_link(data): - """ - Test that a file:// url dir that's not a find-link, doesn't get a listdir - run - """ - finder = PackageFinder.create([], [], session=PipSession()) - files, urls = finder._sort_locations([data.index_url("empty_with_pkg")]) - assert urls and not files, "urls, but not files should have been found" - - -def test_sort_locations_non_existing_path(): - """ - Test that a non-existing path is ignored. - """ - finder = PackageFinder.create([], [], session=PipSession()) - files, urls = finder._sort_locations( - [os.path.join('this', 'doesnt', 'exist')]) - assert not urls and not files, "nothing should have been found" - - class TestLink(object): def test_splitext(self):