Skip to content
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
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Compare two native Python versions:

.. code:: python

from univers.version import PypiVersion
from univers.versions import PypiVersion
assert PypiVersion("1.2.3") < PypiVersion("1.2.4")


Expand All @@ -156,7 +156,7 @@ Test if a version is within or outside a version range:

.. code:: python

from univers.version import PypiVersion
from univers.versions import PypiVersion
from univers.version_range import VersionRange

range = VersionRange.from_string("vers:pypi/>=1.2.4")
Expand All @@ -170,7 +170,7 @@ Development

Run these commands, starting from a git clone of https://github.com/nexB/univers ::

$ configure --dev
$ ./configure --dev
$ source venv/bin/active
$ pytest -vvs

Expand Down
4 changes: 2 additions & 2 deletions src/univers/version_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,10 @@ def from_native(cls, string):
anyof_constraints = []
if isinstance(clause, AnyOf):
for allof_clause in clause.clauses:
anyof_constraints.append(get_allof_constraints(cls, allof_clause))
anyof_constraints.extend(get_allof_constraints(cls, allof_clause))
elif isinstance(clause, AllOf):
alloc = get_allof_constraints(cls, clause)
anyof_constraints.append(alloc)
anyof_constraints.extend(alloc)
else:
raise ValueError(f"Unknown clause type: {spec!r}")

Expand Down
4 changes: 2 additions & 2 deletions tests/test_codestyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class BaseTests(unittest.TestCase):
def test_codestyle(self):
args = "venv/bin/black --check -l 100 setup.py etc src tests docs"
args = "venv/bin/black --check -l 100 setup.py src tests"
try:
subprocess.check_output(args.split())
except subprocess.CalledProcessError as e:
Expand All @@ -19,6 +19,6 @@ def test_codestyle(self):
print("===========================================================")
raise Exception(
"Black style check failed; please format the code using:\n"
" python -m black -l 100 setup.py etc src tests docs",
" python -m black -l 100 setup.py src tests",
e.output,
) from e
25 changes: 25 additions & 0 deletions tests/test_version_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
from univers.version_range import PypiVersionRange
from univers.version_range import VersionRange
from univers.version_range import RANGE_CLASS_BY_SCHEMES
from univers.version_range import NpmVersionRange
from univers.versions import PypiVersion
from univers.versions import RubygemsVersion
from univers.versions import SemverVersion


class TestVersionRange(TestCase):
Expand Down Expand Up @@ -209,9 +211,32 @@ def test_PypiVersionRange_raises_ivr_for_invalid_ranges(self):
except InvalidVersionRange as ivre:
assert str(ivre).startswith("Unsupported character")

def test_NpmVersionRange_from_native_with_compatible_with_version_operator(self):
npm_range = "^1.2.9"
expected = NpmVersionRange(
constraints=(
VersionConstraint(comparator=">=", version=SemverVersion(string="1.2.9")),
VersionConstraint(comparator="<", version=SemverVersion(string="2.0.0")),
)
)
version_range = NpmVersionRange.from_native(npm_range)
assert version_range == expected

def test_NpmVersionRange_from_native_with_approximately_equal_to_operator(self):
npm_range = "~3.8.2"
expected = NpmVersionRange(
constraints=(
VersionConstraint(comparator=">=", version=SemverVersion(string="3.8.2")),
VersionConstraint(comparator="<", version=SemverVersion(string="3.9.0")),
)
)
version_range = NpmVersionRange.from_native(npm_range)
assert version_range == expected


VERSION_RANGE_TESTS_BY_SCHEME = {
"nginx": ["0.8.40+", "0.7.52-0.8.39", "0.9.10", "1.5.0+, 1.4.1+"],
Comment thread
keshav-space marked this conversation as resolved.
"npm": ["^1.2.9", "~3.8.2", "5.0.0 - 7.2.3", "2.1 || 2.6", "1.1.2 1.2.2", "<=2.1 >=1.1"],
}


Expand Down