Exemple #1
0
 def test_isKnown(self):
     """
     L{Platform.isKnown} returns a boolean indicating whether this is one of
     the L{runtime.knownPlatforms}.
     """
     platform = Platform()
     self.assertTrue(platform.isKnown())
 def test_noCGroups(self):
     """
     If the platform is Linux, and the cgroups file in C{/proc} does not
     exist, C{isDocker()} returns L{False}
     """
     platform = Platform(None, 'linux')
     self.assertFalse(platform.isDocker(_initCGroupLocation="fakepath"))
Exemple #3
0
 def test_isKnown(self):
     """
     L{Platform.isKnown} returns a boolean indicating whether this is one of
     the L{runtime.knownPlatforms}.
     """
     platform = Platform()
     self.assertTrue(platform.isKnown())
Exemple #4
0
 def test_noCGroups(self):
     """
     If the platform is Linux, and the cgroups file in C{/proc} does not
     exist, C{isDocker()} returns L{False}
     """
     platform = Platform(None, 'linux')
     self.assertFalse(platform.isDocker(_initCGroupLocation="fakepath"))
Exemple #5
0
 def test_isMacOSXConsistency(self):
     """
     L{Platform.isMacOSX} can only return C{True} if L{Platform.getType}
     returns C{'posix'}.
     """
     platform = Platform()
     if platform.isMacOSX():
         self.assertEqual(platform.getType(), 'posix')
Exemple #6
0
 def test_isMacOSXConsistency(self):
     """
     L{Platform.isMacOSX} can only return C{True} if L{Platform.getType}
     returns C{'posix'}.
     """
     platform = Platform()
     if platform.isMacOSX():
         self.assertEqual(platform.getType(), 'posix')
Exemple #7
0
 def test_isLinuxConsistency(self):
     """
     L{Platform.isLinux} can only return C{True} if L{Platform.getType}
     returns C{'posix'} and L{sys.platform} starts with C{"linux"}.
     """
     platform = Platform()
     if platform.isLinux():
         self.assertTrue(sys.platform.startswith("linux"))
Exemple #8
0
 def test_isLinuxConsistency(self):
     """
     L{Platform.isLinux} can only return C{True} if L{Platform.getType}
     returns C{'posix'} and L{sys.platform} starts with C{"linux"}.
     """
     platform = Platform()
     if platform.isLinux():
         self.assertTrue(sys.platform.startswith("linux"))
Exemple #9
0
 def test_isMacOSX(self):
     """
     If a system platform name is supplied to L{Platform}'s initializer, it
     is used to determine the result of L{Platform.isMacOSX}, which returns
     C{True} for C{"darwin"}, C{False} otherwise.
     """
     self.assertTrue(Platform(None, 'darwin').isMacOSX())
     self.assertFalse(Platform(None, 'linux2').isMacOSX())
     self.assertFalse(Platform(None, 'win32').isMacOSX())
Exemple #10
0
 def test_isWinNT(self):
     """
     L{Platform.isWinNT} can return only C{False} or C{True} and can not
     return C{True} if L{Platform.getType} is not C{"win32"}.
     """
     platform = Platform()
     isWinNT = platform.isWinNT()
     self.assertIn(isWinNT, (False, True))
     if platform.getType() != "win32":
         self.assertEqual(isWinNT, False)
Exemple #11
0
 def test_isWinNTDeprecated(self):
     """
     L{Platform.isWinNT} is deprecated in favor of L{platform.isWindows}.
     """
     platform = Platform()
     platform.isWinNT()
     warnings = self.flushWarnings([self.test_isWinNTDeprecated])
     self.assertEqual(len(warnings), 1)
     self.assertEqual(warnings[0]['message'],
                      self.isWinNTDeprecationMessage)
Exemple #12
0
 def test_isWinNT(self):
     """
     L{Platform.isWinNT} can return only C{False} or C{True} and can not
     return C{True} if L{Platform.getType} is not C{"win32"}.
     """
     platform = Platform()
     isWinNT = platform.isWinNT()
     self.assertIn(isWinNT, (False, True))
     if platform.getType() != "win32":
         self.assertEqual(isWinNT, False)
