o
    9»Bink  ã                   @  s  d Z ddlmZ ddlZddlZddlZddlmZmZm	Z	m
Z
mZ ddlmZ ddlmZmZmZ ddlmZmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZmZ ddl m!Z! eeƒG dd„ dƒƒZ"G dd„ deeƒZ#G dd„ de!j$ƒZ%G dd„ de!j&ƒZ'dS )z&
Tests for L{twisted.runner.procmon}.
é    )ÚannotationsN)ÚAnyStrÚMappingÚOptionalÚSequenceÚUnion)Úimplementer)ÚProcessDoneÚProcessExitedAlreadyÚProcessTerminated)ÚIProcessProtocolÚIProcessTransport)ÚClock)ÚMemoryReactor)ÚglobalLogPublisher)ÚFailure)ÚLoggingProtocolÚProcessMonitor)Úunittestc                   @  s>   e Zd ZdZdZdZdZ				ddd„Zdd„ Zd	d
„ Z	dS )ÚDummyProcessa   
    An incomplete and fake L{IProcessTransport} implementation for testing how
    L{ProcessMonitor} behaves when its monitored processes exit.

    @ivar _terminationDelay: the delay in seconds after which the DummyProcess
        will appear to exit when it receives a TERM signal
    é   Nr   c                 C  s@   || _ || _|| _|| _|| _|| _|| _|| _|	| _|
