a
    ´i¬   ã                   @   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/lib64/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rœt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   