def testGetVersions(self): versions = self._versionDirectory.getVersions() versions.sort() self.assertEquals([ Version("2"), Version("3.5.6.7"), Version("4.8"), Version("6.1.2") ], versions)
def __init__(self, groupId, artifactId=None, version=None, description=None, scope=None): assert (groupId is not None) self._groupId = groupId self._artifactId = artifactId self._version = Version(version) if version is not None else None self._description = description self._scope = scope
def testComparisonWithMajor(self): laterVersion = Version("5") olderVersion = Version("4") assert (olderVersion < laterVersion)
def testConstructorWithMajorMinorBuildAndRelease(self): version = Version("5.6.7.8") self.assertEquals(version, "5.6.7.8")
def testConstructorWithMajorMinorAndBuild(self): version = Version("5.6.7") self.assertEquals(version, "5.6.7")
def testConstructorWithMajorAndMinor(self): version = Version("5.6") self.assertEquals(version, "5.6")
def testEqualityWithMajorMinorBuildAndRelease(self): firstVersion = Version("4.5.6.7") secondVersion = Version("4.5.6.7") self.assertEquals(firstVersion, secondVersion)
class MavenArtifact: """ A Maven artifact, identified by some common attributes """ def __init__(self, groupId, artifactId=None, version=None, description=None, scope=None): assert (groupId is not None) self._groupId = groupId self._artifactId = artifactId self._version = Version(version) if version is not None else None self._description = description self._scope = scope def getGroupId(self): return self._groupId def getArtifactId(self): return self._artifactId def getVersion(self): return self._version def getDescription(self): return self._description def getScope(self): return self._scope def getFileName(self, suffix=None, extension="jar"): """ Returns the basename of the artifact's file, using Maven's conventions. In particular, it will be: <artifactId>-<version>[-<suffix>][.<extension>] """ assert (self._artifactId is not None) assert (self._version is not None) return "{0}-{1}{2}{3}".format( self._artifactId, self._version.getRawString(), "-" + suffix.lstrip("-") if suffix is not None else "", "." + extension.lstrip(".") if extension is not None else "") def getPath(self, suffix=None, extension="jar", separator=os.sep): """ Returns the full path, relative to the root of a Maven repository, of the current artifact, using Maven's conventions. In particular, it will be: <groupId with "." replaced by <separator>>[<separator><artifactId><separator>[<version><separator><basename obtained via getFileName()>]] By default, <separator>=os.sep """ assert (self._groupId is not None) resultComponents = [self._groupId.replace(".", separator)] if self._artifactId is not None: resultComponents.append(self._artifactId) version = self._version if version is not None: resultComponents.append(version.getRawString()) resultComponents.append(self.getFileName(suffix, extension)) return separator.join(resultComponents) def __str__(self): """ An artifact can be shown as a string only if its POM coordinates were all provided """ assert (self._artifactId is not None) assert (self._version is not None) return "{0}:{1}:{2}".format(self._groupId, self._artifactId, self._version.getRawString())
def testComparisonWithRevision(self): laterVersion = Version("5.4.8.3") olderVersion = Version("5.4.8.2") assert (olderVersion < laterVersion)
def testCastingToStringWithAlternateZeros(self): versionString = "0.2.0.4" version = Version(versionString) self.assertEquals(versionString, str(version))
def testCastingToStringWhenOnlyTheRevisionIsNonZero(self): versionString = "0.0.0.4" version = Version(versionString) self.assertEquals(versionString, str(version))
def testRepr(self): rawString = "7.6.0" version = Version(rawString) self.assertEquals(rawString, repr(version))
def testConstructorWhenPassingAnotherVersion(self): version = Version("6.7.8.9") self.assertEquals(version, Version(version))
def testGetLatestVersion(self): latestVersion = self._versionDirectory.getLatestVersion() self.assertEquals(Version("6.1.2"), latestVersion)
def testConstructorWithFullStringParameter(self): version = Version("1.2.3.4") self.assertEquals(1, version.getMajor()) self.assertEquals(2, version.getMinor()) self.assertEquals(3, version.getBuild()) self.assertEquals(4, version.getRevision())
def testComparisonWithMinor(self): laterVersion = Version("5.4") olderVersion = Version("5.3") assert (olderVersion < laterVersion)
def testComparisonWithBuild(self): laterVersion = Version("5.4.8") olderVersion = Version("5.4.7") assert (olderVersion < laterVersion)
def testEqualityOfVersionAndString(self): version = Version("1.2.3.4") self.assertEquals(version, "1.2.3.4")
def testEqualityWithMajor(self): firstVersion = Version("4") secondVersion = Version("4") self.assertEquals(firstVersion, secondVersion)
def testEqualityOfVersionAndStringWhenThereAreTrailingZeros(self): version = Version("1.2") self.assertEquals(version, "1.2") self.assertEquals(version, "1.2.0") self.assertEquals(version, "1.2.0.0")
def testConstructorWithOnlyMajor(self): version = Version("5") self.assertEquals(version, "5")
def testEqualityWithMajorMinorAndBuild(self): firstVersion = Version("4.5.6") secondVersion = Version("4.5.6") self.assertEquals(firstVersion, secondVersion)