Exemple #13
0
 def test_isVistaConsistency(self):
     """
     Verify consistency of L{Platform.isVista}: it can only be C{True} if
     L{Platform.isWinNT} and L{Platform.isWindows} are C{True}.
     """
     platform = Platform()
     if platform.isVista():
         self.assertTrue(platform.isWinNT())
         self.assertTrue(platform.isWindows())
         self.assertFalse(platform.isMacOSX())
Exemple #14
0
 def test_isWinNT(self):
     """
     L{Platform.isWinNT} can return only C{0} or C{1} and can not return C{1}
     if L{Platform.getType} is not C{"win32"}.
     """
     platform = Platform()
     isWinNT = platform.isWinNT()
     self.assertTrue(isWinNT in (0, 1))
     if platform.getType() != "win32":
         self.assertEqual(isWinNT, 0)
Exemple #15
0
 def test_isWinNTDeprecated(self):
     """
     L{Platform.isWinNT} is deprecated in favor of L{platform.isWindows}.
     """
     platform = Platform()
     platform.isWinNT()
     warnings = self.flushWarnings([self.test_isWinNTDeprecated])
     self.assertEqual(len(warnings), 1)
     self.assertEqual(
         warnings[0]['message'], self.isWinNTDeprecationMessage)
Exemple #16
0
 def test_getType(self):
     """
     If an operating system name is supplied to L{Platform}'s initializer,
     L{Platform.getType} returns the platform type which corresponds to that
     name.
     """
     self.assertEqual(Platform("nt").getType(), "win32")
     self.assertEqual(Platform("ce").getType(), "win32")
     self.assertEqual(Platform("posix").getType(), "posix")
     self.assertEqual(Platform("java").getType(), "java")
Exemple #17
0
 def test_getType(self):
     """
     If an operating system name is supplied to L{Platform}'s initializer,
     L{Platform.getType} returns the platform type which corresponds to that
     name.
     """
     self.assertEqual(Platform('nt').getType(), 'win32')
     self.assertEqual(Platform('ce').getType(), 'win32')
     self.assertEqual(Platform('posix').getType(), 'posix')
     self.assertEqual(Platform('java').getType(), 'java')
Exemple #18
0
 def test_isLinux(self):
     """
     If a system platform name is supplied to L{Platform}'s initializer, it
     is used to determine the result of L{Platform.isLinux}, which returns
     C{True} for values beginning with C{"linux"}, C{False} otherwise.
     """
     self.assertFalse(Platform(None, 'darwin').isLinux())
     self.assertTrue(Platform(None, 'linux').isLinux())
     self.assertTrue(Platform(None, 'linux2').isLinux())
     self.assertTrue(Platform(None, 'linux3').isLinux())
     self.assertFalse(Platform(None, 'win32').isLinux())
Exemple #19
0
 def test_supportsThreads(self):
     """
     L{Platform.supportsThreads} returns C{True} if threads can be created in
     this runtime, C{False} otherwise.
     """
     # It's difficult to test both cases of this without faking the threading
     # module.  Perhaps an adequate test is to just test the behavior with
     # the current runtime, whatever that happens to be.
     try:
         namedModule('threading')
     except ImportError:
         self.assertFalse(Platform().supportsThreads())
     else:
         self.assertTrue(Platform().supportsThreads())
