Skip to content

Commit

Permalink
add test to invalid prepare_pip_source_args and change error to be mo…
Browse files Browse the repository at this point in the history
…re descriptive.
  • Loading branch information
AdamGold committed Jan 16, 2019
1 parent ee97e03 commit b00fb5b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pipenv/utils.py
Expand Up @@ -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):
Expand All @@ -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

Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_utils.py
Expand Up @@ -8,6 +8,7 @@

import pipenv.utils
import pythonfinder.utils
from pipenv.exceptions import PipenvUsageError


# Pipfile format <-> requirements.txt format.
Expand Down Expand Up @@ -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):
sources[0].pop('url') # let's erase the URL value from [[source]]
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")
Expand Down

0 comments on commit b00fb5b

Please sign in to comment.