diff options
author | Marcus Smith <qwcode@gmail.com> | 2013-02-19 11:49:19 -0800 |
---|---|---|
committer | Marcus Smith <qwcode@gmail.com> | 2013-02-19 11:49:19 -0800 |
commit | cf3a5619b0791bf4be42d8ec4816799807ef05a6 (patch) | |
tree | 6a64e174dbff26e7fcff0cf5a27ace21a65dd9e0 | |
parent | 68d380c3eda7360022e19caee441a9da2406f4bd (diff) | |
download | pip-cf3a5619b0791bf4be42d8ec4816799807ef05a6.tar.gz |
fix mirror url parsing and add tests
-rw-r--r-- | pip/index.py | 7 | ||||
-rw-r--r-- | tests/test_index.py | 22 |
2 files changed, 26 insertions, 3 deletions
diff --git a/pip/index.py b/pip/index.py index d42906fdc..ef7e856db 100644 --- a/pip/index.py +++ b/pip/index.py @@ -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) diff --git a/tests/test_index.py b/tests/test_index.py index 48a18013a..2abe296ae 100644 --- a/tests/test_index.py +++ b/tests/test_index.py @@ -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]) + + + |