Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests for egg_info_matches #5821

Merged
merged 1 commit into from
Sep 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"),
pradyunsg marked this conversation as resolved.
Show resolved Hide resolved
[
# 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