o
    ¯b8  ã                   @   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„ ZdS )ÚPythonVersionTestsz.
    Tests the shortPythonVersion method.
    c                 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   úB/usr/lib/python3/dist-packages/twisted/python/test/test_runtime.pyÚtest_shortPythonVersion   s   ÿz*PythonVersionTests.test_shortPythonVersionN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      s    r   c                   @   s\   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	e
eed�ge	_dd„ Z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.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   Ú
assertTrueÚisKnown©r   Úplatformr   r   r   Útest_isKnown)   s   zPlatformTests.test_isKnownc                 C   s@   t ƒ }| ¡ r|  | ¡ ¡ |  | ¡ ¡ |  | ¡ ¡ dS 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   ÚisVistar   ÚisWinNTÚ	isWindowsÚassertFalseÚisMacOSXr   r   r   r   Útest_isVistaConsistency1   s   ýz%PlatformTests.test_isVistaConsistencyc                 C   s&   t ƒ }| ¡ r|  | ¡ d¡ dS 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 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   s8   t ƒ }| ¡ }|  |d¡ | ¡ dkr|  |¡ dS 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!   Ú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   r1   N)r   r!   ÚflushWarningsÚtest_isWinNTDeprecatedr   ÚlenÚisWinNTDeprecationMessage)r   r   Úwarningsr   r   r   r4   `   s
   z$PlatformTests.test_isWinNTDeprecatedc                 C   sF   zt dƒ W n ty   |  tƒ  ¡ ¡ Y dS w |  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   ÚsupportsThreadsr   ©r   r   r   r   Útest_supportsThreadsj   s   ÿz"PlatformTests.test_supportsThreadsN)r   r   r   r   r6   r   r%   r(   r,   r/   ÚSUPRESSÚDeprecationWarningr   r4   r<   r   r   r   r   r      s     ÿ		þÿ
r   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚForeignPlatformTestszD
    Tests for L{Platform} based overridden initializer values.
    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-   Úcer&   ÚjavaN)r   r   r'   r;   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#   r;   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.
        NrD   r)   rE   Úlinux3r-   )r#   r   r*   r   r;   r   r   r   Útest_isLinux”   s
   z!ForeignPlatformTests.test_isLinuxN)r   r   r   r   rC   rF   rH   r   r   r   r   r?   z   s
    
r?   c                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚDockerPlatformTestsz@
    Tests for L{twisted.python.runtime.Platform.isDocker}.
    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)   Úfakepath©Ú_initCGroupLocationrJ   r   r   r   r   Útest_noCGroups­   s   
z"DockerPlatformTests.test_noCGroupsc                 C   ó\   |   ¡ }t|dƒ�}| d¡ W d  ƒ n1 sw   Y  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)   rN   )ÚmktempÚopenÚwriter   r   rK   ©r   ÚcgroupsFileÚfr   r   r   r   Útest_cgroupsSuggestsDockerµ   s   ÿþ
z.DockerPlatformTests.test_cgroupsSuggestsDockerc                 C   rQ   )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}.
        rR   sy   9:perf_event:/
8:blkio:/
7:net_cls:/
6:freezer:/
5:devices:/
4:memory:/
3:cpuacct,cpu:/
2:cpuset:/
1:name=systemd:/systemNr)   rN   )rS   rT   rU   r   r#   rK   rV   r   r   r   Útest_cgroupsSuggestsRealSystemÎ   s   ÿþ
z2DockerPlatformTests.test_cgroupsSuggestsRealSystemN)r   r   r   r   rL   rP   rY   rZ   r   r   r   r   rI   ¡   s    rI   )r   r   Útwisted.python.reflectr   Útwisted.python.runtimer   r   Útwisted.trial.unittestr   Útwisted.trial.utilr   r=   r   r   r?   rI   r   r   r   r   Ú<module>   s   ['