o
    ¯b/  ã                   @   sH   d Z ddlmZ ddlmZ ddlmZ ddlmZ G dd„ deƒZ	dS )	zZ
Test reporter forwarding test results over trial distributed AMP commands.

@since: 12.3
é    )ÚFailure)Úqual)Úmanagercommands)Ú
TestResultc                       s�   e Zd ZdZdZ‡ fdd„Zdd„ Zdd„ Z‡ fd	d
„Z‡ fdd„Z	‡ fdd„Z
‡ fdd„Zdd„ Zd‡ fdd„	Zd‡ fdd„	Zdd„ Z‡  ZS )ÚWorkerReportera  
    Reporter for trial's distributed workers. We send things not through a
    stream, but through an C{AMP} protocol's C{callRemote} method.

    @ivar _DEFAULT_TODO: Default message for expected failures and
        unexpected successes, used only if a C{Todo} is not provided.
    zTest expected to failc                    s   t ƒ  ¡  || _dS )z±
        @param ampProtocol: The communication channel with the trial
            distributed manager which collects all test results.
        @type ampProtocol: C{AMP}
        N)ÚsuperÚ__init__ÚampProtocol)Úselfr	   ©Ú	__class__© úD/usr/lib/python3/dist-packages/twisted/trial/_dist/workerreporter.pyr      s   

zWorkerReporter.__init__c                 C   s&   t |tƒrt|d |d |d ƒS |S )zX
        Convert a C{sys.exc_info()}-style tuple to a L{Failure}, if necessary.
        é   r   é   )Ú
isinstanceÚtupler   )r
   Úerrorr   r   r   Ú_getFailure&   s   
zWorkerReporter._getFailurec                 C   s4   g }|j D ]}| |d |d t|d ƒg¡ q|S )z<
        Extract frames from a C{Failure} instance.
        r   r   r   )ÚframesÚextendÚstr)r
   Úfailurer   Úframer   r   r   Ú
_getFrames.   s   
"zWorkerReporter._getFramesc                    s*   t ƒ  |¡ | ¡ }| jjtj|d� dS )z&
        Send a success over.
        )ÚtestNameN)r   Ú
addSuccessÚidr	   Ú
callRemoter   Ú
AddSuccess)r
   Útestr   r   r   r   r   7   s   zWorkerReporter.addSuccessc                    ób   t ƒ  ||¡ | ¡ }|  |¡}| ¡ }t|jƒ}dd„ |  |¡D ƒ}| jj	t
j||||d� dS )z%
        Send an error over.
        c                 S   ó   g | ]}|‘qS r   r   ©Ú.0r   r   r   r   Ú
<listcomp>H   ó    z+WorkerReporter.addError.<locals>.<listcomp>)r   r   Ú
errorClassr   N)r   ÚaddErrorr   r   ÚgetErrorMessager   Útyper   r	   r   r   ÚAddError)r
   r    r   r   r   r'   r   r   r   r   r(   ?   ó   


ûzWorkerReporter.addErrorc                    r!   )z&
        Send a Failure over.
        c                 S   r"   r   r   r#   r   r   r   r%   Z   r&   z-WorkerReporter.addFailure.<locals>.<listcomp>)r   ÚfailÚ	failClassr   N)r   Ú
addFailurer   r   r)   r   r*   r   r	   r   r   Ú
AddFailure)r
   r    r-   r   r   r.   r   r   r   r   r/   Q   r,   zWorkerReporter.addFailurec                    s6   t ƒ  ||¡ t|ƒ}| ¡ }| jjtj||d� dS )z#
        Send a skip over.
        )r   ÚreasonN)r   ÚaddSkipr   r   r	   r   r   ÚAddSkip)r
   r    r1   r   r   r   r   r2   c   s   
ÿzWorkerReporter.addSkipc                 C   s   |du r| j S |jS )zj
        Get the reason for a C{Todo}.

        If C{todo} is L{None}, return a sensible default.
        N)Ú_DEFAULT_TODOr1   )r
   Útodor   r   r   Ú_getTodoReasonn   s   zWorkerReporter._getTodoReasonNc                    s@   t ƒ  |||¡ | ¡ }| ¡ }| jjtj|||  |¡d� dS )z0
        Send an expected failure over.
        )r   r   r5   N)	r   ÚaddExpectedFailurer)   r   r	   r   r   ÚAddExpectedFailurer6   )r
   r    r   r5   ÚerrorMessager   r   r   r   r7   y   s   
üz!WorkerReporter.addExpectedFailurec                    s4   t ƒ  ||¡ | ¡ }| jjtj||  |¡d� dS )z2
        Send an unexpected success over.
        )r   r5   N)r   ÚaddUnexpectedSuccessr   r	   r   r   ÚAddUnexpectedSuccessr6   )r
   r    r5   r   r   r   r   r:   ‡   s   
ýz#WorkerReporter.addUnexpectedSuccessc                 C   s   dS )z*
        I{Don't} print a summary
        Nr   )r
   r   r   r   ÚprintSummary“   s    zWorkerReporter.printSummary)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r4   r   r   r   r   r(   r/   r2   r6   r7   r:   r<   Ú__classcell__r   r   r   r   r      s    		r   N)
r@   Útwisted.python.failurer   Útwisted.python.reflectr   Útwisted.trial._distr   Útwisted.trial.reporterr   r   r   r   r   r   Ú<module>   s   