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   ['