Example #1
0
def _FindAPIStandardModuleProjectConstructor(version):
    """Find an _APIStandardModuleProject constructor.
    version - The API version to look for 
    """
    if not version in _apiStandardModuleProjectConstructorRegister:
        if version > _currentCSnakeVersion:
            raise APIError("Your CSnake version is too old to compile this code!")
        elif version >= Version([2, 7, 0, "beta"]):
            _apiStandardModuleProjectConstructorRegister[version] = _APIStandardModuleProject_2_7_0
        elif version >= Version([2, 5, 0, "beta"]):
            _apiStandardModuleProjectConstructorRegister[version] = _APIStandardModuleProject_2_5_0
        else:
            # there was no API before this
            raise APIError("Unknown API version")
    return _apiStandardModuleProjectConstructorRegister[version]
Example #2
0
def FindAPI(version):
    """Find a main API.
    version - The API version to look for 
    """
    if not isinstance(version, Version):
        version = Version(version)
    if not version in _apiRegister:
        if version > _currentCSnakeVersion:
            raise APIError("Your CSnake version is too old to compile this code! Demanded API version: %s - CSnake version: %s"
                % (version.GetString(), _currentCSnakeVersion.GetString()))
        elif version >= Version([2, 5, 0, "beta"]):
            _apiRegister[version] = _API_2_5_0(version)
        else:
            # there was no API before this
            raise APIError("Unknown API version: %s" % version.GetString())
    return _apiRegister[version]
Example #3
0
        """
        return self.__version.__cmp__(other.__version)


class _APIVersion_2_5_0(_APIVersion_Base):
    """ Implementation of the version interface for version 2.5.0. """ 
    
    def __init__(self, version):
        """ 
        Constructor.
        version -- The string representing a version number.
        """
        _APIVersion_Base.__init__(self, version)

## Current CSnake version
_currentCSnakeVersion = Version(csnGenerator.version)

################################################

class _API_Base:
    """ Base class for the main API interface. """    
    
    def __init__(self, version):
        """ 
        Constructor.
        version - The version of the API
        """
        self.__version = version
        self.__genericProjectConstructor = _FindAPIGenericProjectConstructor(version)
        self.__standardModuleProjectConstructor = _FindAPIStandardModuleProjectConstructor(version)
        self.__thirdPartyProjectConstructor = _FindAPIThirdPartyProjectConstructor(version)
Example #4
0
 def CreateVersion(self, version):
     """ Create a version object from a String or Array in order to safely compare version numbers. """
     return self.__versionConstructor(Version(version))
Example #5
0
    def testVersion(self):
        """ AboutTests: testVersion. """

        self.assertTrue(Version("1.2.3") < Version("2.3.4"))
        self.assertTrue(Version("2.3.4") > Version("1.2.3"))

        sameVersion = [
            "43.0.0", "43.0", "43", ["43"], [43], [43, 0], [43, 0, 0]
        ]
        for versionA in sameVersion:
            for versionB in sameVersion:
                versionAObj = Version(versionA)
                versionBObj = Version(versionB)
                versionStringPair = (json.dumps(versionA),
                                     json.dumps(versionB))
                self.assertTrue(versionAObj <= versionBObj,
                                msg="Version(%s) should be <= Version(%s)" %
                                versionStringPair)
                self.assertTrue(versionAObj >= versionBObj,
                                msg="Version(%s) should be >= Version(%s)" %
                                versionStringPair)
                self.assertEqual(versionAObj,
                                 versionBObj,
                                 msg="Version(%s) should be == Version(%s)" %
                                 versionStringPair)
                self.assertEqual(
                    hash(versionAObj),
                    hash(versionBObj),
                    msg="hash(Version(%s)) should be == hash(Version(%s))" %
                    versionStringPair)

        lowerVersionList = [
            "43 beta", "43.0.0 beta", ["43", "beta"], [43, "beta"],
            [43, "0", 0, "beta"]
        ]
        higherVersionList = [
            "43", "43.0.0", ["43"], [43, ""], [43], [43, "0", 0]
        ]
        for lowerVersion in lowerVersionList:
            for higherVersion in higherVersionList:
                lowerVersionObj = Version(lowerVersion)
                higherVersionObj = Version(higherVersion)
                versionStringPair = (json.dumps(lowerVersion),
                                     json.dumps(higherVersion))
                self.assertTrue(lowerVersionObj < higherVersionObj,
                                msg="%s should be < %s" % versionStringPair)
                self.assertNotEqual(lowerVersionObj,
                                    higherVersionObj,
                                    msg="%s should be != %s" %
                                    versionStringPair)

        # A list of arguments that should not be accepted by the Version constructor
        invalidConstructorArguments = [
            "", None, [], "beta", [""],
            [3, 2, 3, "dasklgjask-not-in-list-dljggaskdljkgsdl"],
            "dasklgjask-not-in-list-dljggaskdljkgsdl", "1.x.3"
        ]
        for invalidConstructorArgument in invalidConstructorArguments:
            self.assertRaises(Exception, Version, invalidConstructorArgument)
        # Version constructor call without arguments should raise exception
        self.assertRaises(Exception, Version)

        for numDecimals in range(0, 10):
            self.assertEqual(
                Version(
                    Version("1.2.3.4.5.6.7/beta").GetString(
                        numDecimals=numDecimals)),
                Version("1.2.3.4.5.6.7/beta"))

        self.assertEqual(
            Version("1.2 alpha").GetString(numDecimals=3), "1.2.0.0-alpha")
        self.assertEqual(
            Version("1.2 alpha").GetString(numDecimals=2), "1.2.0-alpha")
        self.assertEqual(
            Version("1.2 alpha").GetString(numDecimals=1), "1.2-alpha")
        self.assertEqual(
            Version("1.2 alpha").GetString(numDecimals=0), "1.2-alpha")

        for versionString in [
                "43.0.1", "43.0.1.2-beta", "43.2.1", "47.1.39.144",
                "0.1.2.3.4.5.6"
        ]:
            self.assertEqual(Version(versionString).GetString(), versionString)
            self.assertEqual(
                Version(versionString).GetString(0), versionString)
            self.assertEqual(
                Version(versionString).GetString(1), versionString)
            self.assertEqual(
                Version(versionString).GetString(2), versionString)