-
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathtest_version_constraint.py
More file actions
98 lines (88 loc) · 2.85 KB
/
Copy pathtest_version_constraint.py
File metadata and controls
98 lines (88 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#
# Copyright (c) nexB Inc. and others.
# SPDX-License-Identifier: Apache-2.0
#
# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download.
import pytest
from univers import versions
from univers.version_constraint import VersionConstraint
@pytest.mark.parametrize(
"version, spec, expected",
[
("2.7", "<=3.4", True),
("2.7.1", "<=3.4", True),
("2.7.1rc1", "<=3.4", True),
("2.7.15", "<=3.4", True),
("2.7.15rc1", "<=3.4", True),
("2.7", ">=3.4", False),
("2.7.1", ">=3.4", False),
("2.7.1rc1", ">=3.4", False),
("2.7.15", ">=3.4", False),
("2.7.15rc1", ">=3.4", False),
("0.0.0", ">=1.0.0", False),
("1.2.3", ">=1.0.0", True),
("1.2.3b1", ">=1.0.0", True),
("1.0.1b1", ">=1.0.0", True),
("1.0.0b1", ">=1.0.0", False),
("1.0.0b1", ">=1.0.0b1", True),
],
)
def test_pypi_comparison(version, spec, expected):
version = versions.PypiVersion(version)
constraint = VersionConstraint.from_string(
string=spec,
version_class=versions.PypiVersion,
)
assert (version in constraint) is expected
@pytest.mark.parametrize(
"version, spec, expected",
[
("2.7.1", "<=3.4.3", True),
("1.1.0", ">1.0.0", True),
("2.0.0", "<=2.0.0", True),
("1.9999.9999", "<=2.0.0", True),
("0.2.9", "<=2.0.0", True),
("1.9999.9999", "<2.0.0", True),
("0.1.1-alpha", ">=0.1.1-beta", False),
("1.0.0+20130313144700", "=1.0.0+9999999999", False),
],
)
def test_semver_comparison(version, spec, expected):
version = versions.SemverVersion(version)
constraint = VersionConstraint.from_string(
string=spec,
version_class=versions.SemverVersion,
)
assert (version in constraint) is expected
@pytest.mark.parametrize(
"original, inverted",
[
(">2.7.1", "<=2.7.1"),
("!=1.1.0", "=1.1.0"),
("=2.0.0", "!=2.0.0"),
("<=0.9999.9999", ">0.9999.9999"),
(">=0.2.9", "<0.2.9"),
("<1.9999.9999", ">=1.9999.9999"),
("*", None),
],
)
def test_invert_opertaion(original, inverted):
constraint = VersionConstraint.from_string(
string=original,
version_class=versions.SemverVersion,
)
if inverted:
inverted_constraint = VersionConstraint.from_string(
string=inverted,
version_class=versions.SemverVersion,
)
assert constraint.invert() == inverted_constraint
else:
assert constraint.invert() is None
@pytest.mark.parametrize("spec", ["<<2.3", ">>2.3"])
def test_invalid_vers_comparator_prefixes(spec):
with pytest.raises(ValueError, match="Unknown comparator"):
VersionConstraint.from_string(
string=spec,
version_class=versions.SemverVersion,
)