def _assert_version_equal(self, v1, v2): V1 = Version(v1) V2 = Version(v2) # test Version equal Version assert V1 == V2, \ "%s != %s" % (V1, V2) assert V2 == V1, \ "%s != %s" % (V2, V1) # test str equal Version assert v1 == V2, \ "%s != %s" % (v1, V2) assert v2 == V1, \ "%s != %s" % (v2, V1) # test Version equal str assert V1 == v2, \ "%s != %s" % (V1, v2) assert V2 == v1, \ "%s != %s" % (V2, v1)
def _assert_version_order(self, v1, v2): V1 = Version(v1) V2 = Version(v2) # Version <-> Version order assert V1 < V2, \ "%s >= %s" % (V1._parsed, V2._parsed) assert V2 > V1, \ "%s >= %s" % (V2._parsed, V1._parsed) # Version <-> str order assert V1 < v2, \ "%s >= %s" % (V1._parsed, v2) assert V2 > v1, \ "%s >= %s" % (V2._parsed, v1) # str <-> Version order assert v1 < V2, \ "%s >= %s" % (v1, V2._parsed) assert v2 > V1, \ "%s >= %s" % (v2, V1._parsed)
def test_from_string(self): test_pairs = ( # weird versions (".1", (0, 1)), ("-1", ((1,),)), # test some major.minor.tiny parsing ("1", (1,)), ("1.0", (1,)), ("1.0.0", (1,)), ("1.0.0.0", (1,)), ("11", (11,)), ("11.0", (11,)), ("1-1", (1, (1,))), ("1-1-1", (1, (1, (1,)))), (" 1 ", (1,)), # test qualifeirs ("1.0-ALPHA", (1, ("alpha",))), ("1-alpha", (1, ("alpha",))), ("1.0ALPHA", (1, ("alpha",))), ("1-alpha", (1, ("alpha",))), ("1.0-A", (1, ("a",))), ("1-a", (1, ("a",))), ("1.0A", (1, ("a",))), ("1a", (1, ("a",))), ("1.0-BETA", (1, ("beta",))), ("1-beta", (1, ("beta",))), ("1.0-B", (1, ("b",))), ("1-b", (1, ("b",))), ("1.0B", (1, ("b",))), ("1b", (1, ("b",))), ("1.0-MILESTONE", (1, ("milestone",))), ("1.0-milestone", (1, ("milestone",))), ("1-M", (1, ("m",))), ("1.0-m", (1, ("m",))), ("1M", (1, ("m",))), ("1m", (1, ("m",))), ("1.0-RC", (1, ("rc",))), ("1-rc", (1, ("rc",))), ("1.0-SNAPSHOT", (1, ("snapshot",))), ("1.0-snapshot", (1, ("snapshot",))), ("1-SP", (1, ("sp",))), ("1.0-sp", (1, ("sp",))), ("1-GA", (1,)), ("1-ga", (1,)), ("1.0-FINAL", (1,)), ("1-final", (1,)), ("1.0-CR", (1, ("rc",))), ("1-cr", (1, ("rc",))), # test some transistion ("1.0-alpha1", (1, ("alpha", (1,)))), ("1.0-alpha2", (1, ("alpha", (2,)))), ("1.0.0alpha1", (1, ("alpha", (1,)))), ("1.0-beta1", (1, ("beta", (1,)))), ("1-beta2", (1, ("beta", (2,)))), ("1.0.0beta1", (1, ("beta", (1,)))), ("1.0-BETA1", (1, ("beta", (1,)))), ("1-BETA2", (1, ("beta", (2,)))), ("1.0.0BETA1", (1, ("beta", (1,)))), ("1.0-milestone1", (1, ("milestone", (1,)))), ("1.0-milestone2", (1, ("milestone", (2,)))), ("1.0.0milestone1", (1, ("milestone", (1,)))), ("1.0-MILESTONE1", (1, ("milestone", (1,)))), ("1.0-milestone2", (1, ("milestone", (2,)))), ("1.0.0MILESTONE1", (1, ("milestone", (1,)))), ("1.0-alpha2snapshot", (1, ("alpha", (2, ("snapshot",))))), ) for test, expected in test_pairs: v = Version(test) assert v._parsed == expected, \ "Version(%s) == %s, want %s" % (test, v._parsed, expected)
def test_contains(self): test_pairs = (("2.0.5", True), ("2.0.4", True), ("[2.0.5]", True), ("[2.0.6,)", False), ("[2.0.6]", False), ("2.0,2.1]", True), ("[2.0,2.0.3]", False), ("[2.0,2.0.5]", True), ("[2.0,2.0.5)", False),) v = Version("2.0.5") for spec, expected in test_pairs: vr = VersionRange(spec) assert (v in vr) == expected assert ("2.0.5" in vr) == expected assert VersionRange("2.0.5") in \ VersionRange("[2.0,3.0)") assert VersionRange("[2.0.5]") not in \ VersionRange("[2.0,3.0)")
def test_match_versions(self): versions = [Version("0.1"), Version("1.0"), Version("1.1"), Version("2.0"), Version("2.1")] vr = VersionRange("(1.0,2.0]") assert vr.match_version(versions) == "2.0" assert vr.match_version(versions[:3]) == "1.1"
def test_fromversion(self): v = Version("1.0") vr = VersionRange.from_version(v) assert vr.version == v
def test_long_version(self): vr = VersionRange("[5.0.9.0,5.0.10.0)") assert Version("5.0.9.0") in vr assert "5.0.9.0" in vr
def test_compare_errors(self): v = Version("1.0") self.assertRaises(RuntimeError, v._compare, v, 1.0) self.assertRaises(RuntimeError, v._int_compare, v, 1.0) self.assertRaises(RuntimeError, v._list_compare, v, 1.0) self.assertRaises(RuntimeError, v._string_compare, v, 1.0)
def test_compare(self): assert 1 < Version("1.0") assert VersionRange("1.0") == Version("1.0")