2016-07-28 21:11:53 +02:00
|
|
|
import sys
|
2013-08-18 11:59:44 +02:00
|
|
|
|
2017-06-13 14:17:00 +02:00
|
|
|
import pytest
|
|
|
|
from mock import Mock, patch
|
2017-05-16 12:16:30 +02:00
|
|
|
from pkg_resources import Distribution, parse_version
|
2013-08-23 13:12:37 +02:00
|
|
|
|
2017-05-16 12:16:30 +02:00
|
|
|
import pip.pep425tags
|
|
|
|
import pip.wheel
|
|
|
|
from pip.download import PipSession
|
|
|
|
from pip.exceptions import BestVersionAlreadyInstalled, DistributionNotFound
|
|
|
|
from pip.index import (
|
|
|
|
FormatControl, InstallationCandidate, Link, PackageFinder, fmt_ctl_formats
|
|
|
|
)
|
|
|
|
from pip.req import InstallRequirement
|
2011-12-16 18:01:23 +01:00
|
|
|
|
|
|
|
|
2013-08-23 13:12:37 +02:00
|
|
|
def test_no_mpkg(data):
|
2011-12-16 18:01:23 +01:00
|
|
|
"""Finder skips zipfiles with "macosx10" in the name."""
|
2014-05-07 01:25:44 +02:00
|
|
|
finder = PackageFinder([data.find_links], [], session=PipSession())
|
2011-12-16 18:01:23 +01:00
|
|
|
req = InstallRequirement.from_line("pkgwithmpkg")
|
|
|
|
found = finder.find_requirement(req, False)
|
|
|
|
|
|
|
|
assert found.url.endswith("pkgwithmpkg-1.0.tar.gz"), found
|
2012-04-17 01:27:47 +02:00
|
|
|
|
|
|
|
|
2013-08-23 13:12:37 +02:00
|
|
|
def test_no_partial_name_match(data):
|
2012-04-17 01:27:47 +02:00
|
|
|
"""Finder requires the full project name to match, not just beginning."""
|
2014-05-07 01:25:44 +02:00
|
|
|
finder = PackageFinder([data.find_links], [], session=PipSession())
|
2012-04-17 01:27:47 +02:00
|
|
|
req = InstallRequirement.from_line("gmpy")
|
|
|
|
found = finder.find_requirement(req, False)
|
|
|
|
|
|
|
|
assert found.url.endswith("gmpy-1.15.tar.gz"), found
|
2012-09-10 22:04:00 +02:00
|
|
|
|
2013-08-23 13:12:37 +02:00
|
|
|
|
2015-03-07 17:56:14 +01:00
|
|
|
def test_tilde(data):
|
|
|
|
"""Finder can accept a path with ~ in it and will normalize it."""
|
2015-11-25 05:47:36 +01:00
|
|
|
session = PipSession()
|
|
|
|
with patch('pip.index.os.path.exists', return_value=True):
|
|
|
|
finder = PackageFinder(['~/python-pkgs'], [], session=session)
|
2015-03-07 17:56:14 +01:00
|
|
|
req = InstallRequirement.from_line("gmpy")
|
|
|
|
with pytest.raises(DistributionNotFound):
|
|
|
|
finder.find_requirement(req, False)
|
|
|
|
|
|
|
|
|
2013-08-23 13:12:37 +02:00
|
|
|
def test_duplicates_sort_ok(data):
|
2012-09-10 22:04:00 +02:00
|
|
|
"""Finder successfully finds one of a set of duplicates in different
|
|
|
|
locations"""
|
2014-05-07 01:25:44 +02:00
|
|
|
finder = PackageFinder(
|
|
|
|
[data.find_links, data.find_links2],
|
|
|
|
[],
|
|
|
|
session=PipSession(),
|
|
|
|
)
|
2012-09-10 22:04:00 +02:00
|
|
|
req = InstallRequirement.from_line("duplicate")
|
|
|
|
found = finder.find_requirement(req, False)
|
|
|
|
|
|
|
|
assert found.url.endswith("duplicate-1.0.tar.gz"), found
|
2012-09-23 23:58:14 +02:00
|
|
|
|
|
|
|
|
2013-08-23 13:12:37 +02:00
|
|
|
def test_finder_detects_latest_find_links(data):
|
2012-09-23 23:58:14 +02:00
|
|
|
"""Test PackageFinder detects latest using find-links"""
|
|
|
|
req = InstallRequirement.from_line('simple', None)
|
2014-05-07 01:25:44 +02:00
|
|
|
finder = PackageFinder([data.find_links], [], session=PipSession())
|
2012-09-23 23:58:14 +02:00
|
|
|
link = finder.find_requirement(req, False)
|
|
|
|
assert link.url.endswith("simple-3.0.tar.gz")
|
|
|
|
|
|
|
|
|
2014-09-12 23:41:53 +02:00
|
|
|
def test_incorrect_case_file_index(data):
|
|
|
|
"""Test PackageFinder detects latest using wrong case"""
|
|
|
|
req = InstallRequirement.from_line('dinner', None)
|
|
|
|
finder = PackageFinder([], [data.find_links3], session=PipSession())
|
|
|
|
link = finder.find_requirement(req, False)
|
|
|
|
assert link.url.endswith("Dinner-2.0.tar.gz")
|
|
|
|
|
|
|
|
|
2015-01-15 00:53:15 +01:00
|
|
|
@pytest.mark.network
|
2013-08-23 13:12:37 +02:00
|
|
|
def test_finder_detects_latest_already_satisfied_find_links(data):
|
2014-04-30 07:33:04 +02:00
|
|
|
"""Test PackageFinder detects latest already satisfied using find-links"""
|
2012-09-23 23:58:14 +02:00
|
|
|
req = InstallRequirement.from_line('simple', None)
|
2014-03-26 23:24:19 +01:00
|
|
|
# the latest simple in local pkgs is 3.0
|
2012-09-23 23:58:14 +02:00
|
|
|
latest_version = "3.0"
|
|
|
|
satisfied_by = Mock(
|
2014-01-28 15:17:51 +01:00
|
|
|
location="/path",
|
|
|
|
parsed_version=parse_version(latest_version),
|
|
|
|
version=latest_version
|
|
|
|
)
|
2012-09-23 23:58:14 +02:00
|
|
|
req.satisfied_by = satisfied_by
|
2014-05-07 01:25:44 +02:00
|
|
|
finder = PackageFinder([data.find_links], [], session=PipSession())
|
2013-08-18 11:59:44 +02:00
|
|
|
|
|
|
|
with pytest.raises(BestVersionAlreadyInstalled):
|
|
|
|
finder.find_requirement(req, True)
|
2012-09-23 23:58:14 +02:00
|
|
|
|
|
|
|
|
2015-01-15 00:53:15 +01:00
|
|
|
@pytest.mark.network
|
2012-09-23 23:58:14 +02:00
|
|
|
def test_finder_detects_latest_already_satisfied_pypi_links():
|
2014-04-30 07:33:04 +02:00
|
|
|
"""Test PackageFinder detects latest already satisfied using pypi links"""
|
2012-09-23 23:58:14 +02:00
|
|
|
req = InstallRequirement.from_line('initools', None)
|
2014-03-26 23:24:19 +01:00
|
|
|
# the latest initools on pypi is 0.3.1
|
2012-09-23 23:58:14 +02:00
|
|
|
latest_version = "0.3.1"
|
|
|
|
satisfied_by = Mock(
|
2014-01-28 15:17:51 +01:00
|
|
|
location="/path",
|
|
|
|
parsed_version=parse_version(latest_version),
|
2014-02-24 22:52:23 +01:00
|
|
|
version=latest_version,
|
|
|
|
)
|
2012-09-23 23:58:14 +02:00
|
|
|
req.satisfied_by = satisfied_by
|
2014-05-07 01:25:44 +02:00
|
|
|
finder = PackageFinder(
|
|
|
|
[],
|
|
|
|
["http://pypi.python.org/simple"],
|
|
|
|
session=PipSession(),
|
|
|
|
)
|
2013-08-18 11:59:44 +02:00
|
|
|
|
|
|
|
with pytest.raises(BestVersionAlreadyInstalled):
|
|
|
|
finder.find_requirement(req, True)
|
2012-10-12 10:36:05 +02:00
|
|
|
|
2013-04-02 07:44:46 +02:00
|
|
|
|
2013-08-23 13:12:37 +02:00
|
|
|
class TestWheel:
|
2013-06-28 03:08:25 +02:00
|
|
|
|
2014-08-31 01:52:28 +02:00
|
|
|
def test_skip_invalid_wheel_link(self, caplog, data):
|
2013-11-15 01:35:24 +01:00
|
|
|
"""
|
|
|
|
Test if PackageFinder skips invalid wheel filenames
|
|
|
|
"""
|
|
|
|
req = InstallRequirement.from_line("invalid")
|
2014-03-26 23:24:19 +01:00
|
|
|
# data.find_links contains "invalid.whl", which is an invalid wheel
|
2014-05-07 01:25:44 +02:00
|
|
|
finder = PackageFinder(
|
|
|
|
[data.find_links],
|
|
|
|
[],
|
|
|
|
session=PipSession(),
|
|
|
|
)
|
2013-11-15 01:35:24 +01:00
|
|
|
with pytest.raises(DistributionNotFound):
|
|
|
|
finder.find_requirement(req, True)
|
2014-08-31 01:52:28 +02:00
|
|
|
|
|
|
|
assert (
|
2015-04-03 23:20:34 +02:00
|
|
|
"invalid.whl; invalid wheel filename"
|
2017-03-20 16:45:29 +01:00
|
|
|
in caplog.text
|
2014-08-31 01:52:28 +02:00
|
|
|
)
|
2013-11-15 01:35:24 +01:00
|
|
|
|
2013-08-23 13:12:37 +02:00
|
|
|
def test_not_find_wheel_not_supported(self, data, monkeypatch):
|
2013-06-28 03:08:25 +02:00
|
|
|
"""
|
|
|
|
Test not finding an unsupported wheel.
|
|
|
|
"""
|
2014-01-28 15:17:51 +01:00
|
|
|
monkeypatch.setattr(
|
|
|
|
pip.pep425tags,
|
|
|
|
"supported_tags",
|
|
|
|
[('py1', 'none', 'any')],
|
|
|
|
)
|
2013-08-23 13:12:37 +02:00
|
|
|
|
2013-06-28 03:08:25 +02:00
|
|
|
req = InstallRequirement.from_line("simple.dist")
|
2014-05-07 01:25:44 +02:00
|
|
|
finder = PackageFinder(
|
|
|
|
[data.find_links],
|
|
|
|
[],
|
|
|
|
session=PipSession(),
|
|
|
|
)
|
2015-06-15 23:36:59 +02:00
|
|
|
finder.valid_tags = pip.pep425tags.supported_tags
|
2013-08-18 11:59:44 +02:00
|
|
|
|
|
|
|
with pytest.raises(DistributionNotFound):
|
|
|
|
finder.find_requirement(req, True)
|
2013-06-28 03:08:25 +02:00
|
|
|
|
2013-08-23 13:12:37 +02:00
|
|
|
def test_find_wheel_supported(self, data, monkeypatch):
|
2013-06-28 03:08:25 +02:00
|
|
|
"""
|
|
|
|
Test finding supported wheel.
|
|
|
|
"""
|
2014-01-28 15:17:51 +01:00
|
|
|
monkeypatch.setattr(
|
|
|
|
pip.pep425tags,
|
|
|
|
"supported_tags",
|
|
|
|
[('py2', 'none', 'any')],
|
|
|
|
)
|
2013-08-23 13:12:37 +02:00
|
|
|
|
2013-06-28 03:08:25 +02:00
|
|
|
req = InstallRequirement.from_line("simple.dist")
|
2014-05-07 01:25:44 +02:00
|
|
|
finder = PackageFinder(
|
|
|
|
[data.find_links],
|
|
|
|
[],
|
|
|
|
session=PipSession(),
|
|
|
|
)
|
2013-06-28 03:08:25 +02:00
|
|
|
found = finder.find_requirement(req, True)
|
2014-01-28 15:17:51 +01:00
|
|
|
assert (
|
2014-10-09 06:51:14 +02:00
|
|
|
found.url.endswith("simple.dist-0.1-py2.py3-none-any.whl")
|
|
|
|
), found
|
2013-06-28 03:08:25 +02:00
|
|
|
|
2013-08-23 13:12:37 +02:00
|
|
|
def test_wheel_over_sdist_priority(self, data):
|
2013-06-28 03:08:25 +02:00
|
|
|
"""
|
|
|
|
Test wheels have priority over sdists.
|
|
|
|
`test_link_sorting` also covers this at lower level
|
|
|
|
"""
|
|
|
|
req = InstallRequirement.from_line("priority")
|
2014-05-07 01:25:44 +02:00
|
|
|
finder = PackageFinder(
|
|
|
|
[data.find_links],
|
|
|
|
[],
|
|
|
|
session=PipSession(),
|
|
|
|
)
|
2013-06-28 03:08:25 +02:00
|
|
|
found = finder.find_requirement(req, True)
|
|
|
|
assert found.url.endswith("priority-1.0-py2.py3-none-any.whl"), found
|
|
|
|
|
2013-08-23 13:12:37 +02:00
|
|
|
def test_existing_over_wheel_priority(self, data):
|
2013-06-28 03:08:25 +02:00
|
|
|
"""
|
|
|
|
Test existing install has priority over wheels.
|
|
|
|
`test_link_sorting` also covers this at a lower level
|
|
|
|
"""
|
|
|
|
req = InstallRequirement.from_line('priority', None)
|
|
|
|
latest_version = "1.0"
|
|
|
|
satisfied_by = Mock(
|
2014-01-28 15:17:51 +01:00
|
|
|
location="/path",
|
|
|
|
parsed_version=parse_version(latest_version),
|
2014-02-24 22:52:23 +01:00
|
|
|
version=latest_version,
|
|
|
|
)
|
2013-06-28 03:08:25 +02:00
|
|
|
req.satisfied_by = satisfied_by
|
2014-05-07 01:25:44 +02:00
|
|
|
finder = PackageFinder(
|
|
|
|
[data.find_links],
|
|
|
|
[],
|
|
|
|
session=PipSession(),
|
|
|
|
)
|
2013-06-28 03:08:25 +02:00
|
|
|
|
2013-08-18 11:59:44 +02:00
|
|
|
with pytest.raises(BestVersionAlreadyInstalled):
|
|
|
|
finder.find_requirement(req, True)
|
2013-06-28 03:08:25 +02:00
|
|
|
|
|
|
|
def test_link_sorting(self):
|
|
|
|
"""
|
|
|
|
Test link sorting
|
|
|
|
"""
|
|
|
|
links = [
|
2014-07-04 00:56:26 +02:00
|
|
|
InstallationCandidate("simple", "2.0", Link('simple-2.0.tar.gz')),
|
|
|
|
InstallationCandidate(
|
|
|
|
"simple",
|
|
|
|
"1.0",
|
2014-01-28 15:17:51 +01:00
|
|
|
Link('simple-1.0-pyT-none-TEST.whl'),
|
2014-07-04 00:56:26 +02:00
|
|
|
),
|
|
|
|
InstallationCandidate(
|
|
|
|
"simple",
|
|
|
|
'1.0',
|
|
|
|
Link('simple-1.0-pyT-TEST-any.whl'),
|
|
|
|
),
|
|
|
|
InstallationCandidate(
|
|
|
|
"simple",
|
2014-01-28 15:17:51 +01:00
|
|
|
'1.0',
|
2014-07-04 00:56:26 +02:00
|
|
|
Link('simple-1.0-pyT-none-any.whl'),
|
|
|
|
),
|
|
|
|
InstallationCandidate(
|
|
|
|
"simple",
|
|
|
|
'1.0',
|
|
|
|
Link('simple-1.0.tar.gz'),
|
2014-01-28 15:17:51 +01:00
|
|
|
),
|
|
|
|
]
|
2014-05-07 01:25:44 +02:00
|
|
|
finder = PackageFinder([], [], session=PipSession())
|
2015-06-15 23:36:59 +02:00
|
|
|
finder.valid_tags = [
|
|
|
|
('pyT', 'none', 'TEST'),
|
|
|
|
('pyT', 'TEST', 'any'),
|
|
|
|
('pyT', 'none', 'any'),
|
|
|
|
]
|
2015-12-18 21:11:08 +01:00
|
|
|
results = sorted(links,
|
|
|
|
key=finder._candidate_sort_key, reverse=True)
|
|
|
|
results2 = sorted(reversed(links),
|
|
|
|
key=finder._candidate_sort_key, reverse=True)
|
2013-06-28 03:08:25 +02:00
|
|
|
|
|
|
|
assert links == results == results2, results2
|
2012-10-12 10:36:05 +02:00
|
|
|
|
2013-04-02 07:44:46 +02:00
|
|
|
|
2013-08-23 13:12:37 +02:00
|
|
|
def test_finder_priority_file_over_page(data):
|
2012-10-11 06:47:27 +02:00
|
|
|
"""Test PackageFinder prefers file links over equivalent page links"""
|
|
|
|
req = InstallRequirement.from_line('gmpy==1.15', None)
|
2014-01-28 15:17:51 +01:00
|
|
|
finder = PackageFinder(
|
|
|
|
[data.find_links],
|
|
|
|
["http://pypi.python.org/simple"],
|
2014-05-07 01:25:44 +02:00
|
|
|
session=PipSession(),
|
2014-01-28 15:17:51 +01:00
|
|
|
)
|
2015-12-18 20:29:42 +01:00
|
|
|
all_versions = finder.find_all_candidates(req.name)
|
2015-03-12 22:49:39 +01:00
|
|
|
# 1 file InstallationCandidate followed by all https ones
|
|
|
|
assert all_versions[0].location.scheme == 'file'
|
|
|
|
assert all(version.location.scheme == 'https'
|
|
|
|
for version in all_versions[1:]), all_versions
|
|
|
|
|
2012-10-11 06:47:27 +02:00
|
|
|
link = finder.find_requirement(req, False)
|
|
|
|
assert link.url.startswith("file://")
|
|
|
|
|
|
|
|
|
2014-12-30 20:06:54 +01:00
|
|
|
def test_finder_deplink():
|
|
|
|
"""
|
|
|
|
Test PackageFinder with dependency links only
|
|
|
|
"""
|
|
|
|
req = InstallRequirement.from_line('gmpy==1.15', None)
|
|
|
|
finder = PackageFinder(
|
|
|
|
[],
|
|
|
|
[],
|
|
|
|
process_dependency_links=True,
|
|
|
|
session=PipSession(),
|
|
|
|
)
|
|
|
|
finder.add_dependency_links(
|
|
|
|
['https://pypi.python.org/packages/source/g/gmpy/gmpy-1.15.zip'])
|
|
|
|
link = finder.find_requirement(req, False)
|
|
|
|
assert link.url.startswith("https://pypi"), link
|
|
|
|
|
|
|
|
|
2015-01-15 00:53:15 +01:00
|
|
|
@pytest.mark.network
|
2014-08-01 22:20:23 +02:00
|
|
|
def test_finder_priority_page_over_deplink():
|
|
|
|
"""
|
|
|
|
Test PackageFinder prefers page links over equivalent dependency links
|
|
|
|
"""
|
2015-03-12 22:49:39 +01:00
|
|
|
req = InstallRequirement.from_line('pip==1.5.6', None)
|
2014-08-01 22:20:23 +02:00
|
|
|
finder = PackageFinder(
|
|
|
|
[],
|
|
|
|
["https://pypi.python.org/simple"],
|
|
|
|
process_dependency_links=True,
|
|
|
|
session=PipSession(),
|
|
|
|
)
|
2015-03-12 22:49:39 +01:00
|
|
|
finder.add_dependency_links([
|
|
|
|
'https://warehouse.python.org/packages/source/p/pip/pip-1.5.6.tar.gz'])
|
2015-12-18 20:29:42 +01:00
|
|
|
all_versions = finder.find_all_candidates(req.name)
|
2015-03-12 22:49:39 +01:00
|
|
|
# Check that the dependency_link is last
|
|
|
|
assert all_versions[-1].location.url.startswith('https://warehouse')
|
2014-08-01 22:20:23 +02:00
|
|
|
link = finder.find_requirement(req, False)
|
|
|
|
assert link.url.startswith("https://pypi"), link
|
|
|
|
|
|
|
|
|
2012-10-11 07:29:16 +02:00
|
|
|
def test_finder_priority_nonegg_over_eggfragments():
|
|
|
|
"""Test PackageFinder prefers non-egg links over "#egg=" links"""
|
|
|
|
req = InstallRequirement.from_line('bar==1.0', None)
|
|
|
|
links = ['http://foo/bar.py#egg=bar-1.0', 'http://foo/bar-1.0.tar.gz']
|
|
|
|
|
2014-05-07 01:25:44 +02:00
|
|
|
finder = PackageFinder(links, [], session=PipSession())
|
2013-08-16 14:04:27 +02:00
|
|
|
|
|
|
|
with patch.object(finder, "_get_pages", lambda x, y: []):
|
2015-12-18 20:29:42 +01:00
|
|
|
all_versions = finder.find_all_candidates(req.name)
|
2015-03-12 22:49:39 +01:00
|
|
|
assert all_versions[0].location.url.endswith('tar.gz')
|
|
|
|
assert all_versions[1].location.url.endswith('#egg=bar-1.0')
|
|
|
|
|
2013-08-16 14:04:27 +02:00
|
|
|
link = finder.find_requirement(req, False)
|
|
|
|
|
2012-10-11 07:29:16 +02:00
|
|
|
assert link.url.endswith('tar.gz')
|
|
|
|
|
|
|
|
links.reverse()
|
2014-05-07 01:25:44 +02:00
|
|
|
finder = PackageFinder(links, [], session=PipSession())
|
2013-08-16 14:04:27 +02:00
|
|
|
|
|
|
|
with patch.object(finder, "_get_pages", lambda x, y: []):
|
2015-12-18 20:29:42 +01:00
|
|
|
all_versions = finder.find_all_candidates(req.name)
|
2015-03-12 22:49:39 +01:00
|
|
|
assert all_versions[0].location.url.endswith('tar.gz')
|
|
|
|
assert all_versions[1].location.url.endswith('#egg=bar-1.0')
|
2013-08-16 14:04:27 +02:00
|
|
|
link = finder.find_requirement(req, False)
|
|
|
|
|
2012-10-11 07:29:16 +02:00
|
|
|
assert link.url.endswith('tar.gz')
|
|
|
|
|
|
|
|
|
2013-08-23 13:12:37 +02:00
|
|
|
def test_finder_only_installs_stable_releases(data):
|
2013-03-09 17:28:36 +01:00
|
|
|
"""
|
|
|
|
Test PackageFinder only accepts stable versioned releases by default.
|
|
|
|
"""
|
2013-03-12 06:39:17 +01:00
|
|
|
|
2013-03-09 17:28:36 +01:00
|
|
|
req = InstallRequirement.from_line("bar", None)
|
2012-10-11 07:29:16 +02:00
|
|
|
|
2013-03-12 06:39:17 +01:00
|
|
|
# using a local index (that has pre & dev releases)
|
2014-05-07 01:25:44 +02:00
|
|
|
finder = PackageFinder([], [data.index_url("pre")], session=PipSession())
|
2013-03-12 06:39:17 +01:00
|
|
|
link = finder.find_requirement(req, False)
|
|
|
|
assert link.url.endswith("bar-1.0.tar.gz"), link.url
|
|
|
|
|
|
|
|
# using find-links
|
|
|
|
links = ["https://foo/bar-1.0.tar.gz", "https://foo/bar-2.0b1.tar.gz"]
|
2014-05-07 01:25:44 +02:00
|
|
|
finder = PackageFinder(links, [], session=PipSession())
|
2013-08-16 14:04:27 +02:00
|
|
|
|
|
|
|
with patch.object(finder, "_get_pages", lambda x, y: []):
|
|
|
|
link = finder.find_requirement(req, False)
|
|
|
|
assert link.url == "https://foo/bar-1.0.tar.gz"
|
|
|
|
|
2013-03-09 17:28:36 +01:00
|
|
|
links.reverse()
|
2014-05-07 01:25:44 +02:00
|
|
|
finder = PackageFinder(links, [], session=PipSession())
|
2013-08-16 14:04:27 +02:00
|
|
|
|
|
|
|
with patch.object(finder, "_get_pages", lambda x, y: []):
|
|
|
|
link = finder.find_requirement(req, False)
|
|
|
|
assert link.url == "https://foo/bar-1.0.tar.gz"
|
2013-03-09 17:28:36 +01:00
|
|
|
|
|
|
|
|
2016-07-28 21:11:53 +02:00
|
|
|
def test_finder_only_installs_data_require(data):
|
|
|
|
"""
|
2016-07-29 18:41:10 +02:00
|
|
|
Test whether the PackageFinder understand data-python-requires
|
|
|
|
|
|
|
|
This can optionally be exposed by a simple-repository to tell which
|
|
|
|
distribution are compatible with which version of Python by adding a
|
|
|
|
data-python-require to the anchor links.
|
|
|
|
|
|
|
|
See pep 503 for more informations.
|
2016-07-28 21:11:53 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
# using a local index (that has pre & dev releases)
|
|
|
|
finder = PackageFinder([],
|
|
|
|
[data.index_url("datarequire")],
|
|
|
|
session=PipSession())
|
|
|
|
links = finder.find_all_candidates("fakepackage")
|
|
|
|
|
|
|
|
expected = ['1.0.0', '9.9.9']
|
2017-03-18 19:42:32 +01:00
|
|
|
if (2, 7) < sys.version_info < (3,):
|
2016-07-28 21:11:53 +02:00
|
|
|
expected.append('2.7.0')
|
|
|
|
elif sys.version_info > (3, 3):
|
|
|
|
expected.append('3.3.0')
|
|
|
|
|
|
|
|
assert set([str(v.version) for v in links]) == set(expected)
|
|
|
|
|
|
|
|
|
2013-08-23 13:12:37 +02:00
|
|
|
def test_finder_installs_pre_releases(data):
|
2013-03-09 17:28:36 +01:00
|
|
|
"""
|
2013-03-12 06:39:17 +01:00
|
|
|
Test PackageFinder finds pre-releases if asked to.
|
2013-03-09 17:28:36 +01:00
|
|
|
"""
|
2013-03-12 06:39:17 +01:00
|
|
|
|
2014-07-04 00:56:26 +02:00
|
|
|
req = InstallRequirement.from_line("bar", None)
|
2013-03-09 17:28:36 +01:00
|
|
|
|
2013-03-12 06:39:17 +01:00
|
|
|
# using a local index (that has pre & dev releases)
|
2014-07-04 00:56:26 +02:00
|
|
|
finder = PackageFinder(
|
|
|
|
[], [data.index_url("pre")],
|
|
|
|
allow_all_prereleases=True,
|
|
|
|
session=PipSession(),
|
|
|
|
)
|
2013-03-12 06:39:17 +01:00
|
|
|
link = finder.find_requirement(req, False)
|
|
|
|
assert link.url.endswith("bar-2.0b1.tar.gz"), link.url
|
|
|
|
|
|
|
|
# using find-links
|
|
|
|
links = ["https://foo/bar-1.0.tar.gz", "https://foo/bar-2.0b1.tar.gz"]
|
2014-07-04 00:56:26 +02:00
|
|
|
finder = PackageFinder(
|
|
|
|
links, [],
|
|
|
|
allow_all_prereleases=True,
|
|
|
|
session=PipSession(),
|
|
|
|
)
|
2013-08-16 14:04:27 +02:00
|
|
|
|
|
|
|
with patch.object(finder, "_get_pages", lambda x, y: []):
|
|
|
|
link = finder.find_requirement(req, False)
|
|
|
|
assert link.url == "https://foo/bar-2.0b1.tar.gz"
|
|
|
|
|
2013-03-09 17:28:36 +01:00
|
|
|
links.reverse()
|
2014-07-04 00:56:26 +02:00
|
|
|
finder = PackageFinder(
|
|
|
|
links, [],
|
|
|
|
allow_all_prereleases=True,
|
|
|
|
session=PipSession(),
|
|
|
|
)
|
2013-08-16 14:04:27 +02:00
|
|
|
|
|
|
|
with patch.object(finder, "_get_pages", lambda x, y: []):
|
|
|
|
link = finder.find_requirement(req, False)
|
|
|
|
assert link.url == "https://foo/bar-2.0b1.tar.gz"
|
2013-03-09 17:28:36 +01:00
|
|
|
|
|
|
|
|
2013-08-23 13:12:37 +02:00
|
|
|
def test_finder_installs_dev_releases(data):
|
2013-03-12 06:39:17 +01:00
|
|
|
"""
|
|
|
|
Test PackageFinder finds dev releases if asked to.
|
|
|
|
"""
|
|
|
|
|
2014-07-04 00:56:26 +02:00
|
|
|
req = InstallRequirement.from_line("bar", None)
|
2013-03-12 06:39:17 +01:00
|
|
|
|
|
|
|
# using a local index (that has dev releases)
|
2014-07-04 00:56:26 +02:00
|
|
|
finder = PackageFinder(
|
|
|
|
[], [data.index_url("dev")],
|
|
|
|
allow_all_prereleases=True,
|
|
|
|
session=PipSession(),
|
|
|
|
)
|
2013-03-12 06:39:17 +01:00
|
|
|
link = finder.find_requirement(req, False)
|
|
|
|
assert link.url.endswith("bar-2.0.dev1.tar.gz"), link.url
|
|
|
|
|
|
|
|
|
2013-03-09 17:28:36 +01:00
|
|
|
def test_finder_installs_pre_releases_with_version_spec():
|
|
|
|
"""
|
|
|
|
Test PackageFinder only accepts stable versioned releases by default.
|
|
|
|
"""
|
|
|
|
req = InstallRequirement.from_line("bar>=0.0.dev0", None)
|
|
|
|
links = ["https://foo/bar-1.0.tar.gz", "https://foo/bar-2.0b1.tar.gz"]
|
|
|
|
|
2014-05-07 01:25:44 +02:00
|
|
|
finder = PackageFinder(links, [], session=PipSession())
|
2013-08-16 14:04:27 +02:00
|
|
|
|
|
|
|
with patch.object(finder, "_get_pages", lambda x, y: []):
|
|
|
|
link = finder.find_requirement(req, False)
|
|
|
|
assert link.url == "https://foo/bar-2.0b1.tar.gz"
|
2013-03-09 17:28:36 +01:00
|
|
|
|
|
|
|
links.reverse()
|
2014-05-07 01:25:44 +02:00
|
|
|
finder = PackageFinder(links, [], session=PipSession())
|
2013-08-16 14:04:27 +02:00
|
|
|
|
|
|
|
with patch.object(finder, "_get_pages", lambda x, y: []):
|
|
|
|
link = finder.find_requirement(req, False)
|
|
|
|
assert link.url == "https://foo/bar-2.0b1.tar.gz"
|
2013-04-02 07:44:46 +02:00
|
|
|
|
|
|
|
|
2013-10-02 06:33:26 +02:00
|
|
|
class test_link_package_versions(object):
|
|
|
|
|
2014-03-04 00:19:55 +01:00
|
|
|
# patch this for travis which has distribute in its base env for now
|
2014-01-28 15:17:51 +01:00
|
|
|
@patch(
|
|
|
|
'pip.wheel.pkg_resources.get_distribution',
|
|
|
|
lambda x: Distribution(project_name='setuptools', version='0.9')
|
|
|
|
)
|
2013-10-02 06:33:26 +02:00
|
|
|
def setup(self):
|
|
|
|
self.version = '1.0'
|
2013-10-06 06:49:41 +02:00
|
|
|
self.parsed_version = parse_version(self.version)
|
2013-10-02 06:33:26 +02:00
|
|
|
self.search_name = 'pytest'
|
2014-05-07 01:25:44 +02:00
|
|
|
self.finder = PackageFinder(
|
|
|
|
[],
|
|
|
|
[],
|
|
|
|
session=PipSession(),
|
|
|
|
)
|
2013-10-02 06:33:26 +02:00
|
|
|
|
|
|
|
def test_link_package_versions_match_wheel(self):
|
|
|
|
"""Test that 'pytest' archives match for 'pytest'"""
|
|
|
|
|
|
|
|
# TODO: Uncomment these, when #1217 is fixed
|
|
|
|
# link = Link('http:/yo/pytest-1.0.tar.gz')
|
|
|
|
# result = self.finder._link_package_versions(link, self.search_name)
|
|
|
|
# assert result == [(self.parsed_version, link, self.version)], result
|
|
|
|
|
|
|
|
link = Link('http:/yo/pytest-1.0-py2.py3-none-any.whl')
|
|
|
|
result = self.finder._link_package_versions(link, self.search_name)
|
|
|
|
assert result == [(self.parsed_version, link, self.version)], result
|
|
|
|
|
|
|
|
def test_link_package_versions_substring_fails(self):
|
|
|
|
"""Test that 'pytest<something> archives won't match for 'pytest'"""
|
|
|
|
|
|
|
|
# TODO: Uncomment these, when #1217 is fixed
|
|
|
|
# link = Link('http:/yo/pytest-xdist-1.0.tar.gz')
|
|
|
|
# result = self.finder._link_package_versions(link, self.search_name)
|
|
|
|
# assert result == [], result
|
|
|
|
|
|
|
|
# link = Link('http:/yo/pytest2-1.0.tar.gz')
|
|
|
|
# result = self.finder._link_package_versions(link, self.search_name)
|
|
|
|
# assert result == [], result
|
|
|
|
|
|
|
|
link = Link('http:/yo/pytest_xdist-1.0-py2.py3-none-any.whl')
|
|
|
|
result = self.finder._link_package_versions(link, self.search_name)
|
|
|
|
assert result == [], result
|
2015-03-09 00:15:27 +01:00
|
|
|
|
|
|
|
|
2015-03-10 23:13:06 +01:00
|
|
|
def test_get_index_urls_locations():
|
2015-03-09 00:15:27 +01:00
|
|
|
"""Check that the canonical name is on all indexes"""
|
|
|
|
finder = PackageFinder(
|
|
|
|
[], ['file://index1/', 'file://index2'], session=PipSession())
|
2015-03-10 23:13:06 +01:00
|
|
|
locations = finder._get_index_urls_locations(
|
2015-03-27 17:31:05 +01:00
|
|
|
InstallRequirement.from_line('Complex_Name').name)
|
2015-03-09 00:15:27 +01:00
|
|
|
assert locations == ['file://index1/complex-name/',
|
|
|
|
'file://index2/complex-name/']
|
|
|
|
|
|
|
|
|
2015-12-18 20:29:42 +01:00
|
|
|
def test_find_all_candidates_nothing(data):
|
2015-03-09 00:15:27 +01:00
|
|
|
"""Find nothing without anything"""
|
|
|
|
finder = PackageFinder([], [], session=PipSession())
|
2015-12-18 20:29:42 +01:00
|
|
|
assert not finder.find_all_candidates('pip')
|
2015-03-09 00:15:27 +01:00
|
|
|
|
|
|
|
|
2015-12-18 20:29:42 +01:00
|
|
|
def test_find_all_candidates_find_links(data):
|
2015-03-09 00:15:27 +01:00
|
|
|
finder = PackageFinder(
|
|
|
|
[data.find_links], [], session=PipSession())
|
2015-12-18 20:29:42 +01:00
|
|
|
versions = finder.find_all_candidates('simple')
|
2015-03-09 00:15:27 +01:00
|
|
|
assert [str(v.version) for v in versions] == ['3.0', '2.0', '1.0']
|
|
|
|
|
|
|
|
|
2015-12-18 20:29:42 +01:00
|
|
|
def test_find_all_candidates_index(data):
|
2015-03-09 00:15:27 +01:00
|
|
|
finder = PackageFinder(
|
|
|
|
[], [data.index_url('simple')], session=PipSession())
|
2015-12-18 20:29:42 +01:00
|
|
|
versions = finder.find_all_candidates('simple')
|
2015-03-09 00:15:27 +01:00
|
|
|
assert [str(v.version) for v in versions] == ['1.0']
|
|
|
|
|
|
|
|
|
2015-12-18 20:29:42 +01:00
|
|
|
def test_find_all_candidates_find_links_and_index(data):
|
2015-03-09 00:15:27 +01:00
|
|
|
finder = PackageFinder(
|
|
|
|
[data.find_links], [data.index_url('simple')], session=PipSession())
|
2015-12-18 20:29:42 +01:00
|
|
|
versions = finder.find_all_candidates('simple')
|
2015-03-09 00:15:27 +01:00
|
|
|
# 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']
|
2015-04-17 05:03:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_fmt_ctl_matches():
|
|
|
|
fmt = FormatControl(set(), set())
|
|
|
|
assert fmt_ctl_formats(fmt, "fred") == frozenset(["source", "binary"])
|
|
|
|
fmt = FormatControl(set(["fred"]), set())
|
|
|
|
assert fmt_ctl_formats(fmt, "fred") == frozenset(["source"])
|
|
|
|
fmt = FormatControl(set(["fred"]), set([":all:"]))
|
|
|
|
assert fmt_ctl_formats(fmt, "fred") == frozenset(["source"])
|
|
|
|
fmt = FormatControl(set(), set(["fred"]))
|
|
|
|
assert fmt_ctl_formats(fmt, "fred") == frozenset(["binary"])
|
|
|
|
fmt = FormatControl(set([":all:"]), set(["fred"]))
|
|
|
|
assert fmt_ctl_formats(fmt, "fred") == frozenset(["binary"])
|