| _	d S ©N)
ÚprotoÚ_reactorÚ_executableÚ_argsÚ_environmentÚ_pathÚ_uidÚ_gidÚ_usePTYÚ	_childFDs)ÚselfÚreactorÚ
executableÚargsÚenvironmentÚpathr   ÚuidÚgidÚusePTYÚchildFDs© r,   ú`/var/www/html/Trade-python/venv/lib/python3.10/site-packages/twisted/runner/test/test_procmon.pyÚ__init__)   s   
zDummyProcess.__init__c                 C  sP   | j dfddœ}| jdu rtƒ ‚||v r&|| \}}| j || j|¡| _dS dS )añ  
        A partial implementation of signalProcess which can only handle TERM and
        KILL signals.
         - When a TERM signal is given, the dummy process will appear to exit
           after L{DummyProcess._terminationDelay} seconds with exit code 0
         - When a KILL signal is given, the dummy process will appear to exit
           immediately with exit code 1.

        @param signalID: The signal name or number to be issued to the process.
        @type signalID: C{str}
        r   ©r   r   )ÚTERMÚKILLN)Ú_terminationDelayÚpidr
   r   Ú	callLaterÚprocessEndedÚ_signalHandler)r"   ÚsignalIDÚparamsÚdelayÚstatusr,   r,   r-   ÚsignalProcessB   s   

ÿþzDummyProcess.signalProcessc                 C  s,   d| _ ttdœ}| j t|| |ƒƒ¡ dS )zC
        Deliver the process ended event to C{self.proto}.
        Nr/   )r3   r	   r   r   r5   r   )r"   r:   Ú	statusMapr,   r,   r-   r5   Y   s
   þzDummyProcess.processEnded)NNr   N)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r3   r   r2   r.   r;   r5   r,   r,   r,   r-   r      s    

õr   c                   @  sD   e Zd ZU dZded< ded< d dd	„Z	
	
	
	
		
d!d"dd„Zd
S )#ÚDummyProcessReactorzÉ
    @ivar spawnedProcesses: a list that keeps track of the fake process
        instances built by C{spawnProcess}.

    @ivar spawnProcessException: An exception which spawnProcess() will raise.
    zlist[DummyProcess]ÚspawnedProcesseszException | NoneÚspawnProcessExceptionÚreturnÚNonec                 C  s$   t  | ¡ t | ¡ g | _d | _d S r   )r   r.   r   rB   rC   ©r"   r,   r,   r-   r.   p   s   


zDummyProcessReactor.__init__NFÚprocessProtocolr   r$   úUnion[bytes, str]r%   úSequence[Union[bytes, str]]Úenvú!Optional[Mapping[AnyStr, AnyStr]]r'   úUnion[None, bytes, str]r(   úOptional[int]r)   r*   Úboolr+   ú'Optional[Mapping[int, Union[int, str]]]r   c
                 C  sD   | j dur| j ‚t| |||||||||	ƒ
}
| |
¡ | j |
¡ |
S )zz
        Fake L{reactor.spawnProcess}, that logs all the process
        arguments and returns a L{DummyProcess}.
        N)rC   r   ÚmakeConnectionrB   Úappend)r"   rG   r$   r%   rJ   r'   r(   r)   r*   r+   Úprocr,   r,   r-   ÚspawnProcessv   s"   
ö
z DummyProcessReactor.spawnProcess©rD   rE   )NNNNFN)rG   r   r$   rH   r%   rI   rJ   rK   r'   rL   r(   rM   r)   rM   r*   rN   r+   rO   rD   r   )r=   r>   r?   r@   Ú__annotations__r.   rS   r,   r,   r,   r-   rA   e   s   
 
örA   c                   @  s$  e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdId d!„ZdId"d#„Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ Zd<d=„ Z d>d?„ Z!d@dA„ Z"dBdC„ Z#dDdE„ Z$dFdG„ Z%dHS )JÚProcmonTestsz&
    Tests for L{ProcessMonitor}.
    c                 C  s2   t ƒ | _t| jd| _d| j_d| j_d| j_dS )zL
        Create an L{ProcessMonitor} wrapped around a fake reactor.
        ©r#   é   é
   N)rA   r#   r   ÚpmÚminRestartDelayÚmaxRestartDelayÚ	thresholdrF   r,   r,   r-   ÚsetUpŸ   s
   zProcmonTests.setUpc                 C  sL   | j jdddgddi d t| j ƒ}|  d|¡ |  d|¡ |  d|¡ d	S )
z+
        Repr includes all details
        ÚfooÚarg1Úarg2r   rX   ©r(   r)   rJ   Ú1Ú2N)rZ   Ú
addProcessÚreprÚassertIn©r"   Úrepresentationr,   r,   r-   Útest_reprLooksGood©   s
   
zProcmonTests.test_reprLooksGoodc                 C  s<   | j jdddgi d t| j ƒ}|  d|¡ |  d|¡ dS )z·
        Repr does not include unneeded details.

        Values of attributes that just mean "inherit from launching
        process" do not appear in the repr of a process.
        r_   r`   ra   )rJ   ú(ú)N)rZ   re   rf   ÚassertNotInrh   r,   r,   r-   Útest_simpleReprLooksGood³   s   
z%ProcmonTests.test_simpleReprLooksGoodc                 C  sD   | j jdddgddi d |  | j  ¡ d dddgddi fi¡ dS )	zW
        The list of monitored processes must be included in the pickle state.
        r_   r`   ra   r   rX   rb   Ú	processesN)rZ   re   ÚassertEqualÚ__getstate__rF   r,   r,   r-   Útest_getStateIncludesProcesses¿   s   ÿz+ProcmonTests.test_getStateIncludesProcessesc                 C  s   |   d| j ¡ ¡ dS )z~
        The private L{ProcessMonitor._reactor} instance variable should not be
        included in the pickle state.
        r   N)rm   rZ   rq   rF   r,   r,   r-   Útest_getStateExcludesReactorÈ   ó   z)ProcmonTests.test_getStateExcludesReactorc                 C  s~   | j jdddgddi d |  | j ji ¡ |  | j jdddgddi fi¡ | j  ¡  | j d¡ |  t| j j 	¡ ƒdg¡ dS )	z‡
        L{ProcessMonitor.addProcess} only starts the named program if
        L{ProcessMonitor.startService} has been called.
        r_   r`   ra   r   rX   rb   r   N)
