Skip to content

Commit

Permalink
Merge pull request #5821 from uranusjr/htmlpage-clean
Browse files Browse the repository at this point in the history
Add unit tests for egg_info_matches
  • Loading branch information
cjerdonek committed Sep 30, 2018
2 parents 773f161 + 00c043d commit 5dd9f5b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/5821.trivial
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add unit tests for egg_info_matches.
34 changes: 33 additions & 1 deletion tests/unit/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
from pip._vendor import html5lib

from pip._internal.download import PipSession
from pip._internal.index import Link, PackageFinder, _determine_base_url
from pip._internal.index import (
Link, PackageFinder, _determine_base_url, egg_info_matches,
)


def test_sort_locations_file_expand_dir(data):
Expand Down Expand Up @@ -158,3 +160,33 @@ def test_get_formatted_locations_basic_auth():

result = finder.get_formatted_locations()
assert 'user' not in result and 'pass' not in result


@pytest.mark.parametrize(
("egg_info", "search_name", "expected"),
[
# Trivial.
("pip-18.0", "pip", "18.0"),
("pip-18.0", None, "18.0"),
# Non-canonical names.
("Jinja2-2.10", "jinja2", "2.10"),
("jinja2-2.10", "Jinja2", "2.10"),
# Ambiguous names. Should be smart enough if the package name is
# provided, otherwise make a guess.
("foo-2-2", "foo", "2-2"),
("foo-2-2", "foo-2", "2"),
("foo-2-2", None, "2-2"),
("im-valid", None, "valid"),
# Invalid names.
("invalid", None, None),
("im_invalid", None, None),
("the-package-name-8.19", "does-not-match", None),
],
)
def test_egg_info_matches(egg_info, search_name, expected):
link = None # Only used for reporting.
version = egg_info_matches(egg_info, search_name, link)
assert version == expected

0 comments on commit 5dd9f5b

Please sign in to comment.