o
    ˜»áfs  ã                   @   sn   d Z ddlZddlZddlZddlmZ ddlmZ dZG dd„ de	ƒZ
G d	d
„ d
ejƒZG dd„ de	ƒZdS )zRunning testsé    Né   )Úresult)ÚregisterResultTc                   @   s*   e Zd ZdZdd„ Zdd„ Zd	dd„ZdS )
Ú_WritelnDecoratorz@Used to decorate file-like objects with a handy 'writeln' methodc                 C   s
   || _ d S ©N)Ústream)Úselfr   © r	   ú&/usr/lib/python3.10/unittest/runner.pyÚ__init__   s   
z_WritelnDecorator.__init__c                 C   s   |dv rt |ƒ‚t| j|ƒS )N)r   Ú__getstate__)ÚAttributeErrorÚgetattrr   )r   Úattrr	   r	   r
   Ú__getattr__   s   z_WritelnDecorator.__getattr__Nc                 C   s   |r|   |¡ |   d¡ d S ©NÚ
)Úwrite)r   Úargr	   r	   r
   Úwriteln   s   
z_WritelnDecorator.writelnr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r	   r	   r	   r
   r      s
    r   c                       s”   e Zd ZdZdZdZ‡ fdd„Zdd„ Z‡ fdd	„Z‡ fd
d„Z	‡ fdd„Z
‡ fdd„Z‡ fdd„Z‡ fdd„Z‡ fdd„Zdd„ Zdd„ Z‡  ZS )ÚTextTestResultzhA test result class that can print formatted text results to a stream.

    Used by TextTestRunner.
    zF======================================================================zF----------------------------------------------------------------------c                    s8   t t| ƒ |||¡ || _|dk| _|dk| _|| _d S )Nr   )Úsuperr   r   r   ÚshowAllÚdotsÚdescriptions)r   r   r   Ú	verbosity©Ú	__class__r	   r
   r   %   s
   


zTextTestResult.__init__c                 C   s,   |  ¡ }| jr|rd t|ƒ|f¡S t|ƒS r   )ÚshortDescriptionr   ÚjoinÚstr)r   ÚtestÚdoc_first_liner	   r	   r
   ÚgetDescription,   s   
zTextTestResult.getDescriptionc                    sF   t t| ƒ |¡ | jr!| j |  |¡¡ | j d¡ | j ¡  d S d S )Nz ... )r   r   Ú	startTestr   r   r   r'   Úflush©r   r%   r    r	   r
   r(   3   s   ýzTextTestResult.startTestc                    óT   t t| ƒ |¡ | jr| j d¡ | j ¡  d S | jr(| j d¡ | j ¡  d S d S )NÚokÚ.)	r   r   Ú
addSuccessr   r   r   r)   r   r   r*   r    r	   r
   r.   :   ó   þzTextTestResult.addSuccessc                    óV   t t| ƒ ||¡ | jr| j d¡ | j ¡  d S | jr)| j d¡ | j ¡  d S d S )NÚERRORÚE)	r   r   ÚaddErrorr   r   r   r)   r   r   ©r   r%   Úerrr    r	   r
   r3   C   ó   þzTextTestResult.addErrorc                    r0   )NÚFAILÚF)	r   r   Ú
addFailurer   r   r   r)   r   r   r4   r    r	   r
   r9   L   r6   zTextTestResult.addFailurec                    s\   t t| ƒ ||¡ | jr| j d |¡¡ | j ¡  d S | jr,| j 	d¡ | j ¡  d S d S )Nzskipped {0!r}Ús)
r   r   ÚaddSkipr   r   r   Úformatr)   r   r   )r   r%   Úreasonr    r	   r
   r;   U   s   þzTextTestResult.addSkipc                    r0   )Nzexpected failureÚx)	r   r   ÚaddExpectedFailurer   r   r   r)   r   r   r4   r    r	   r
   r?   ^   r6   z!TextTestResult.addExpectedFailurec                    r+   )Nzunexpected successÚu)	r   r   ÚaddUnexpectedSuccessr   r   r   r)   r   r   r*   r    r	   r
   rA   g   r/   z#TextTestResult.addUnexpectedSuccessc                 C   s@   | j s| jr| j ¡  | j ¡  |  d| j¡ |  d| j¡ d S )Nr1   r7   )r   r   r   r   r)   ÚprintErrorListÚerrorsÚfailures©r   r	   r	   r
   ÚprintErrorsp   s
   

