Skip to content

Commit

Permalink
Add full test coverage for the resolver module (#766)
Browse files Browse the repository at this point in the history
  • Loading branch information
atugushev authored Mar 25, 2019
1 parent 5fc955c commit e20ebac
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion piptools/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def resolve(self, max_rounds=10):

# Ignore existing packages
os.environ[str('PIP_EXISTS_ACTION')] = str('i') # NOTE: str() wrapping necessary for Python 2/3 compat
for current_round in count(start=1):
for current_round in count(start=1): # pragma: no branch
if current_round > max_rounds:
raise RuntimeError('No stable configuration of concrete packages '
'could be found for the given constraints after '
Expand Down
34 changes: 34 additions & 0 deletions tests/test_resolver.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest

from piptools.exceptions import UnsupportedConstraint


@pytest.mark.parametrize(
('input', 'expected', 'prereleases'),
Expand Down Expand Up @@ -142,3 +144,35 @@ def test_resolver__allows_unsafe_deps(resolver, from_line, input, expected, prer
output = resolver(input, prereleases=prereleases, allow_unsafe=True).resolve()
output = {str(line) for line in output}
assert output == {str(line) for line in expected}


def test_resolver__max_number_rounds_reached(resolver, from_line):
"""
Resolver should raise an exception if max round has been reached.
"""
input = [from_line('django')]
with pytest.raises(RuntimeError, match='after 0 rounds of resolving'):
resolver(input).resolve(max_rounds=0)


def test_resolver__check_constraints(resolver, from_line):
"""
Resolver should not support non-editable URLs as packages.
"""
input = [
from_line('django'),
from_line('https://example.com/#egg=example')
]
with pytest.raises(UnsupportedConstraint, match='pip-compile does not support URLs as packages'):
resolver(input).resolve()


def test_iter_dependencies(resolver, from_line):
"""
Dependencies should be pinned or editable.
"""
ireq = from_line('django>=1.8')
res = resolver([])

with pytest.raises(TypeError, match='Expected pinned or editable requirement, got django>=1.8'):
next(res._iter_dependencies(ireq))

0 comments on commit e20ebac

Please sign in to comment.