rZ   re   rp   Ú	protocolsro   ÚstartServicer#   ÚadvanceÚlistÚkeysrF   r,   r,   r-   Útest_addProcessÏ   s    
zProcmonTests.test_addProcessc              	   C  s>   | j jdddgddi d | jt| j jdddgddi d dS )z|
        L{ProcessMonitor.addProcess} raises a C{KeyError} if a process with the
        given name already exists.
        r_   r`   ra   r   rX   rb   N)rZ   re   ÚassertRaisesÚKeyErrorrF   r,   r,   r-   Ú test_addProcessDuplicateKeyErrorÛ   s   
ÿz-ProcmonTests.test_addProcessDuplicateKeyErrorc                 C  sP   ddi}| j  ¡  | j jddgdd|d | j d¡ |  | jjd j|¡ dS )	zƒ
        L{ProcessMonitor.addProcess} takes an C{env} parameter that is passed to
        L{IReactorProcess.spawnProcess}.
        ÚKEYÚvaluer_   r   rX   rb   r   N)rZ   rv   re   r#   rw   rp   rB   r   )r"   ÚfakeEnvr,   r,   r-   Útest_addProcessEnvå   s
   
zProcmonTests.test_addProcessEnvc                 C  sD   | j  ¡  | j jddgdd | j d¡ |  | jjd jd¡ dS )zƒ
        L{ProcessMonitor.addProcess} takes an C{cwd} parameter that is passed
        to L{IReactorProcess.spawnProcess}.
        r_   z	/mnt/lala)Úcwdr   N)rZ   rv   re   r#   rw   rp   rB   r   rF   r,   r,   r-   Útest_addProcessCwdð   s   
zProcmonTests.test_addProcessCwdc                 C  sR   | j  ¡  | j  ddg¡ |  t| j jƒd¡ | j  d¡ |  t| j jƒd¡ dS )zm
        L{ProcessMonitor.removeProcess} removes the process from the public
        processes list.
        r_   r   r   N)rZ   rv   re   rp   Úlenro   ÚremoveProcessrF   r,   r,   r-   Útest_removeProcessú   s
   
zProcmonTests.test_removeProcessc                 C  s    | j  ¡  |  t| j jd¡ dS )zz
        L{ProcessMonitor.removeProcess} raises a C{KeyError} if the given
        process name isn't recognised.
        r_   N)rZ   rv   r{   r|   r…   rF   r,   r,   r-   Ú!test_removeProcessUnknownKeyError  s   
z.ProcmonTests.test_removeProcessUnknownKeyErrorc                 C  sH   | j  ddg¡ | j  d¡ |  | j jd t¡ |  d| j j ¡ ¡ dS )a  
        When a process has been started, an instance of L{LoggingProtocol} will
        be added to the L{ProcessMonitor.protocols} dict and the start time of
        the process will be recorded in the L{ProcessMonitor.timeStarted}
        dictionary.
        r_   N)	rZ   re   ÚstartProcessÚassertIsInstanceru   r   rg   ÚtimeStartedry   rF   r,   r,   r-   Útest_startProcess  s   zProcmonTests.test_startProcessc                 C  s2   | j  ddg¡ | j  d¡ |  | j  d¡¡ dS )zr
        L{ProcessMonitor.startProcess} silently returns if the named process is
        already started.
        r_   N)rZ   re   rˆ   ÚassertIsNonerF   r,   r,   r-   Útest_startProcessAlreadyStarted  s   z,ProcmonTests.test_startProcessAlreadyStartedc                 C  ó   |   t| jjd¡ dS )zy
        L{ProcessMonitor.startProcess} raises a C{KeyError} if the given
        process name isn't recognised.
        r_   N)r{   r|   rZ   rˆ   rF   r,   r,   r-   Ú test_startProcessUnknownKeyError"  rt   z-ProcmonTests.test_startProcessUnknownKeyErrorrD   rE   c                 C  sr   t tjt tj¡ƒ| j_d| j_d| j_	| j 
ddg¡ | j d¡ |  | jjd d¡ |  t|  t ¡ƒd¡ dS )z
        L{IReactorProcess.spawnProcess} might raise C{OSError}, ensure it
        is caught and process is restarted.
        é{   r_   r   N)ÚOSErrorÚerrnoÚEAGAINÚosÚstrerrorr#   rC   rZ   r[   r\   re   rˆ   ÚassertEqualsr9   r„   ÚflushLoggedErrorsrF   r,   r,   r-   Ú%test_startProcessSpawnCaughtException)  s   ÿz2ProcmonTests.test_startProcessSpawnCaughtExceptionc                 C  s2   t dƒ| j_| j ddg¡ |  t | jjd¡ dS )zy
        L{IReactorProcess.spawnProcess} might raise C{OSError}, ensure other
        exceptions are not caught.
        zJust another exceptionr_   N)ÚSystemErrorr#   rC   rZ   re   r{   rˆ   rF   r,   r,   r-   Ú'test_startProcessSpawnUncaughtException9  s   z4ProcmonTests.test_startProcessSpawnUncaughtExceptionc                 C  s   | j  ¡  | j  ddg¡ |  d| j j¡ d }| j jd j_| j | j j	¡ | j  
d¡ | j |¡ | j d¡ |  | j ¡ | j jd ¡ dS )zm
        L{ProcessMonitor.stopProcess} immediately sends a TERM signal to the
        named process.
        r_   r   r   N)rZ   rv   re   rg   ru   Ú	transportr2   r#   rw   r]   ÚstopProcessrp   ÚsecondsrŠ   )r"   Ú	timeToDier,   r,   r-   Ú"test_stopProcessNaturalTerminationB  s   
z/ProcmonTests.test_stopProcessNaturalTerminationc                 C  sÄ   | j  ¡  | j  ddg¡ |  d| j j¡ | j | j j¡ | j jd j}| j j	d |_
| j  d¡ | j | j j	d ¡ |  d| j jd ¡ | j d¡ | j ddg¡ |  | j ¡ | j jd ¡ dS )z•
        L{ProcessMonitor.stopProcess} kills a process which fails to terminate
        naturally within L{ProcessMonitor.killTime} seconds.
        r_   r   g        r   N)rZ   rv   re   rg   ru   r#   rw   r]   r›   ÚkillTimer2   rœ   rp   rŠ   Úpumpr   )r"   rR   r,   r,   r-   Útest_stopProcessForcedKill`  s   
