From d34f3e7b8291ae9ed530f6aa1bdbd119d85c1f3b Mon Sep 17 00:00:00 2001 From: Adam Goldschmidt Date: Wed, 16 Jan 2019 20:29:19 +0200 Subject: [PATCH] fixed test getting empty URL in source (+1 squashed commit) Squashed commits: [b00fb5ba] add test to invalid prepare_pip_source_args and change error to be more descriptive. --- pipenv/utils.py | 9 ++++++--- tests/unit/test_utils.py | 6 ++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/pipenv/utils.py b/pipenv/utils.py index 87f36d1be1..5ed2126483 100644 --- a/pipenv/utils.py +++ b/pipenv/utils.py @@ -206,7 +206,7 @@ def prepare_pip_source_args(sources, pip_args=None): # Add the source to notpip. package_url = sources[0].get("url") if not package_url: - raise PipenvUsageError("Please provide a source URL.") + raise PipenvUsageError("[[source]] section does not contain a URL.") pip_args.extend(["-i", package_url]) # Trust the host if it's not verified. if not sources[0].get("verify_ssl", True): @@ -216,11 +216,14 @@ def prepare_pip_source_args(sources, pip_args=None): # Add additional sources as extra indexes. if len(sources) > 1: for source in sources[1:]: - pip_args.extend(["--extra-index-url", source.get("url")]) + url = source.get("url") + if not url: # not harmless, just don't continue + continue + pip_args.extend(["--extra-index-url", url]) # Trust the host if it's not verified. if not source.get("verify_ssl", True): pip_args.extend( - ["--trusted-host", urllib3_util.parse_url(source.get("url")).host] + ["--trusted-host", urllib3_util.parse_url(url).host] ) return pip_args diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index aeaf3ed36f..ac5eb29bef 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -8,6 +8,7 @@ import pipenv.utils import pythonfinder.utils +from pipenv.exceptions import PipenvUsageError # Pipfile format <-> requirements.txt format. @@ -374,6 +375,11 @@ def test_prepare_pip_source_args(self, sources, expected_args): == expected_args ) + def test_invalid_prepare_pip_source_args(self): + sources = [{}] + with pytest.raises(PipenvUsageError): + pipenv.utils.prepare_pip_source_args(sources, pip_args=None) + @pytest.mark.utils def test_parse_python_version(self): ver = pipenv.utils.parse_python_version("Python 3.6.5\n")