zTextTestResult.printErrorsc                 C   sb   |D ],\}}| j  | j¡ | j  d||  |¡f ¡ | j  | j¡ | j  d| ¡ | j  ¡  qd S )Nz%s: %sz%s)r   r   Ú
separator1r'   Ú
separator2r)   )r   ÚflavourrC   r%   r5   r	   r	   r
   rB   w   s   ûzTextTestResult.printErrorList)r   r   r   r   rG   rH   r   r'   r(   r.   r3   r9   r;   r?   rA   rF   rB   Ú__classcell__r	   r	   r    r
   r      s    						r   c                   @   s8   e Zd ZdZeZ		dddœdd„Zd	d
„ Zdd„ ZdS )ÚTextTestRunnerzÉA test runner class that displays results in textual form.

    It prints out the names of tests as they are run, errors as they
    occur, and a summary of the results at the end of the test run.
    NTr   F)Ú	tb_localsc          	      C   sR   |du rt j}t|ƒ| _|| _|| _|| _|| _|| _|| _	|dur'|| _
dS dS )z‰Construct a TextTestRunner.

        Subclasses should accept **kwargs to ensure compatibility as the
        interface changes.
        N)ÚsysÚstderrr   r   r   r   ÚfailfastÚbufferrL   ÚwarningsÚresultclass)	r   r   r   r   rO   rP   rR   rQ   rL   r	   r	   r
   r   ˆ   s   

ÿzTextTestRunner.__init__c                 C   s   |   | j| j| j¡S r   )rR   r   r   r   rE   r	   r	   r
   Ú_makeResultœ   s   zTextTestRunner._makeResultc                 C   s^  |   ¡ }t|ƒ | j|_| j|_| j|_t ¡ V | jr/t | j¡ | jdv r/tjdt	dd t
 ¡ }t|ddƒ}|dur@|ƒ  z||ƒ W t|ddƒ}|durS|ƒ  nt|ddƒ}|durb|ƒ  w w t
 ¡ }W d  ƒ n1 sqw   Y  || }| ¡  t|dƒrŠ| j |j¡ |j}| j d	||d
kr˜dp™d|f ¡ | j ¡  d }	 }
}ztt|j|j|jfƒ}W n	 ty¿   Y nw |\}	}
}g }| ¡ sï| j d¡ t|jƒt|jƒ}}|rå| d| ¡ |rî| d| ¡ n| j d¡ |rþ| d| ¡ |	r| d|	 ¡ |
r| d|
 ¡ |r"| j dd |¡f ¡ n| j d¡ | j ¡  |S )z&Run the given test case or test suite.)ÚdefaultÚalwaysÚmodulezPlease use assert\w+ instead.)ÚcategoryÚmessageÚstartTestRunNÚstopTestRunrH   zRan %d test%s in %.3fsr   r:   Ú r   ÚFAILEDzfailures=%dz	errors=%dÚOKz
skipped=%dzexpected failures=%dzunexpected successes=%dz (%s)z, r   ) rS   r   rO   rP   rL   rQ   Úcatch_warningsÚsimplefilterÚfilterwarningsÚDeprecationWarningÚtimeÚperf_counterr   rF   Úhasattrr   r   rH   ÚtestsRunÚmapÚlenÚexpectedFailuresÚunexpectedSuccessesÚskippedr   ÚwasSuccessfulr   rD   rC   Úappendr#   r)   )r   r%   r   Ú	startTimerY   rZ   ÚstopTimeÚ	timeTakenÚrunÚexpectedFailsri   rj   ÚresultsÚinfosÚfailedÚerroredr	   r	   r
   rp   Ÿ   sŠ   

þ
€þÿ
é
ÿ

þÿ
€
zTextTestRunner.run)NTr   FFNN)	r   r   r   r   r   rR   r   rS   rp   r	   r	   r	   r
   rK   €   s    ÿþrK   )r   rM   rb   rQ   r[   r   Úsignalsr   Ú
__unittestÚobjectr   Ú
TestResultr   rK   r	   r	   r	   r
   Ú<module>   s    c