Skip to content

Commit

Permalink
add test cases for pyspec
Browse files Browse the repository at this point in the history
  • Loading branch information
frostming committed Oct 1, 2019
1 parent d7820cb commit d75f7ba
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/passa/internals/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class Marker(_Marker):
- (C and A or B) and A -> A
"""
def __init__(self, marker=None):
if marker is None:
if not marker:
self._markers = []
else:
super(Marker, self).__init__(marker)
Expand Down
8 changes: 5 additions & 3 deletions src/passa/models/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ def __lt__(self, other):
return operator.lt(self.__key(), other.__key())

def __str__(self):
marker = self.marker & self.pyspecset.as_markers
marker = self.marker
if self.pyspecset:
marker = marker & self.pyspecset
return str(marker)

def __bool__(self):
Expand All @@ -65,7 +67,7 @@ def __nonzero__(self): # Python 2.
def from_tuple(cls, pair):
marker, specset = pair
pyspecs = PySpecs(specset)
marker = Marker()
new_marker = Marker()
if marker:
# Returns a PySpec instance or None
marker_pyversions = get_contained_pyversions(marker)
Expand All @@ -74,7 +76,7 @@ def from_tuple(cls, pair):
# The remainder of the marker, if there is any
cleaned_marker = get_without_pyversion(marker)
if cleaned_marker:
marker = marker & cleaned_marker
new_marker = new_marker & cleaned_marker
metaset = cls()
metaset.marker = marker
metaset.pyspecset = pyspecs
Expand Down
38 changes: 37 additions & 1 deletion tests/unit/test_specifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from packaging.specifiers import SpecifierSet

from passa.internals.specifiers import cleanup_pyspecs
from passa.internals.specifiers import cleanup_pyspecs, PySpecs


@pytest.mark.parametrize("spec, cleaned", [
Expand All @@ -28,3 +28,39 @@
def test_cleanup_pyspecs(spec, cleaned):
cleaned_specifierset = frozenset(s for s in cleaned)
assert cleanup_pyspecs(SpecifierSet(spec)) == cleaned_specifierset


@pytest.mark.parametrize("left, right, result", [
("", ">=3.6", ">=3.6"),
(">=2.7,!=3.0,!=3.1,!=3.2,!=3.3", ">=3.6", "!=3.0,!=3.1,!=3.2,!=3.3,>=3.6"),
("<3.0", ">=3.3", "<3.0,>=3.3"),
("==3.7", ">=3.6", "==3.7,>=3.6")
])
def test_pyspecs_and_operator(left, right, result):
left = PySpecs(SpecifierSet(left))
right = PySpecs(SpecifierSet(right))
rv = left & right
assert str(rv.specifierset) == result


@pytest.mark.parametrize("left, right, result", [
("", ">=3.6", ">=3.6"),
(">=2.7,!=3.0,!=3.1,!=3.2,!=3.3", ">=3.6", "!=3.0,!=3.1,!=3.2,!=3.3,>=2.7"),
("==2.7", ">=3.4", "!=3.0,!=3.1,!=3.2,!=3.3,>=2.7"),
(">=2.6,<3.0", ">=3.3,<3.6", "!=3.0,!=3.1,!=3.2,<3.6,>=2.6"),
("~=3.0", ">=2.7", ">=2.7")
])
def test_pyspecs_or_operator(left, right, result):
left = PySpecs(SpecifierSet(left))
right = PySpecs(SpecifierSet(right))
rv = left | right
assert str(rv.specifierset) == result


@pytest.mark.parametrize("spec, marker", [
("", ""),
(">=3.3,<3.7", 'python_version < "3.7" and python_version >= "3.3"')
])
def test_pyspecs_to_marker(spec, marker):
pyspec = PySpecs(SpecifierSet(spec))
assert str(pyspec) == marker

0 comments on commit d75f7ba

Please sign in to comment.