
    Vh                         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e      Z G d	 d
e      Z G d de      Z G d de      Zy)z&
Tests for L{twisted.python.runtime}.
    N)namedModule)PlatformshortPythonVersion)SynchronousTestCase)suppressc                       e Zd ZdZddZy)PythonVersionTestsz.
    Tests the shortPythonVersion method.
    Nc                     t               j                  d      }t        d      D ]1  }| j                  t	        ||         t
        j                  |          3 y)zE
        Verify if the Python version is returned correctly.
        .   N)r   splitrangeassertEqualintsysversion_info)selfveris      P/home/dcms/DCMS/lib/python3.12/site-packages/twisted/python/test/test_runtime.pytest_shortPythonVersionz*PythonVersionTests.test_shortPythonVersion   sM     !"((-q 	?ASQ[#*:*:1*=>	?    returnN)__name__
__module____qualname____doc__r    r   r   r	   r	      s    ?r   r	   c                   l    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	      ge	_        dd
ZddZy)PlatformTestsz8
    Tests for the default L{Platform} initializer.
    zgtwisted.python.runtime.Platform.isWinNT was deprecated in Twisted 13.0. Use Platform.isWindows instead.Nc                 V    t               }| j                  |j                                y)z
        L{Platform.isKnown} returns a boolean indicating whether this is one of
        the L{runtime.knownPlatforms}.
        N)r   
assertTrueisKnownr   platforms     r   test_isKnownzPlatformTests.test_isKnown)   s     
 :((*+r   c                     t               }|j                         r^| j                  |j                                | j                  |j	                                | j                  |j                                yy)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%   s     r   test_isVistaConsistencyz%PlatformTests.test_isVistaConsistency1   s]    
 :OOH,,./OOH..01X..01 r   c                 z    t               }|j                         r!| j                  |j                         d       yy)zq
        L{Platform.isMacOSX} can only return C{True} if L{Platform.getType}
        returns C{'posix'}.
        posixN)r   r-   r   getTyper%   s     r   test_isMacOSXConsistencyz&PlatformTests.test_isMacOSXConsistency<   s5    
 :X--/9 r   c                     t               }|j                         r/| j                  t        j                  j                  d             yy)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%   s     r   test_isLinuxConsistencyz%PlatformTests.test_isLinuxConsistencyE   s7    
 :OOCLL33G<= r   c                     t               }|j                         }| j                  |d       |j                         dk7  r| j	                  |       yy)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*   assertInr1   r,   )r   r&   r*   s      r   test_isWinNTzPlatformTests.test_isWinNTN   sK    
 :""$g}-(W% )r   )categorymessagec                     t               }|j                          | j                  | j                  g      }| j	                  t        |      d       | j	                  |d   d   | j                         y)zV
        L{Platform.isWinNT} is deprecated in favor of L{platform.isWindows}.
           r   r=   N)r   r*   flushWarningstest_isWinNTDeprecatedr   lenisWinNTDeprecationMessage)r   r&   warningss      r   rA   z$PlatformTests.test_isWinNTDeprecated`   sc     :%%t'B'B&CDX*!Y/1O1OPr   c                     	 t        d       | j                  t               j                                y# t        $ r* | j                  t               j                                Y yw xY w)z
        L{Platform.supportsThreads} returns C{True} if threads can be created in
        this runtime, C{False} otherwise.
        	threadingN)r   r#   r   supportsThreadsImportErrorr,   r   s    r   test_supportsThreadsz"PlatformTests.test_supportsThreadsj   sR    	:$ OOHJ6689  	;XZ779:	;s   5 0A('A(r   )r   r   r   r   rC   r'   r.   r2   r7   r;   SUPRESSDeprecationWarningr   rA   rJ   r   r   r   r!   r!      sP    
	F 
,	2:>	& 	'-	
LQ:r   r!   c                   (    e Zd ZdZddZddZddZy)ForeignPlatformTestszD
    Tests for L{Platform} based overridden initializer values.
    Nc                 L   | j                  t        d      j                         d       | j                  t        d      j                         d       | j                  t        d      j                         d       | j                  t        d      j                         d       y)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.
        ntr9   cer0   javaN)r   r   r1   rI   s    r   test_getTypez!ForeignPlatformTests.test_getType   sz     	$//17;$//17;'*224g>&)113V<r   c                     | j                  t        dd      j                                | j                  t        dd      j                                | j                  t        dd      j                                y)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linux2r9   )r#   r   r-   r,   rI   s    r   test_isMacOSXz"ForeignPlatformTests.test_isMacOSX   s\     	x099;<$1::<=$099;<r   c                    | j                  t        dd      j                                | j                  t        dd      j                                | j                  t        dd      j                                | j                  t        dd      j                                | j                  t        dd      j                                y)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.
        NrU   r4   rV   linux3r9   )r,   r   r5   r#   rI   s    r   test_isLinuxz!ForeignPlatformTests.test_isLinux   s     	$199;<w/779:x088:;x088:;$088:;r   r   )r   r   r   r   rS   rW   rZ   r   r   r   rN   rN   z   s    	==
<r   rN   c                   0    e Zd ZdZddZddZddZddZy)DockerPlatformTestsz@
    Tests for L{twisted.python.runtime.Platform.isDocker}.
    Nc                 Z    t        dd      }| j                  |j                                y)zV
        If the platform is not Linux, C{isDocker()} always returns L{False}.
        Nr9   r   r,   isDockerr%   s     r   test_noChecksOnLinuxz(DockerPlatformTests.test_noChecksOnLinux   s'     D'***,-r   c                 ^    t        dd      }| j                  |j                  d             y)z
        If the platform is Linux, and the cgroups file in C{/proc} does not
        exist, C{isDocker()} returns L{False}
        Nr4   fakepath_initCGroupLocationr^   r%   s     r   test_noCGroupsz"DockerPlatformTests.test_noCGroups   s,    
 D'***z*JKr   c                     | j                         }t        |d      5 }|j                  d       ddd       t        dd      }| j	                  |j                  |             y# 1 sw Y   7xY w)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/104155a6453cb67590027e397dc90fc25a06a7508403c797bc89ea43adf8d35fNr4   rc   )mktempopenwriter   r#   r_   r   cgroupsFilefr&   s       r   test_cgroupsSuggestsDockerz.DockerPlatformTests.test_cgroupsSuggestsDocker   sj     kkm+t$ 	GG	U	 D'*))k)JK!	 	   A%%A.c                     | j                         }t        |d      5 }|j                  d       ddd       t        dd      }| j	                  |j                  |             y# 1 sw Y   7xY w)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}.
        rg   sy   9:perf_event:/
8:blkio:/
7:net_cls:/
6:freezer:/
5:devices:/
4:memory:/
3:cpuacct,cpu:/
2:cpuset:/
1:name=systemd:/systemNr4   rc   )rh   ri   rj   r   r,   r_   rk   s       r   test_cgroupsSuggestsRealSystemz2DockerPlatformTests.test_cgroupsSuggestsRealSystem   sk     kkm+t$ 	GG
	 D'***{*KL	 	ro   r   )r   r   r   r   r`   re   rn   rq   r   r   r   r\   r\      s    .LL2Mr   r\   )r   r   twisted.python.reflectr   twisted.python.runtimer   r   twisted.trial.unittestr   twisted.trial.utilr   rK   r	   r!   rN   r\   r   r   r   <module>rv      sW   
  . ? 6 2?, ?X:' X:v$<. $<NCM- CMr   