@@ -42,10 +42,50 @@ def within_major(currentVersion, targetVersion):
42
42
return int (major ) == int (majorTarget )
43
43
44
44
45
+ def is_gt (currentVersion , targetVersion ):
46
+ matchCurrent = SEMVER_RE .match (currentVersion )
47
+ if not matchCurrent :
48
+ raise ValueError ("invalid semantic version '%s'" % currentVersion )
49
+ matchTarget = SEMVER_RE .match (targetVersion )
50
+ if not matchTarget :
51
+ raise ValueError ("invalid semantic version '%s'" % targetVersion )
52
+
53
+ (major , minor , patch , _ , _ ) = matchCurrent .group (1 , 2 , 3 , 4 , 5 )
54
+ (majorTarget , minorTarget , patchTarget , _ , _ ) = matchTarget .group (1 , 2 , 3 , 4 , 5 )
55
+
56
+ return (
57
+ int (major ) < int (majorTarget )
58
+ or int (minor ) < int (minorTarget )
59
+ or int (patch ) < int (patchTarget )
60
+ )
61
+
62
+
63
+ def is_lt (currentVersion , targetVersion ):
64
+ matchCurrent = SEMVER_RE .match (currentVersion )
65
+ if not matchCurrent :
66
+ raise ValueError ("invalid semantic version '%s'" % currentVersion )
67
+ matchTarget = SEMVER_RE .match (targetVersion )
68
+ if not matchTarget :
69
+ raise ValueError ("invalid semantic version '%s'" % targetVersion )
70
+
71
+ (major , minor , patch , _ , _ ) = matchCurrent .group (1 , 2 , 3 , 4 , 5 )
72
+ (majorTarget , minorTarget , patchTarget , _ , _ ) = matchTarget .group (1 , 2 , 3 , 4 , 5 )
73
+
74
+ return (
75
+ int (major ) > int (majorTarget )
76
+ or int (minor ) > int (minorTarget )
77
+ or int (patch ) > int (patchTarget )
78
+ )
79
+
80
+
45
81
class TestModule (object ):
46
82
"""
47
83
Jinja2 tests for version compare
48
84
"""
49
85
50
86
def tests (self ):
51
- return {"withinMajorVersion" : within_major }
87
+ return {
88
+ "withinMajorVersion" : within_major ,
89
+ "isLesserThan" : is_lt ,
90
+ "isGreaterThan" : is_gt ,
91
+ }
0 commit comments