-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
111 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# -*- coding=utf-8 -*- | ||
import requirementslib | ||
from requirementslib.models.requirements import Requirement | ||
from requirementslib.models.dependencies import ( | ||
get_abstract_dependencies, | ||
get_dependencies_from_json, | ||
get_dependencies_from_index | ||
) | ||
|
||
from pip_shims import InstallRequirement | ||
|
||
|
||
|
||
def test_find_all_matches(): | ||
r = Requirement.from_line("six") | ||
matches = r.find_all_matches() | ||
assert len(matches) > 0 | ||
|
||
|
||
def test_get_dependencies(): | ||
r = Requirement.from_line("requests") | ||
deps = r.get_dependencies() | ||
assert len(deps) > 0 | ||
deps_from_ireq = requirementslib.models.dependencies.get_dependencies(r.as_ireq()) | ||
assert len(deps_from_ireq) > 0 | ||
assert sorted(set(deps_from_ireq)) == sorted(set(deps)) | ||
|
||
|
||
def get_abstract_deps(): | ||
r = Requirement.from_line("requests") | ||
deps = [InstallRequirement.from_line(d) for d in r.get_dependencies()] | ||
abstract_deps = r.get_abstract_dependencies() | ||
req_abstract_dep = requirementslib.models.dependencies.AbstractDependency.from_requirement(r) | ||
assert r.abstract_dep == req_abstract_dep | ||
assert len(abstract_deps) > 0 | ||
deps_from_ireqs = get_abstract_dependencies(deps, parent=r) | ||
assert len(deps_from_ireqs) > 0 | ||
assert sorted(set(deps_from_ireqs)) == sorted(set(abstract_deps)) | ||
|
||
|
||
def test_get_deps_from_json(): | ||
r = Requirement.from_line("requests==2.19.1") | ||
deps = get_dependencies_from_json(r.as_ireq()) | ||
assert len(deps) > 0 | ||
|
||
|
||
def test_get_deps_from_index(): | ||
r = Requirement.from_line("requests==2.19.1") | ||
deps = get_dependencies_from_index(r.as_ireq()) | ||
assert len(deps) > 0 | ||
|
||
|
||
def test_get_editable_from_index(): | ||
r = InstallRequirement.from_editable("git+https://github.com/requests/requests.git#egg=requests[security]") | ||
deps = get_dependencies_from_index(r) | ||
assert len(deps) > 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# -*- coding=utf-8 -*- | ||
from requirementslib.models import utils | ||
|
||
|
||
def test_filter_none(): | ||
assert utils.filter_none("abc", "") == False | ||
assert utils.filter_none("abc", None) == False | ||
assert utils.filter_none("abc", []) == False | ||
assert utils.filter_none("abc", "asdf") == True | ||
|
||
|
||
def test_init_requirement(): | ||
req = utils.init_requirement("requests[security]") | ||
assert req.name == "requests" | ||
assert req.extras == ("security",) | ||
req = utils.init_requirement("requests[security,insecurity]") | ||
assert sorted(req.extras) == ["insecurity", "security"] | ||
req = utils.init_requirement("requests[security,insecurity]>=2.19.1") | ||
assert req.specifier | ||
assert req.revision is None | ||
assert req.vcs is None | ||
assert req.path is None | ||
|
||
|
||
def test_extras_to_string(): | ||
assert utils.extras_to_string("[security,insecurity]") == "[security,insecurity]" | ||
assert utils.extras_to_string(["security", "insecurity"]) == "[insecurity,security]" | ||
assert utils.extras_to_string(["security"]) == "[security]" | ||
|
||
|
||
def test_build_vcs_link(): | ||
link = utils.build_vcs_link("git", "https://github.com/sarugaku/plette.git", name="passa", ref="master", subdirectory="subdir", extras="validation") | ||
assert link.url == "git+https://github.com/sarugaku/plette.git@master#egg=passa[validation]&subdirectory=subdir" | ||
|
||
|
||
def test_strip_ssh_from_git_url(): | ||
url = "git+ssh://git@github.com/sarugaku/passa.git" | ||
url_no_ssh = "git+git@github.com/sarugaku/passa.git" | ||
assert utils.strip_ssh_from_git_uri(url) == url_no_ssh | ||
assert utils.add_ssh_scheme_to_git_uri(url_no_ssh) == url | ||
|
||
|
||
def test_split_markers_from_line(): | ||
line = "test_requirement; marker=='something'" | ||
assert utils.split_markers_from_line(line) == ("test_requirement", "marker=='something'") | ||
line = "test_requirement" | ||
assert utils.split_markers_from_line(line) == ("test_requirement", None) | ||
|
||
|
||
def test_split_vcs_method_from_uri(): | ||
url = "git+https://github.com/sarugaku/plette.git" | ||
assert utils.split_vcs_method_from_uri(url) == ("git", "https://github.com/sarugaku/plette.git") | ||
url = "https://github.com/sarugaku/plette.git" | ||
assert utils.split_vcs_method_from_uri(url) == (None, "https://github.com/sarugaku/plette.git") |