|
5 | 5 | # Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. |
6 | 6 |
|
7 | 7 | from unittest import TestCase |
| 8 | +import pytest |
8 | 9 |
|
9 | 10 | from univers.version_constraint import VersionConstraint |
10 | 11 | from univers.version_range import GemVersionRange |
11 | 12 | from univers.version_range import PypiVersionRange |
12 | 13 | from univers.version_range import VersionRange |
| 14 | +from univers.version_range import RANGE_CLASS_BY_SCHEMES |
13 | 15 | from univers.versions import PypiVersion |
14 | 16 | from univers.versions import RubygemsVersion |
15 | 17 |
|
@@ -150,3 +152,19 @@ def test_GemVersionRange_from_native_range_with_pessimistic_operator(self): |
150 | 152 | VersionConstraint(comparator=">=", version=RubygemsVersion(string="2.0.8")), |
151 | 153 | VersionConstraint(comparator="<", version=RubygemsVersion(string="2.1")), |
152 | 154 | ) |
| 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