z'ProcmonTests.test_stopProcessForcedKillc                 C  rŽ   )zx
        L{ProcessMonitor.stopProcess} raises a C{KeyError} if the given process
        name isn't recognised.
        r_   N)r{   r|   rZ   rœ   rF   r,   r,   r-   Útest_stopProcessUnknownKeyError}  rt   z,ProcmonTests.test_stopProcessUnknownKeyErrorc                 C  s&   | j  ddg¡ |  | j  d¡¡ dS )zá
        L{ProcessMonitor.stopProcess} silently returns if the named process
        is already stopped. eg Process has crashed and a restart has been
        rescheduled, but in the meantime, the service is stopped.
        r_   N)rZ   re   rŒ   rœ   rF   r,   r,   r-   Útest_stopProcessAlreadyStopped„  s   z+ProcmonTests.test_stopProcessAlreadyStoppedc                 C  óì   g }|   tj|j¡ t |j¡ | j ddg¡ | j ¡  | j 	d¡ |  
d| jj¡ | j 	| jj¡ | jjd  d¡ |  t|ƒd¡ |d d }|d d }|d d }|d d }|  |d	¡ |  |d
¡ |  |d¡ |  |d¡ dS )zS
        Getting a complete output line on stdout generates a log message.
        r_   r   ó   hello world!
