Skip to content

Add end-to-end tests to prepare for PackageFinder location sorting rewrite #5849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions tests/unit/test_finder.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
33 changes: 0 additions & 33 deletions tests/unit/test_index.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import os.path
import sys

import pytest
Expand Down Expand Up @@ -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):
Expand Down