U
    �Acj°  ã                   @   s„   d Z ddlZddlmZ ddlmZmZ ddlmZ ddl	m
Z G dd„ deƒZG d	d
„ d
eƒZG dd„ deƒZG dd„ deƒZdS )z&
Tests for L{twisted.python.runtime}.
é    N)ÚnamedModule)ÚPlatformÚshortPythonVersion)ÚSynchronousTestCase)Úsuppressc                   @   s   e Zd ZdZddœdd„ZdS )ÚPythonVersionTestsz.
    Tests the shortPythonVersion method.
    N©Úreturnc                 C   s8   t ƒ  d¡}tdƒD ]}|  t|| ƒtj| ¡ qdS )zE
        Verify if the Python version is returned correctly.
        Ú.é   N)r   ÚsplitÚrangeÚassertEqualÚintÚsysÚversion_info)ÚselfÚverÚi© r   úD/tmp/pip-unpacked-wheel-nrvc_22y/twisted/python/test/test_runtime.pyÚtest_shortPythonVersion   s    z*PythonVersionTests.test_shortPythonVersion)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      s   r   c                   @   s†   e Zd ZdZdZddœdd„Zddœdd„Zddœd	d
„Zddœdd„Zddœdd„Z	e
eed�ge	_ddœdd„Zddœdd„ZdS )ÚPlatformTestsz8
    Tests for the default L{Platform} initializer.
    zgtwisted.python.runtime.Platform.isWinNT was deprecated in Twisted 13.0. Use Platform.isWindows instead.Nr   c                 C   s   t ƒ }|  | ¡ ¡ dS )z€
        L{Platform.isKnown} returns a boolean indicating whether this is one of
        the L{runtime.knownPlatforms}.
        N)r   Ú
assertTrueZisKnown©r   Úplatformr   r   r   Útest_isKnown)   s    zPlatformTests.test_isKnownc                 C   s<   t ƒ }| ¡ r8|  | ¡ ¡ |  | ¡ ¡ |  | ¡ ¡ dS )z™
        Verify consistency of L{Platform.isVista}: it can only be C{True} if
        L{Platform.isWinNT} and L{Platform.isWindows} are C{True}.
        N)r   ZisVistar   ÚisWinNTZ	isWindowsÚassertFalseÚisMacOSXr   r   r   r   Útest_isVistaConsistency1   s
    z%PlatformTests.test_isVistaConsistencyc                 C   s"   t ƒ }| ¡ r|  | ¡ d¡ dS )zq
        L{Platform.isMacOSX} can only return C{True} if L{Platform.getType}
        returns C{'posix'}.
        ÚposixN)r   r#   r   ÚgetTyper   r   r   r   Útest_isMacOSXConsistency<   s    z&PlatformTests.test_isMacOSXConsistencyc                 C   s$   t ƒ }| ¡ r |  tj d¡¡ dS )z›
        L{Platform.isLinux} can only return C{True} if L{Platform.getType}
        returns C{'posix'} and L{sys.platform} starts with C{"linux"}.
        ÚlinuxN)r   ÚisLinuxr   r   r   Ú
