a
    ze                      @   sX   d dl Z d dlZd dlZddlmZ d dlmZ dZdd ZdZ	d	Z
G d
d deZdS )    N   )utilwrapsTc                    s   t   fdd}|S )Nc                    s*   t | ddr|    | g|R i |S )NfailfastF)getattrstop)selfargskwmethod %/usr/lib/python3.9/unittest/result.pyinner   s    zfailfast.<locals>.innerr   )r   r   r   r   r   r      s    r   z
Stdout:
%sz
Stderr:
%sc                   @   s   e Zd ZdZdZdZd/ddZdd Zdd Zd	d
 Z	dd Z
dd Zdd Zdd Zedd Zedd Zdd Zdd Zdd Zdd Ze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S )0
TestResultNFc                 C   sb   d| _ g | _g | _d| _g | _g | _g | _d| _d| _d| _	d | _
d | _tj| _tj| _d| _d S )NFr   )r   failureserrorstestsRunskippedexpectedFailuresunexpectedSuccesses
shouldStopbuffer	tb_locals_stdout_buffer_stderr_buffersysstdout_original_stdoutstderr_original_stderr_mirrorOutput)r	   streamZdescriptions	verbosityr   r   r   __init__&   s    zTestResult.__init__c                 C   s   d S Nr   r	   r   r   r   printErrors7   s    zTestResult.printErrorsc                 C   s    |  j d7  _ d| _|   d S )Nr   F)r   r"   _setupStdoutr	   testr   r   r   	startTest:   s    zTestResult.startTestc                 C   s8   | j r4| jd u r$t | _t | _| jt_| jt_d S r&   )r   r   ioStringIOr   r   r   r    r'   r   r   r   r)   @   s    


zTestResult._setupStdoutc                 C   s   d S r&   r   r'   r   r   r   startTestRunH   s    zTestResult.startTestRunc                 C   s   |    d| _d S )NF)_restoreStdoutr"   r*   r   r   r   stopTestN   s    zTestResult.stopTestc                 C   s   | j r| jrltj }tj }|rF|ds6|d7 }| jt	|  |rl|ds\|d7 }| j
t|  | jt_| j
t_| jd | j  | jd | j  d S )N
r   )r   r"   r   r   getvaluer    endswithr   writeSTDOUT_LINEr!   STDERR_LINEr   seektruncater   )r	   outputerrorr   r   r   r0   S   s$    




zTestResult._restoreStdoutc                 C   s   d S r&   r   r'   r   r   r   stopTestRunh   s    zTestResult.stopTestRunc                 C   s"   | j || ||f d| _d S NT)r   append_exc_info_to_stringr"   r	   r+   errr   r   r   addErrorn   s    zTestResult.addErrorc                 C   s"   | j || ||f d| _d S r=   )r   r>   r?   r"   r@   r   r   r   
addFailurev   s    zTestResult.addFailurec                 C   sZ   |d urVt | ddr|   t|d |jr4| j}n| j}||| ||f d| _d S )Nr   Fr   T)	r   r   
issubclassfailureExceptionr   r   r>   r?   r"   )r	   r+   ZsubtestrA   r   r   r   r   
addSubTest}   s    zTestResult.addSubTestc                 C   s   d S r&   r   r*   r   r   r   
addSuccess   s    zTestResult.addSuccessc                 C   s   | j ||f d S r&   )r   r>   )r	   r+   reasonr   r   r   addSkip   s    zTestResult.addSkipc                 C   s   | j || ||f d S r&   )r   r>   r?   r@   r   r   r   addExpectedFailure   s    zTestResult.addExpectedFailurec                 C   s   | j | d S r&   )r   r>   r*   r   r   r   addUnexpectedSuccess   s    zTestResult.addUnexpectedSuccessc                 C   s>   t | jt | j  kodkn  o<t| d p<t | jdkS )Nr   r   )lenr   r   hasattrr   r'   r   r   r   wasSuccessful   s    $zTestResult.wasSuccessfulc                 C   s
   d| _ d S r=   )r   r'   r   r   r   r      s    zTestResult.stopc           
      C   s   |\}}}|  ||||}tj|||| jd}t| }| jrtj	 }tj
	 }	|rx|dsj|d7 }|t|  |	r|	ds|	d7 }	|t|	  d|S )N)capture_localsr2    )_clean_tracebacks	tracebackTracebackExceptionr   listformatr   r   r   r3   r    r4   r>   r6   r7   join)
r	   rA   r+   exctypevaluetbZtb_eZmsgLinesr:   r;   r   r   r   r?      s$    





zTestResult._exc_info_to_stringc           	      C   s   d }d}|||fg}|r|  \}}}|r<| |r<|j}q&||ju rP| | |r^|}d}n||_|d ur|j|jfD ]"}|d urx|t	|||jf qxq|S )NTF)
pop_is_relevant_tb_leveltb_nextrE   _remove_unittest_tb_frames__traceback__	__cause____context__r>   type)	r	   rW   rX   rY   r+   retfirstZexcscr   r   r   rQ      s$    

zTestResult._clean_tracebacksc                 C   s   d|j jv S )N
__unittest)tb_frame	f_globals)r	   rY   r   r   r   r[      s    z TestResult._is_relevant_tb_levelc                 C   s0   d }|r|  |s|}|j}q|d ur,d |_d S r&   )r[   r\   )r	   rY   prevr   r   r   r]      s    z%TestResult._remove_unittest_tb_framesc                 C   s&   dt | j| jt| jt| jf S )Nz!<%s run=%i errors=%i failures=%i>)r   Zstrclass	__class__r   rL   r   r   r'   r   r   r   __repr__   s
    zTestResult.__repr__)NNN)__name__
__module____qualname__Z_previousTestClassZ_testRunEnteredZ_moduleSetUpFailedr%   r(   r,   r)   r/   r1   r0   r<   r   rB   rC   rF   rG   rI   rJ   rK   rN   r   r?   rQ   r[   r]   rj   r   r   r   r   r      s8   



	r   )r-   r   rR   rP   r   	functoolsr   re   r   r6   r7   objectr   r   r   r   r   <module>   s   