Exemple #20
0
def ffmpeg_args():
    ret = ['ffmpeg', '-f']

    p = Platform()
    if p.isMacOSX():
        ret.append('avfoundation')
    elif p.isLinux():
        ret.append('v4l2')
    else:
        raise NotImplementedError

    ret.extend([
        '-framerate',
        '30',
        '-video_size',
        '640x480',
    ])

    if p.isMacOSX():
        ret.extend([
            '-i',
            'default',
            '-f',
            'avfoundation',
            '-i',
            ':0',
        ])
    elif p.isLinux():
        ret.extend([
            '-i',
            '/dev/video0',
            '-f',
            'alsa',
            '-thread_queue_size',
            '99999',
            '-i',
            'hw:0',
        ])

    ret.extend([
        '-async',
        '1',
        '-c:a',
        'aac',
        '-vcodec',
        'libx264',
        '-tune',
        'zerolatency',
        '-preset',
        'veryfast',
        '-x264opts',
        'crf=20:vbv-maxrate=3000:vbv-bufsize=100:intra-refresh=1:slice-max-size=1500:keyint=30:ref=1',
    ])

    # Ubuntu-only?
    if p.isLinux() and isUbuntu():
        ret.extend(['-strict', '-2'])

    ret.extend(['-f', 'mpegts', '-'])
    return ret
Exemple #21
0
    def test_cgroupsSuggestsRealSystem(self):
        """
        If the platform is Linux, and the cgroups file (faked out here) exists,
        and none of the paths starts with C{/docker/}, C{isDocker()} returns
        C{False}.
        """
        cgroupsFile = self.mktemp()
        with open(cgroupsFile, 'wb') as f:
            # real cgroups file from a Fedora 17 system
            f.write(b"""9:perf_event:/
8:blkio:/
7:net_cls:/
6:freezer:/
5:devices:/
4:memory:/
3:cpuacct,cpu:/
2:cpuset:/
1:name=systemd:/system""")

        platform = Platform(None, 'linux')
        self.assertFalse(platform.isDocker(_initCGroupLocation=cgroupsFile))
    def test_cgroupsSuggestsRealSystem(self):
        """
        If the platform is Linux, and the cgroups file (faked out here) exists,
        and none of the paths starts with C{/docker/}, C{isDocker()} returns
        C{False}.
        """
        cgroupsFile = self.mktemp()
        with open(cgroupsFile, 'wb') as f:
            # real cgroups file from a Fedora 17 system
            f.write(b"""9:perf_event:/
8:blkio:/
7:net_cls:/
6:freezer:/
5:devices:/
4:memory:/
3:cpuacct,cpu:/
2:cpuset:/
1:name=systemd:/system""")

        platform = Platform(None, 'linux')
        self.assertFalse(platform.isDocker(_initCGroupLocation=cgroupsFile))
Exemple #23
0
    def test_cgroupsSuggestsDocker(self):
        """
        If the platform is Linux, and the cgroups file (faked out here) exists,
        and one of the paths starts with C{/docker/}, C{isDocker()} returns
        C{True}.
        """
        cgroupsFile = self.mktemp()
        with open(cgroupsFile, 'wb') as f:
            # real cgroups file from inside a Debian 7 docker container
            f.write(b"""10:debug:/
9:net_prio:/
8:perf_event:/docker/104155a6453cb67590027e397dc90fc25a06a7508403c797bc89ea43adf8d35f
7:net_cls:/
6:freezer:/docker/104155a6453cb67590027e397dc90fc25a06a7508403c797bc89ea43adf8d35f
5:devices:/docker/104155a6453cb67590027e397dc90fc25a06a7508403c797bc89ea43adf8d35f
4:blkio:/docker/104155a6453cb67590027e397dc90fc25a06a7508403c797bc89ea43adf8d35f
3:cpuacct:/docker/104155a6453cb67590027e397dc90fc25a06a7508403c797bc89ea43adf8d35f
2:cpu:/docker/104155a6453cb67590027e397dc90fc25a06a7508403c797bc89ea43adf8d35f
1:cpuset:/docker/104155a6453cb67590027e397dc90fc25a06a7508403c797bc89ea43adf8d35f""")

        platform = Platform(None, 'linux')
        self.assertTrue(platform.isDocker(_initCGroupLocation=cgroupsFile))
    def test_cgroupsSuggestsDocker(self):
        """
        If the platform is Linux, and the cgroups file (faked out here) exists,
        and one of the paths starts with C{/docker/}, C{isDocker()} returns
        C{True}.
        """
        cgroupsFile = self.mktemp()
        with open(cgroupsFile, 'wb') as f:
            # real cgroups file from inside a Debian 7 docker container
            f.write(b"""10:debug:/
9:net_prio:/
8:perf_event:/docker/104155a6453cb67590027e397dc90fc25a06a7508403c797bc89ea43adf8d35f
7:net_cls:/
6:freezer:/docker/104155a6453cb67590027e397dc90fc25a06a7508403c797bc89ea43adf8d35f
5:devices:/docker/104155a6453cb67590027e397dc90fc25a06a7508403c797bc89ea43adf8d35f
4:blkio:/docker/104155a6453cb67590027e397dc90fc25a06a7508403c797bc89ea43adf8d35f
3:cpuacct:/docker/104155a6453cb67590027e397dc90fc25a06a7508403c797bc89ea43adf8d35f
2:cpu:/docker/104155a6453cb67590027e397dc90fc25a06a7508403c797bc89ea43adf8d35f
1:cpuset:/docker/104155a6453cb67590027e397dc90fc25a06a7508403c797bc89ea43adf8d35f""")

        platform = Platform(None, 'linux')
        self.assertTrue(platform.isDocker(_initCGroupLocation=cgroupsFile))
