mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
Add tests
This commit is contained in:
parent
1d10fca6fc
commit
d4e22ea097
|
@ -113,6 +113,7 @@ class UpdatingDefaultsHelpFormatter(PrettyHelpFormatter):
|
|||
|
||||
|
||||
class CustomOptionParser(optparse.OptionParser):
|
||||
|
||||
def insert_option_group(self, idx, *args, **kwargs):
|
||||
"""Insert an OptionGroup at a given position."""
|
||||
group = self.add_option_group(*args, **kwargs)
|
||||
|
|
15
pip/index.py
15
pip/index.py
|
@ -646,6 +646,8 @@ class PackageFinder(object):
|
|||
try:
|
||||
support_this_python = check_requires_python(link.requires_python)
|
||||
except specifiers.InvalidSpecifier:
|
||||
logger.debug("Package %s has an invalid Requires-Python entry: %s",
|
||||
link.filename, link.requires_python)
|
||||
support_this_python = True
|
||||
|
||||
if not support_this_python:
|
||||
|
@ -841,7 +843,8 @@ class HTMLPage(object):
|
|||
url = self.clean_link(
|
||||
urllib_parse.urljoin(self.base_url, href)
|
||||
)
|
||||
pyrequire = unescape(anchor.get('data-requires-python'))
|
||||
pyrequire = anchor.get('data-requires-python')
|
||||
pyrequire = unescape(pyrequire) if pyrequire else None
|
||||
yield Link(url, self, requires_python=pyrequire)
|
||||
|
||||
_clean_re = re.compile(r'[^a-z0-9$&+,/:;=?@.#%_\\|-]', re.I)
|
||||
|
@ -863,10 +866,11 @@ class Link(object):
|
|||
url:
|
||||
url of the resource pointed to (href of the link)
|
||||
comes_from:
|
||||
<Not sure>
|
||||
instance of HTMLPage where the link was found, or string.
|
||||
requires_python:
|
||||
String containing the `Requires-Python` metadata field, specified
|
||||
in PEP 345.
|
||||
in PEP 345. This may be specified by a data-requires-python
|
||||
attribute in the HTML link tag, as described in PEP 503.
|
||||
"""
|
||||
|
||||
# url can be a UNC windows share
|
||||
|
@ -875,10 +879,7 @@ class Link(object):
|
|||
|
||||
self.url = url
|
||||
self.comes_from = comes_from
|
||||
if not requires_python:
|
||||
self.requires_python = None
|
||||
else:
|
||||
self.requires_python = requires_python
|
||||
self.requires_python = requires_python if requires_python else None
|
||||
|
||||
def __str__(self):
|
||||
if self.requires_python:
|
||||
|
|
|
@ -10,23 +10,18 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
def check_requires_python(requires_python):
|
||||
"""
|
||||
Check if the python version in used match the `requires_python` specifier.
|
||||
Check if the python version in use match the `requires_python` specifier.
|
||||
|
||||
Return `True` if the version of python in use matches the requirement.
|
||||
Return `False` if the version of python in use does not matches the
|
||||
requirement. Raises an InvalidSpecifier if `requires_python` have an
|
||||
invalid format.
|
||||
Returns `True` if the version of python in use matches the requirement.
|
||||
Returns `False` if the version of python in use does not matches the
|
||||
requirement.
|
||||
|
||||
Raises an InvalidSpecifier if `requires_python` have an invalid format.
|
||||
"""
|
||||
if requires_python is None:
|
||||
# The package provides no information
|
||||
return True
|
||||
try:
|
||||
requires_python_specifier = specifiers.SpecifierSet(requires_python)
|
||||
except specifiers.InvalidSpecifier as e:
|
||||
logger.debug(
|
||||
"Package %s has an invalid Requires-Python entry - %s" % (
|
||||
requires_python, e))
|
||||
raise
|
||||
requires_python_specifier = specifiers.SpecifierSet(requires_python)
|
||||
|
||||
# We only use major.minor.micro
|
||||
python_version = version.parse('.'.join(map(str, sys.version_info[:3])))
|
||||
|
|
8
tests/data/indexes/datarequire/fakepackage/index.html
Normal file
8
tests/data/indexes/datarequire/fakepackage/index.html
Normal file
|
@ -0,0 +1,8 @@
|
|||
<html><head><title>Links for fakepackage</title><meta name="api-version" value="2" /></head><body><h1>Links for fakepackage</h1>
|
||||
<a data-requires-python='' href="/fakepackage-1.0.0.tar.gz#md5=00000000000000000000000000000000" rel="internal">fakepackage-1.0.0.tar.gz</a><br/>
|
||||
<a data-requires-python='<2.7' href="/fakepackage-2.6.0.tar.gz#md5=00000000000000000000000000000000" rel="internal">fakepackage-2.6.0.tar.gz</a><br/>
|
||||
<a data-requires-python='>=2.7,<3' href="/fakepackage-2.7.0.tar.gz#md5=00000000000000000000000000000000" rel="internal">fakepackage-2.7.0.tar.gz</a><br/>
|
||||
<a data-requires-python='>=3.3' href="/fakepackage-3.3.0.tar.gz#md5=00000000000000000000000000000000" rel="internal">fakepackage-3.3.0.tar.gz</a><br/>
|
||||
<a data-requires-python='><X.y.z' href="/fakepackage-9.9.9.tar.gz#md5=00000000000000000000000000000000" rel="internal">fakepackage-9.9.9.tar.gz</a><br/>
|
||||
</body></html>
|
||||
|
|
@ -38,10 +38,9 @@ def main(args=None):
|
|||
print('Downloading pending list')
|
||||
projects = all_projects()
|
||||
print('Found %s projects' % len(projects))
|
||||
f = open(pending_fn, 'w')
|
||||
for name in projects:
|
||||
f.write(name + '\n')
|
||||
f.close()
|
||||
with open(pending_fn, 'w') as f:
|
||||
for name in projects:
|
||||
f.write(name + '\n')
|
||||
print('Starting testing...')
|
||||
while os.stat(pending_fn).st_size:
|
||||
_test_packages(output, pending_fn)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import pytest
|
||||
import sys
|
||||
|
||||
import pip.wheel
|
||||
import pip.pep425tags
|
||||
|
@ -365,6 +366,27 @@ def test_finder_only_installs_stable_releases(data):
|
|||
assert link.url == "https://foo/bar-1.0.tar.gz"
|
||||
|
||||
|
||||
def test_finder_only_installs_data_require(data):
|
||||
"""
|
||||
"""
|
||||
|
||||
# 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']
|
||||
if sys.version_info < (2, 7):
|
||||
expected.append('2.6.0')
|
||||
elif (2, 7) < sys.version_info < (3,):
|
||||
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)
|
||||
|
||||
|
||||
def test_finder_installs_pre_releases(data):
|
||||
"""
|
||||
Test PackageFinder finds pre-releases if asked to.
|
||||
|
|
Loading…
Reference in a new issue