Skip to content

Commit

Permalink
ramp up test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Ryan <dan@danryan.co>
  • Loading branch information
techalchemy committed Aug 20, 2018
1 parent 0df7027 commit c79567a
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 5 deletions.
56 changes: 56 additions & 0 deletions tests/unit/test_dependencies.py
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
6 changes: 1 addition & 5 deletions tests/unit/test_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
import pytest
from first import first
from requirementslib import Requirement

try:
from pathlib import Path
except ImportError:
from pathlib2 import Path
from vistir.compat import Path


UNIT_TEST_DIR = os.path.dirname(os.path.abspath(__file__))
Expand Down
54 changes: 54 additions & 0 deletions tests/unit/test_utils.py
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")

0 comments on commit c79567a

Please sign in to comment.