Exemple #25
0
 def test_isVistaConsistency(self):
     """
     Verify consistency of L{Platform.isVista}: it can only be C{True} if
     L{Platform.isWinNT} and L{Platform.isWindows} are C{True}.
     """
     platform = Platform()
     if platform.isVista():
         self.assertTrue(platform.isWinNT())
         self.assertTrue(platform.isWindows())
         self.assertFalse(platform.isMacOSX())
Exemple #26
0
"""
Tests for L{twisted.internet.default}.
"""

from __future__ import division, absolute_import

import select, sys
from twisted.trial.unittest import SynchronousTestCase
from twisted.python.runtime import Platform
from twisted.python.reflect import requireModule
from twisted.internet import default
from twisted.internet.default import _getInstallFunction, install
from twisted.internet.test.test_main import NoReactor
from twisted.internet.interfaces import IReactorCore

unix = Platform('posix', 'other')
linux = Platform('posix', 'linux2')
windows = Platform('nt', 'win32')
osx = Platform('posix', 'darwin')


class PollReactorTests(SynchronousTestCase):
    """
    Tests for the cases of L{twisted.internet.default._getInstallFunction}
    in which it picks the poll(2) or epoll(7)-based reactors.
    """
    def assertIsPoll(self, install):
        """
        Assert the given function will install the poll() reactor, or select()
        if poll() is unavailable.
        """
Exemple #27
0
"""
Tests for L{twisted.internet.default}.
"""

import select
import sys

from twisted.internet import default
from twisted.internet.default import _getInstallFunction, install
from twisted.internet.interfaces import IReactorCore
from twisted.internet.test.test_main import NoReactor
from twisted.python.reflect import requireModule
from twisted.python.runtime import Platform
from twisted.trial.unittest import SynchronousTestCase

unix = Platform("posix", "other")
linux = Platform("posix", "linux2")
windows = Platform("nt", "win32")
osx = Platform("posix", "darwin")


class PollReactorTests(SynchronousTestCase):
    """
    Tests for the cases of L{twisted.internet.default._getInstallFunction}
    in which it picks the poll(2) or epoll(7)-based reactors.
    """
    def assertIsPoll(self, install):
        """
        Assert the given function will install the poll() reactor, or select()
        if poll() is unavailable.
        """
Exemple #28
0
 def test_noChecksOnLinux(self):
     """
     If the platform is not Linux, C{isDocker()} always returns L{False}.
     """
     platform = Platform(None, 'win32')
     self.assertFalse(platform.isDocker())
 def test_noChecksOnLinux(self):
     """
     If the platform is not Linux, C{isDocker()} always returns L{False}.
     """
     platform = Platform(None, 'win32')
     self.assertFalse(platform.isDocker())