-
Notifications
You must be signed in to change notification settings - Fork 989
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/better version ranges (#14912)
* better version ranges * tests passing better version ranges * Fully implement intersection operator * Add OR support, ensure prerelease support * Bring back None on incompatible * Improve limit condition logic * Use display versions for conditions that change due to prereleases * Fix bug with * range and 0.0.0 pres, add pres tests * Improve verison range comparison * Add handling for spcial non-void check cases --------- Co-authored-by: Rubén Rincón Blanco <rubenrb@jfrog.com>
- Loading branch information
1 parent
79e6d7d
commit da85f6f
Showing
5 changed files
with
186 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
conans/test/unittests/model/version/test_version_range_intersection.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import pytest | ||
|
||
from conans.model.version_range import VersionRange | ||
|
||
values = [ | ||
# single lower limits bounds | ||
['>1.0', ">1.0", ">1.0"], | ||
['>=1.0', ">1.0", ">1.0"], | ||
['>1.0', ">1.1", ">1.1"], | ||
['>1.0', ">=1.1", ">=1.1"], | ||
['>=1.0', ">=1.1", ">=1.1"], | ||
# single upper limits bounds | ||
['<2.0', "<2.0", "<2.0"], | ||
['<=1.0', "<1.0", "<1.0"], | ||
['<2.0', "<2.1", "<2.0"], | ||
['<2.0', "<=1.1", "<=1.1"], | ||
['<=1.0', "<=1.1", "<=1.0"], | ||
# One lower limit, one upper | ||
['>=1.0', "<2.0", ">=1.0 <2.0"], | ||
['>=1', '<=1', ">=1 <=1"], | ||
[">=1", "<=1-", ">=1 <=1-"], | ||
[">=1-", "<=1", ">=1- <=1"], | ||
# Two lower, one upper | ||
['>=1.0', ">1.0 <2.0", ">1.0 <2.0"], | ||
['>=1.0', ">1.1 <2.0", ">1.1 <2.0"], | ||
['>1.0', ">1.1 <=2.0", ">1.1 <=2.0"], | ||
['>1.0', ">=1.1 <=2.0", ">=1.1 <=2.0"], | ||
# one lower, two upper | ||
['<3.0', ">1.0 <2.0", ">1.0 <2.0"], | ||
['<=2.0', ">1.1 <2.0", ">1.1 <2.0"], | ||
['<1.9', ">1.1 <=2.0", ">1.1 <1.9"], | ||
['<=1.9', ">=1.1 <=2.0", ">=1.1 <=1.9"], | ||
# two lower, two upper | ||
['>0.1 <3.0', ">1.0 <2.0", ">1.0 <2.0"], | ||
['>1.2 <=2.0', ">1.1 <2.0", ">1.2 <2.0"], | ||
['>0.1 <1.9', ">1.1 <=2.0", ">1.1 <1.9"], | ||
['>=1.3 <=1.9', ">=1.1 <=2.0", ">=1.3 <=1.9"], | ||
['>=1.0 <=5.0', ">2 <2.5", ">2 <2.5"], | ||
# equal limits | ||
['>=1.0 <3.0', ">0.0 <=1.0", ">=1.0 <=1.0"], | ||
# prereleases | ||
['>1.0', ">1.0-", ">1.0"], | ||
['>=1.0- <3.0', ">=1.0 <3.0-", ">=1.0 <3.0-"], | ||
['>=1.0 <=3.0-', "<3", ">=1.0 <3"], | ||
# OR | ||
['>=1.0 <2.0 || >=2.1 <3', ">=2.3", ">=2.3 <3"], | ||
['>=1.3 <=1.9 || >2.1', ">=1.1 <=2.0 || >=2.1 <2.6", ">=1.3 <=1.9 || >2.1 <2.6"], | ||
['>=1.3 <=1.9 || >=2.2', ">=1.8- <2.3 || >=2.1 <2.6", ">=1.8- <=1.9 || >=2.2 <2.3 || >=2.2 <2.6"], | ||
] | ||
|
||
|
||
@pytest.mark.parametrize("range1, range2, result", values) | ||
def test_range_intersection(range1, range2, result): | ||
r1 = VersionRange(range1) | ||
r2 = VersionRange(range2) | ||
inter = r1.intersection(r2) | ||
result = f"[{result}]" | ||
assert inter.version() == result | ||
inter = r2.intersection(r1) # Test reverse order, result should be the same | ||
assert inter.version() == result | ||
|
||
|
||
incompatible_values = [ | ||
['>1.0', "<1.0"], | ||
['>=1.0', "<1.0"], | ||
['>1.0', "<=1.0"], | ||
['>1.0 <2.0', ">2.0"], | ||
['>1.0 <2.0', "<1.0"], | ||
['>1.0 <2.0', ">3.0 <4.0"], | ||
['<1.0', ">3.0 <4.0"], | ||
['>=1.0 <2 || >2 <3', ">4 <5"] | ||
] | ||
|
||
|
||
@pytest.mark.parametrize("range1, range2", incompatible_values) | ||
def test_range_intersection_incompatible(range1, range2): | ||
r1 = VersionRange(range1) | ||
r2 = VersionRange(range2) | ||
inter = r1.intersection(r2) | ||
assert inter is None | ||
inter = r2.intersection(r1) # Test reverse order, result should be the same | ||
assert inter is None |