Skip to content

Commit dc17ee3

Browse files
committed
Add tests to check from_string & from_spec equality
This will avoid errors like #27 popping up in future Signed-off-by: Hritik Vijay <hritikxx8@gmail.com>
1 parent 4dccdfb commit dc17ee3

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

tests/test_version_range.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download.
66

77
from unittest import TestCase
8+
import pytest
89

910
from univers.version_constraint import VersionConstraint
1011
from univers.version_range import GemVersionRange
1112
from univers.version_range import PypiVersionRange
1213
from univers.version_range import VersionRange
14+
from univers.version_range import RANGE_CLASS_BY_SCHEMES
1315
from univers.versions import PypiVersion
1416
from univers.versions import RubygemsVersion
1517

@@ -150,3 +152,19 @@ def test_GemVersionRange_from_native_range_with_pessimistic_operator(self):
150152
VersionConstraint(comparator=">=", version=RubygemsVersion(string="2.0.8")),
151153
VersionConstraint(comparator="<", version=RubygemsVersion(string="2.1")),
152154
)
155+
156+
157+
@pytest.mark.parametrize("scheme, range_class", RANGE_CLASS_BY_SCHEMES.items())
158+
class TestVersionRangeImplementations:
159+
VERSION_RANGES_BY_SCHEMES = {
160+
"nginx": ["0.8.40+", "0.7.52-0.8.39", "0.9.10", "1.5.0+, 1.4.1+"],
161+
}
162+
163+
def test_from_native_and_from_string_equality(self, scheme, range_class):
164+
if scheme not in self.VERSION_RANGES_BY_SCHEMES:
165+
pytest.skip(f"No {scheme} in VERSION_RANGES_BY_SCHEMES")
166+
167+
for rng in self.VERSION_RANGES_BY_SCHEMES.get(scheme, []):
168+
rng_from_native = range_class.from_native(rng)
169+
rng_from_string = range_class.from_string(rng_from_native.to_string())
170+
assert rng_from_native == rng_from_string

0 commit comments

Comments
 (0)