startswithr   r   r   r   Útest_isLinuxConsistencyE   s    z%PlatformTests.test_isLinuxConsistencyc                 C   s4   t ƒ }| ¡ }|  |d¡ | ¡ dkr0|  |¡ dS )z–
        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"}.
        )FTÚwin32N)r   r!   ZassertInr&   r"   )r   r   r!   r   r   r   Útest_isWinNTN   s
    zPlatformTests.test_isWinNT)ÚcategoryÚmessagec                 C   sF   t ƒ }| ¡  |  | jg¡}|  t|ƒd¡ |  |d d | j¡ dS )zV
        L{Platform.isWinNT} is deprecated in favor of L{platform.isWindows}.
        é   r   r/   N)r   r!   ZflushWarningsÚtest_isWinNTDeprecatedr   ÚlenÚisWinNTDeprecationMessage)r   r   Úwarningsr   r   r   r1   `   s
    z$PlatformTests.test_isWinNTDeprecatedc                 C   sF   zt dƒ W n$ tk
r0   |  tƒ  ¡ ¡ Y nX |  tƒ  ¡ ¡ dS )z„
        L{Platform.supportsThreads} returns C{True} if threads can be created in
        this runtime, C{False} otherwise.
        Ú	threadingN)r   ÚImportErrorr"   r   ZsupportsThreadsr   ©r   r   r   r   Útest_supportsThreadsj   s
    z"PlatformTests.test_supportsThreads)r   r   r   r   r3   r    r$   r'   r+   r-   ÚSUPRESSÚDeprecationWarningr   r1   r8   r   r   r   r   r      s   ÿ		þÿ
r   c                   @   s:   e Zd ZdZddœdd„Zddœdd„Zddœdd	„ZdS )
ÚForeignPlatformTestszD
    Tests for L{Platform} based overridden initializer values.
    Nr   c                 C   sT   |   tdƒ ¡ d¡ |   tdƒ ¡ d¡ |   tdƒ ¡ d¡ |   tdƒ ¡ d¡ dS )zµ
        If an operating system name is supplied to L{Platform}'s initializer,
        L{Platform.getType} returns the platform type which corresponds to that
        name.
        Úntr,   Zcer%   ÚjavaN)r   r   r&   r7   r   r   r   Útest_getType   s    z!ForeignPlatformTests.test_getTypec                 C   s@   |   tddƒ ¡ ¡ |  tddƒ ¡ ¡ |  tddƒ ¡ ¡ dS )zÜ
        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.
        NÚdarwinÚlinux2r,   )r   r   r#   r"   r7   r   r   r   Útest_isMacOSXŠ   s    z"ForeignPlatformTests.test_isMacOSXc                 C   sh   |   tddƒ ¡ ¡ |  tddƒ ¡ ¡ |  tddƒ ¡ ¡ |  tddƒ ¡ ¡ |   tddƒ ¡ ¡ dS )zð
        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.
        Nr?   r(   r@   Zlinux3r,   )r"   r   r)   r   r7   r   r   r   Útest_isLinux”   s
    z!ForeignPlatformTests.test_isLinux)r   r   r   r   r>   rA   rB   r   r   r   r   r;   z   s   
r;   c                   @   sH   e Zd ZdZddœdd„Zddœdd„Zddœdd	„Zddœd
d„ZdS )ÚDockerPlatformTestsz@
    Tests for L{twisted.python.runtime.Platform.isDocker}.
    Nr   c                 C   s   t ddƒ}|  | ¡ ¡ dS )zV
        If the platform is not Linux, C{isDocker()} always returns L{False}.
        Nr,   ©r   r"   ÚisDockerr   r   r   r   Útest_noChecksOnLinux¦   s    
z(DockerPlatformTests.test_noChecksOnLinuxc                 C   s    t ddƒ}|  |jdd�¡ dS )zƒ
        If the platform is Linux, and the cgroups file in C{/proc} does not
        exist, C{isDocker()} returns L{False}
        Nr(   Zfakepath©Z_initCGroupLocationrD   r   r   r   r   Útest_noCGroups­   s    
z"DockerPlatformTests.test_noCGroupsc              	   C   sH   |   ¡ }t|dƒ�}| d¡ W 5 Q R X tddƒ}|  |j|d�¡ dS )z¶
        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}.
        Úwbsd  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/104155a6453cb67590027e397dc90fc25a06a7508403c797bc89ea43adf8d35fNr(   rG   )ÚmktempÚopenÚwriter   r   rE   ©r   ZcgroupsFileÚfr   r   r   r   Útest_cgroupsSuggestsDockerµ   s    ÿ
z.DockerPlatformTests.test_cgroupsSuggestsDockerc              	   C   sH   |   ¡ }t|dƒ�}| d¡ W 5 Q R X tddƒ}|  |j|d�¡ dS )z¸
        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}.
        rI   sy   9:perf_event:/
8:blkio:/
7:net_cls:/
6:freezer:/
5:devices:/
4:memory:/
3:cpuacct,cpu:/
2:cpuset:/
1:name=systemd:/systemNr(   rG   )rJ   rK   rL   r   r"   rE   rM   r   r   r   Útest_cgroupsSuggestsRealSystemÎ   s    ÿ
z2DockerPlatformTests.test_cgroupsSuggestsRealSystem)r   r   r   r   rF   rH   rO   rP   r   r   r   r   rC   ¡   s
   rC   )r   r   Ztwisted.python.reflectr   Ztwisted.python.runtimer   r   Ztwisted.trial.unittestr   Ztwisted.trial.utilr   r9   r   r   r;   rC   r   r   r   r   Ú<module>   s   ['