Ejemplo n.º 1
0
    def testGetOSPlatform(self, monkeypatch):
        monkeypatch.setattr(sys, 'platform', 'win32')
        monkeypatch.setattr(platform, 'python_compiler', lambda:'WINDOWS')

        monkeypatch.setattr(os, 'environ', {})
        assert str(Platform.GetOSPlatform()) == 'win32'

        monkeypatch.setattr(os, 'environ', {'PROGRAMFILES(X86)':''})
        assert str(Platform.GetOSPlatform()) == 'win64'

        monkeypatch.setattr(sys, 'platform', 'linux2')
        monkeypatch.setattr(platform, 'dist', lambda:['fedora'])
        monkeypatch.setattr(platform, 'machine', lambda:'x86_64')
        assert str(Platform.GetOSPlatform()) == 'redhat64'
Ejemplo n.º 2
0
def IsRunningOn64BitMachine():
    '''
    TODO: BEN-19: Refactor: Move uname stuff to Platform class.

    :rtype: bool
    :returns:
        Returns true if the current machine is a 64 bit machine (regardless of the way this
        executable was compiled).
    '''
    platform_short_name = str(Platform.GetCurrentPlatform())

    # If python is compiled on 64 bits and running, this is a 64 bit machine.
    if platform_short_name == 'win64':
        return True

    # Otherwise,
    elif platform_short_name == 'win32':
        import ctypes
        i = ctypes.c_int()
        process = ctypes.windll.kernel32.GetCurrentProcess()
        ctypes.windll.kernel32.IsWow64Process(process, ctypes.byref(i))
        is64bit = (i.value != 0)
        return is64bit

    # If python is compiled on 64 bits and running, this is a 64 bit machine.
    elif platform_short_name == 'redhat64':
        return True

    else:
        raise AssertionError('Unsupported for: %s' % (platform_short_name, ))
Ejemplo n.º 3
0
def IsUrlEqual(url_or_path_1, url_or_path_2):
    '''
    :param str url_or_path_1:

    :param str url_or_path_2:

    :rtype: bool
    :returns:
        True if Url's are equal.

        Ignores case if url protocol is 'file' in a Windows machine (Windows ignores case for local
        directories).
    '''
    from urlparse import urlparse

    protocol = urlparse(url_or_path_1)[0].lower()
    is_local = protocol == 'file'

    # Ignore case if dealing with a local file in a Windows machine
    if is_local:
        is_windows = Platform.GetCurrentFlavour() == 'windows'
        if is_windows:
            return url_or_path_1.lower() == url_or_path_2.lower()

    # All other cases are case sensitive
    return url_or_path_1 == url_or_path_2
Ejemplo n.º 4
0
    def testCreate(self):
        assert str(Platform.Create('win32')) == 'win32'
        assert str(Platform.Create('i686.win32')) == 'win32'
        assert str(Platform.Create(None)) == str(Platform.GetCurrentPlatform())

        plat = Platform.GetCurrentPlatform()
        assert Platform.Create(plat) is plat

        p = Platform.CreateFromString('win32')
        assert str(p) == 'win32'

        p = Platform.CreateFromSimplePlatform('i686.win32')
        assert str(p) == 'win32'

        with pytest.raises(UnknownPlatform):
            Platform.Create(123)

        with pytest.raises(UnknownPlatform):
            Platform.CreateFromSimplePlatform('UNKNOWN')
Ejemplo n.º 5
0
    def testPlatform(self):
        p = Platform("win", "32")
        assert p.name == "win"
        assert p.bits == "32"
        assert p.debug == False
        assert unicode(p) == "win32"
        assert p.AsString(False) == "win32"
        assert p.AsString(True) == "win32"
        assert p.GetSimplePlatform() == "i686.win32"
        assert p.GetBaseName() == "win32"
        assert p.GetLongName() == "Windows 32-bit"
        assert p.GetPlatformFlavour() == "windows"
        assert p.GetMneumonic() == "w32"

        p = Platform("win", "64", True)
        assert p.name == "win"
        assert p.bits == "64"
        assert p.debug == True
        assert unicode(p) == "win64d"
        assert p.AsString(False) == "win64d"
        assert p.AsString(True) == "win64"
        assert p.GetSimplePlatform() == "amd64.win32"
        assert p.GetBaseName() == "win64"
        assert p.GetLongName() == "Windows 64-bit DEBUG"
        assert p.GetPlatformFlavour() == "windows"
        assert p.GetMneumonic() == "w64"

        with pytest.raises(ValueError):
            p = Platform("win", "INVALID")

        p = Platform("win", "32")
        p.name = "INVALID"
        with pytest.raises(UnknownPlatform):
            p.GetSimplePlatform()

        with pytest.raises(UnknownPlatform):
            p.GetPlatformFlavour()

        with pytest.raises(UnknownPlatform):
            p.GetLongName()

        assert p.GetCurrentFlavour() == p.GetCurrentPlatform().GetPlatformFlavour()