r   Úlog_namespaceÚstreamÚtagÚlineú%twisted.runner.procmon.ProcessMonitorÚstdoutúhello world!N)Ú
addCleanupr   ÚremoveObserverrQ   ÚaddObserverrZ   re   rv   r#   rw   rg   ru   r]   ÚoutReceivedr–   r„   ©r"   ÚeventsÚ	namespacer¨   r©   rª   r,   r,   r-   Útest_outputReceivedCompleteLine  ó$   
z,ProcmonTests.test_outputReceivedCompleteLinec                 C  r¥   )zS
        Getting a complete output line on stderr generates a log message.
        r_   r   r¦   r   r§   r¨   r©   rª   r«   Ústderrr­   N)r®   r   r¯   rQ   r°   rZ   re   rv   r#   rw   rg   ru   r]   ÚerrReceivedr–   r„   r²   r,   r,   r-   Ú!test_ouputReceivedCompleteErrLine¨  r¶   z.ProcmonTests.test_ouputReceivedCompleteErrLinec                 C  sè   g }|   tj|j¡ t |j¡ | j ddg¡ | j ¡  | j 	d¡ |  
d| jj¡ | j 	| jj¡ | jjd  d¡ |  t|ƒd¡ |d }|d }|d }|d }|d }|  |d	¡ |  |d
¡ |  |d¡ |  |tdƒ¡ dS )zN
        Getting invalid UTF-8 results in the repr of the raw message
        r_   r   s   ÿhello world!
r   r§   r¨   r©   rª   r«   r¬   s   ÿhello world!N)r®   r   r¯   rQ   r°   rZ   re   rv   r#   rw   rg   ru   r]   r±   r–   r„   rf   )r"   r³   Úmessager´   r¨   r©   Úoutputr,   r,   r-   Ú*test_outputReceivedCompleteLineInvalidUTF8Ã  s&   
z7ProcmonTests.test_outputReceivedCompleteLineInvalidUTF8c                 C  s  g }|   tj|j¡ t |j¡ | j ddg¡ | j ¡  | j 	d¡ |  
d| jj¡ | j 	| jj¡ | jjd  d¡ |  t|ƒd¡ | jjd  ttdƒƒ¡ |  t|ƒd¡ |d d }|d d }|d d }|d d }|  |d	¡ |  |d
¡ |  |d¡ |  |d¡ dS )zM
        Getting partial line results in no events until process end
        r_   r   s   hello world!r   r§   r¨   r©   rª   r«   r¬   r­   N)r®   r   r¯   rQ   r°   rZ   re   rv   r#   rw   rg   ru   r]   r±   r–   r„   r5   r   r	   r²   r,   r,   r-   Útest_outputReceivedPartialLineß  s(   
z+ProcmonTests.test_outputReceivedPartialLinec                 C  s   | j  ddg¡ | j  ¡  | j d¡ |  d| j j¡ | j | j j¡ | j jd  t	t
dƒƒ¡ |  d| j j¡ | j d¡ |  d| j j¡ dS )z¤
        L{ProcessMonitor.processExit} should immediately restart a process
        if it has been running longer than L{ProcessMonitor.threshold} seconds.
        r_   r   N)rZ   re   rv   r#   rw   rg   ru   r]   r5   r   r	   rm   rF   r,   r,   r-   Ú#test_connectionLostLongLivedProcessü  s   
z0ProcmonTests.test_connectionLostLongLivedProcessc                 C  s–   | j  ddg¡ | j  ¡  | j d¡ | j  d¡ |  d| j j¡ | j jd }|  | 	¡ ¡ | j | j j
d jj¡ |  | 	¡ ¡ |  d| j j¡ dS )zž
        L{ProcessMonitor.processExit} cancels a scheduled process killer and
        deletes the DelayedCall from the L{ProcessMonitor.murder} list.
        r_   r   N)rZ   re   rv   r#   rw   rœ   rg   ÚmurderÚ
