1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00

fix mirror url parsing and add tests

This commit is contained in:
Marcus Smith 2013-02-19 11:49:19 -08:00
parent 68d380c3ed
commit cf3a5619b0
2 changed files with 26 additions and 3 deletions

View file

@ -363,12 +363,13 @@ class PackageFinder(object):
mirror_urls = set()
for mirror_url in mirrors:
mirror_url = mirror_url.rstrip('/')
# Make sure we have a valid URL
if not ("http://" or "https://" or "file://") in mirror_url:
if not any([mirror_url.startswith(scheme) for scheme in ["http://", "https://", "file://"]]):
mirror_url = "http://%s" % mirror_url
if not mirror_url.endswith("/simple"):
mirror_url = "%s/simple/" % mirror_url
mirror_urls.add(mirror_url)
mirror_url = "%s/simple" % mirror_url
mirror_urls.add(mirror_url + '/')
return list(mirror_urls)

View file

@ -129,3 +129,25 @@ def test_file_index_url_quoting():
def test_inflink_greater():
"""Test InfLink compares greater."""
assert InfLink > Link(object())
def test_mirror_url_formats():
"""
Test various mirror formats get transformed properly
"""
formats = [
'some_mirror',
'some_mirror/',
'some_mirror/simple',
'some_mirror/simple/'
]
for scheme in ['http://', 'https://', 'file://', '']:
result = (scheme or 'http://') + 'some_mirror/simple/'
scheme_formats = ['%s%s' % (scheme, format) for format in formats]
finder = PackageFinder([], [])
urls = finder._get_mirror_urls(mirrors=scheme_formats, main_mirror_url=None)
for url in urls:
assert url == result, str([url, result])