Ejemplo n.º 6
0
    def testGetCurrentPlatform(self, monkeypatch):
        '''
        This is a white box test, but I found it necessary to full coverage.
        '''
        monkeypatch.setattr(sys, 'platform', 'win32')
        monkeypatch.setattr(platform, 'python_compiler', lambda:'WINDOWS')
        assert str(Platform.GetCurrentPlatform()) == 'win32'
        assert str(Platform.GetDefaultPlatform()) == 'win32'

        monkeypatch.setattr(platform, 'python_compiler', lambda:'AMD64')
        assert str(Platform.GetCurrentPlatform()) == 'win64'
        assert str(Platform.GetDefaultPlatform()) == 'win32'

        monkeypatch.setattr(sys, 'platform', 'darwin')
        assert str(Platform.GetCurrentPlatform()) == 'darwin64'
        assert str(Platform.GetDefaultPlatform()) == 'darwin64'

        monkeypatch.setattr(sys, 'platform', 'linux2')
        monkeypatch.setattr(platform, 'dist', lambda:['fedora'])
        monkeypatch.setattr(platform, 'machine', lambda:'x86_64')
        assert str(Platform.GetCurrentPlatform()) == 'redhat64'
        assert str(Platform.GetDefaultPlatform()) == 'redhat64'
Ejemplo n.º 7
0
    def testPlatform(self):
        p = Platform('win', '32')
        assert p.name == 'win'
        assert p.bits == '32'
        assert p.debug == False
        assert unicode(p) == 'win32'
        assert p.AsString(False) == 'win32'
        assert p.AsString(True) == 'win32'
        assert p.GetSimplePlatform() == 'i686.win32'
        assert p.GetBaseName() == 'win32'
        assert p.GetLongName() == 'Windows 32-bit'
        assert p.GetPlatformFlavour() == 'windows'
        assert p.GetMneumonic() == 'w32'

        p = Platform('win', '64', True)
        assert p.name == 'win'
        assert p.bits == '64'
        assert p.debug == True
        assert unicode(p) == 'win64d'
        assert p.AsString(False) == 'win64d'
        assert p.AsString(True) == 'win64'
        assert p.GetSimplePlatform() == 'amd64.win32'
        assert p.GetBaseName() == 'win64'
        assert p.GetLongName() == 'Windows 64-bit DEBUG'
        assert p.GetPlatformFlavour() == 'windows'
        assert p.GetMneumonic() == 'w64'

        with pytest.raises(ValueError):
            p = Platform('INVALID', '32')

        with pytest.raises(ValueError):
            p = Platform('win', 'INVALID')

        p = Platform('win', '32')
        p.name = 'INVALID'
        with pytest.raises(UnknownPlatform):
            p.GetSimplePlatform()

        with pytest.raises(UnknownPlatform):
            p.GetPlatformFlavour()

        with pytest.raises(UnknownPlatform):
            p.GetLongName()

        assert p.GetCurrentFlavour() == p.GetCurrentPlatform().GetPlatformFlavour()
Ejemplo n.º 8
0
 def testGetValidPlatforms(self):
     assert set(Platform.GetValidPlatforms()) == \
         set([
             'darwin32',
             'darwin32d',
             'darwin64',
             'darwin64d',
             'debian32',
             'debian32d',
             'debian64',
             'debian64d',
             'redhat32',
             'redhat32d',
             'redhat64',
             'redhat64d',
             'ubuntu32',
             'ubuntu32d',
             'ubuntu64',
             'ubuntu64d',
             'win32',
             'win32d',
             'win64',
             'win64d',
         ])
Ejemplo n.º 9
0
def platform():
    from ben10.foundation.platform_ import Platform
    return Platform.GetCurrentPlatform()
Ejemplo n.º 10
0
    def testPlatform(self):
        p = Platform('win', '32')
        assert p.name == 'win'
        assert p.bits == '32'
        assert p.debug == False
        assert str(p) == 'win32'
        assert p.AsString(False) == 'win32'
        assert p.AsString(True) == 'win32'
        assert p.GetSimplePlatform() == 'i686.win32'
        assert p.GetBaseName() == 'win32'
        assert p.GetLongName() == 'Windows 32-bit'
        assert p.GetPlatformFlavour() == 'windows'
        assert p.GetMneumonic() == 'w32'

        p = Platform('win', '64', True)
        assert p.name == 'win'
        assert p.bits == '64'
        assert p.debug == True
        assert str(p) == 'win64d'
        assert p.AsString(False) == 'win64d'
        assert p.AsString(True) == 'win64'
        assert p.GetSimplePlatform() == 'amd64.win32'
        assert p.GetBaseName() == 'win64'
        assert p.GetLongName() == 'Windows 64-bit DEBUG'
        assert p.GetPlatformFlavour() == 'windows'
        assert p.GetMneumonic() == 'w64'

        with pytest.raises(ValueError):
            p = Platform('INVALID', '32')

        with pytest.raises(ValueError):
            p = Platform('win', 'INVALID')

        p = Platform('win', '32')
        p.name = 'INVALID'
        with pytest.raises(UnknownPlatform):
            p.GetSimplePlatform()

        with pytest.raises(UnknownPlatform):
            p.GetPlatformFlavour()

        with pytest.raises(UnknownPlatform):
            p.GetLongName()

        assert p.GetCurrentFlavour() == p.GetCurrentPlatform().GetPlatformFlavour()