assertTrueÚactiveru   r›   r2   ÚassertFalserm   )r"   ÚdelayedCallr,   r,   r-   Útest_connectionLostMurderCancel  s   
z,ProcmonTests.test_connectionLostMurderCancelc                 C  sj   | j  ¡  | j  ddg¡ |  d| j j¡ | j jd j d¡ | j | j jd jj	¡ |  
d| j j¡ dS )z•
        L{ProcessMonitor.processExit} removes the corresponding
        ProcessProtocol instance from the L{ProcessMonitor.protocols} list.
        r_   r1   N)rZ   rv   re   rg   ru   r›   r;   r#   rw   r2   rm   rF   r,   r,   r-   Ú#test_connectionLostProtocolDeletion%  s   
z0ProcmonTests.test_connectionLostProtocolDeletionc                 C  sŒ   d| j _d| j _| j  ¡  | j  ddg¡ |  | j jd | j j¡ | j | j j	d ¡ | j j
d  ttdƒƒ¡ |  | j jd | j j¡ dS )zz
        L{ProcessMonitor.processExit} will wait at least minRestartDelay s
        and at most maxRestartDelay s
        rX   é   r_   r   r   N)rZ   r[   r\   rv   re   rp   r9   r#   rw   r]   ru   r5   r   r	   rF   r,   r,   r-   Ú%test_connectionLostMinMaxRestartDelay1  s   
z2ProcmonTests.test_connectionLostMinMaxRestartDelayc                 C  s   | j  ¡  | j  ddg¡ | j | j jd ¡ |  d| j j¡ |  | j j	d | j j
¡ | j jd  ttdƒƒ¡ |  | j j	d | j j
d ¡ dS )zy
        L{ProcessMonitor.processExit} doubles the restart delay each time
        the process dies too quickly.
        r_   r   r   rX   N)rZ   rv   re   r#   rw   r]   rg   ru   rp   r9   r[   r5   r   r	   rF   r,   r,   r-   Ú&test_connectionLostBackoffDelayDoublesA  s   
 z3ProcmonTests.test_connectionLostBackoffDelayDoublesc                 C  s:   | j  ddg¡ | j  ¡  | j d¡ |  d| j j¡ dS )zP
        L{ProcessMonitor.startService} starts all monitored processes.
        r_   r   N)rZ   re   rv   r#   rw   rg   ru   rF   r,   r,   r-   Útest_startServiceO  s   
zProcmonTests.test_startServicec                 C  s˜   | j  ddg¡ | j  ddg¡ | j  ¡  | j | j j¡ |  d| j j¡ |  d| j j¡ | j d¡ | j  ¡  | j | j j	d ¡ |  
i | j j¡ dS )zT
        L{ProcessMonitor.stopService} should stop all monitored processes.
        r_   Úbarr   N)rZ   re   rv   r#   rw   r]   rg   ru   ÚstopServicer    rp   rF   r,   r,   r-   Útest_stopServiceZ  s   

zProcmonTests.test_stopServicec                 C  sl   | j  ddg¡ | j  ¡  | j d¡ | j  ¡  | j d¡ t| jjƒ}| ¡ }|  	|g ¡ |  
|j¡ dS )zR
        L{ProcessMonitor.restartAll} succeeds when there is one process.
        r_   r   N)rZ   re   rv   r#   rw   Ú
restartAllrx   rB   Úpopr–   rŒ   r3   )r"   ro   Ú	myProcessr,   r,   r-   Ú!test_restartAllRestartsOneProcessp  s   

z.ProcmonTests.test_restartAllRestartsOneProcessc                 C  sš   | j  ddg¡ | j  ¡  | j | j j¡ |  d| j j¡ | j d¡ | j jd  t	t
dƒƒ¡ |  | j jd  ¡ ¡ | j  ¡  |  | j jd  ¡ ¡ dS )ze
        L{ProcessMonitor.stopService} should cancel any scheduled process
        restarts.
        r_   r   r   N)rZ   re   rv   r#   rw   r]   rg   ru   r5   r   r	   rÀ   ÚrestartrÁ   rË   rÂ   rF   r,   r,   r-   Útest_stopServiceCancelRestarts€  s   

