11
Class representing a version of a software package.
12
Stored internally as a list of subversions, from major to minor.
13
Overloaded comparison operators ought to work sanely.
15
def __init__(self, versionList):
16
self.versionList = versionList
18
def fromString(versionString):
20
Parse a string of the form number.number.number
22
return Version(map(int, versionString.split(".")))
23
fromString = staticmethod(fromString)
26
return ".".join(map(str, self.versionList))
29
tmpList = list(self.versionList)
35
for i in range(len(tmpList)):
40
def __lt__(self, other):
41
return self.__getNum()<other.__getNum()
42
def __le__(self, other):
43
return self.__getNum()<=other.__getNum()
44
def __eq__(self, other):
45
return self.__getNum()==other.__getNum()
46
def __ne__(self, other):
47
return self.__getNum()!=other.__getNum()
48
def __gt__(self, other):
49
return self.__getNum()>other.__getNum()
50
def __ge__(self, other):
51
return self.__getNum()>=other.__getNum()
11
Class representing a version of a software package.
12
Stored internally as a list of subversions, from major to minor.
13
Overloaded comparison operators ought to work sanely.
15
def __init__(self, versionList):
16
self.versionList = versionList
18
def fromString(versionString):
20
Parse a string of the form number.number.number
22
return Version(map(int, versionString.split(".")))
23
fromString = staticmethod(fromString)
26
return ".".join(map(str, self.versionList))
29
tmpList = list(self.versionList)
35
for i in range(len(tmpList)):
40
def __lt__(self, other):
41
return self.__getNum()<other.__getNum()
42
def __le__(self, other):
43
return self.__getNum()<=other.__getNum()
44
def __eq__(self, other):
45
return self.__getNum()==other.__getNum()
46
def __ne__(self, other):
47
return self.__getNum()!=other.__getNum()
48
def __gt__(self, other):
49
return self.__getNum()>other.__getNum()
50
def __ge__(self, other):
51
return self.__getNum()>=other.__getNum()
53
53
class VersionTests(unittest.TestCase):
55
assert Version.fromString("2.0.1") < Version.fromString("2.1.0")
56
assert not Version.fromString("1.4.0") < Version.fromString("1.4.0")
59
assert Version.fromString("2.0.1") <= Version.fromString("2.1.0")
60
assert Version.fromString("1.4.0") <= Version.fromString("1.4.0")
63
assert not Version.fromString("2.0.1") == Version.fromString("2.1.0")
64
assert Version.fromString("1.4.0") == Version.fromString("1.4.0")
67
assert Version.fromString("2.0.1") != Version.fromString("2.1.0")
68
assert not Version.fromString("1.4.0") != Version.fromString("1.4.0")
71
assert Version.fromString("2.1.0") > Version.fromString("2.0.1")
72
assert not Version.fromString("1.4.0") > Version.fromString("1.4.0")
75
assert Version.fromString("2.1.0") >= Version.fromString("2.0.1")
76
assert Version.fromString("1.4.0") >= Version.fromString("1.4.0")
79
assert "2.0.4"==str(Version.fromString("2.0.4"))
81
def testParsing(self):
82
assert Version.fromString("0") == Version([0])
83
assert Version.fromString("0.1") == Version([0, 1])
84
assert Version.fromString("1.4.0") == Version([1, 4, 0])
55
assert Version.fromString("2.0.1") < Version.fromString("2.1.0")
56
assert not Version.fromString("1.4.0") < Version.fromString("1.4.0")
59
assert Version.fromString("2.0.1") <= Version.fromString("2.1.0")
60
assert Version.fromString("1.4.0") <= Version.fromString("1.4.0")
63
assert not Version.fromString("2.0.1") == Version.fromString("2.1.0")
64
assert Version.fromString("1.4.0") == Version.fromString("1.4.0")
67
assert Version.fromString("2.0.1") != Version.fromString("2.1.0")
68
assert not Version.fromString("1.4.0") != Version.fromString("1.4.0")
71
assert Version.fromString("2.1.0") > Version.fromString("2.0.1")
72
assert not Version.fromString("1.4.0") > Version.fromString("1.4.0")
75
assert Version.fromString("2.1.0") >= Version.fromString("2.0.1")
76
assert Version.fromString("1.4.0") >= Version.fromString("1.4.0")
79
assert "2.0.4"==str(Version.fromString("2.0.4"))
81
def testParsing(self):
82
assert Version.fromString("0") == Version([0])
83
assert Version.fromString("0.1") == Version([0, 1])
84
assert Version.fromString("1.4.0") == Version([1, 4, 0])
86
86
if __name__ == "__main__":