z+ProcmonTests.test_stopServiceCancelRestartsc                 C  sx   d| j _d| j _| j  ¡  | j  ddg¡ | j d¡ | j  d¡ | j d¡ | j  ¡  | j d¡ |  	| j j
i ¡ dS )ze
        L{ProcessMonitor.stopService} should cancel all scheduled process
        restarts.
        é   r_   r   é   N)rZ   r]   r[   rv   re   r#   rw   rœ   rË   rp   ru   rF   r,   r,   r-   Ú(test_stopServiceCleanupScheduledRestarts”  s   

z5ProcmonTests.test_stopServiceCleanupScheduledRestartsNrT   )&r=   r>   r?   r@   r^   rj   rn   rr   rs   rz   r}   r   rƒ   r†   r‡   r‹   r   r   r˜   rš   rŸ   r¢   r£   r¤   rµ   r¹   r¼   r½   r¾   rÄ   rÅ   rÇ   rÈ   rÉ   rÌ   rÐ   rÒ   rÕ   r,   r,   r,   r-   rV   š   sH    

	

	

		rV   c                   @  s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚDeprecationTestszQ
    Tests that check functionality that should be deprecated is deprecated.
    c                 C  s   t ƒ | _t| jd| _dS )z5
        Create reactor and process monitor.
        rW   N)rA   r#   r   rZ   rF   r,   r,   r-   r^   ±  s   zDeprecationTests.setUpc                 C  sx   | j  ddg¡ | j j}|  t|ƒd¡ |  ¡ }d}|D ]}|  |d t¡ d|d v r.d}q|  |dt	|ƒ› ¡ d	S )
a   
        _Process.toTuple is deprecated.

        When getting the deprecated processes property, the actual
        data (kept in the class _Process) is converted to a tuple --
        which produces a DeprecationWarning per process so converted.
        r_   r   FÚcategoryÚtoTuplerº   Tzno tuple deprecation found:N)
rZ   re   ro   r–   r„   ÚflushWarningsÚassertIsÚDeprecationWarningrÀ   rf   )r"   ÚmyprocessesÚwarningsÚfoundToTupleÚwarningr,   r,   r-   Útest_toTuple¸  s   €zDeprecationTests.test_toTuplec                 C  sF   | j j}|  |i ¡ |  ¡ }| d¡}|  |d t¡ |  |g ¡ dS )a  
        Accessing L{ProcessMonitor.processes} results in deprecation warning

        Even when there are no processes, and thus no process is converted
        to a tuple, accessing the L{ProcessMonitor.processes} property
        should generate its own DeprecationWarning.
        r   r×   N)rZ   ro   r–   rÙ   rÎ   rÚ   rÛ   )r"   ÚmyProcessesrÝ   Úfirstr,   r,   r-   Útest_processesË  s   
zDeprecationTests.test_processesc                 C  s2   t  | j¡ |  ¡ }|D ]
}|  |d t¡ qdS )zO
        Pickling an L{ProcessMonitor} results in deprecation warnings
        r×   N)ÚpickleÚdumpsrZ   rÙ   rÚ   rÛ   )r"   rÝ   rß   r,   r,   r-   Útest_getstateÚ  s
   ÿzDeprecationTests.test_getstateN)r=   r>   r?   r@   r^   rà   rã   ræ   r,   r,   r,   r-   rÖ   ¬  s    rÖ   )(r@   Ú
__future__r   r’   r”   rä   Útypingr   r   r   r   r   Úzope.interfacer   Útwisted.internet.errorr	   r
   r   Útwisted.internet.interfacesr   r   Útwisted.internet.taskr   Útwisted.internet.testingr   Útwisted.loggerr   Útwisted.python.failurer   Útwisted.runner.procmonr   r   Útwisted.trialr   r   rA   ÚTestCaserV   ÚSynchronousTestCaserÖ   r,   r,   r,   r-   Ú<module>   s0   J5    