a
    aU                     @   s   d Z ddlZzddlmZ W n ey:   ddlmZ Y n0 ddlmZ ddlm	Z	m
Z edZdd ZG d	d
 d
eZdd Z
dS )z
Test Result
-----------

Provides a TextTestResult that extends unittest's _TextTestResult to
provide support for error classes (such as the builtin skip and
deprecated classes), and hooks for plugins to take over or extend
reporting.
    N)_TextTestResult)Config)isclasslnznose.resultc                 C   s*   z
t | W S    dt| j  Y S 0 d S )Nz<unprintable %s object>)strtype__name__)exc r
   *lib/python3.9/site-packages/nose/result.py_exception_detail   s    
r   c                   @   sf   e Zd ZdZdddZdd Zdd Zd	d
 ZdddZdd Z	dd Z
dd Zdd ZdddZdS )TextTestResultzText test result that extends unittest's default test result
    support for a configurable set of errorClasses (eg, Skip,
    Deprecated, TODO) that extend the errors/failures/success triad.
    Nc                 C   s:   |d u ri }|| _ |d u r t }|| _t| ||| d S N)errorClassesr   configr   __init__)selfstreamdescriptions	verbosityr   r   r
   r
   r   r   $   s    zTextTestResult.__init__c                 C   sJ   ddl m} || jv rF| j| \}}}|||f | |||d f d S )Nr   SkipTest)nose.plugins.skipr   r   append
printLabel)r   testreasonr   storagelabelisfailr
   r
   r   addSkip.   s
    
zTextTestResult.addSkipc                 C   s   |\}}}z|  ||}W n ty6   |  |}Y n0 t| j D ]J\}\}}	}
t|rFt||rF|
rpd|_|||f | 	|	|  dS qF| j
||f d|_| 	d dS )zOverrides normal addError to add support for
        errorClasses. If the exception is a registered class, the
        error will be added to the list for that class, not errors.
        FNERROR)_exc_info_to_string	TypeErrorlistr   itemsr   
issubclassZpassedr   r   errors)r   r   errZecZevtbexc_infoclsr   r   r   r
   r
   r   addError6   s    
zTextTestResult.addErrorc                 C   s"   | j r| pt|S t|S d S r   )r   ZshortDescriptionr   )r   r   r
   r
   r   getDescriptionP   s    zTextTestResult.getDescriptionc                 C   sl   t | dd }|d urh| jrP|g}|r>t|d }|r>|| |d| n| jrh||d d  d S )Nr      z: )getattrshowAllr   r   writelnjoindotswrite)r   r   r(   r   messageZdetailr
   r
   r   r   V   s    
zTextTestResult.printLabelc                 C   s\   t |  t| j D ]$}| j| \}}}|r| || qt| drX| jj	| j
 dS )z<Overrides to print all errorClasses errors as well.
        r   N)r   printErrorsr$   r   keysZprintErrorListhasattrr   Zpluginsreportr   r   r+   r   r   r   r
   r
   r   r6   d   s    

zTextTestResult.printErrorsc                 C   s.  | j j}| j j}t|| }| j}|dkr.dp0d}|| j |d|||f  |  i }t| j }	|	D ]*}
| j|
 \}}}t	|}|sqj|||< qjt	| j
rt	| j
|d< t	| jrt	| j|d< |  s|d n|d t| }|r$|  |d	 |d
dd |D  |d n|  dS )zZCalled by the test runner to print the final summary of test
        run results.
        r.   s zRan %s test%s in %.3fsfailuresr'   ZFAILEDZOKz (z, c                 S   s   g | ]\}}d ||f qS )z%s=%sr
   ).0r   countr
   r
   r   
<listcomp>   s   z/TextTestResult.printSummary.<locals>.<listcomp>)N)r   r4   r1   floatZtestsRunZ
separator2r$   r   r7   lenr=   r'   wasSuccessfulr%   sortr2   )r   startstopr4   r1   ZtakenrunpluralZsummaryZeckeysr+   r   r   r   r?   r%   r
   r
   r   printSummaryp   s@    






zTextTestResult.printSummaryc                 C   sH   | j s| jrdS t| j D ]$}| j| \}}}|s8q|r dS qdS )zOverrides to check that there are no errors in errorClasses
        lists that are marked as errors and should cause a run to
        fail.
        FT)r'   r=   r$   r   r7   r:   r
   r
   r   rD      s    zTextTestResult.wasSuccessfulc                 C   sh   z|  ||}W n ty,   |  |}Y n0 | j||f | jrR| jd n| jrd| jd d S )Nr!   E)r"   r#   r'   r   r0   r   r4   r3   )r   r   r(   r*   r
   r
   r   	_addError   s    zTextTestResult._addErrorc                 C   sf   ddl m} t|d r2t|d |r2t|d S zt| ||W S  ty`   t| | Y S 0 d S )Nr   r   r.   )r   r   r   r&   r   r   r"   r#   )r   r(   r   r   r
   r
   r   r"      s    z"TextTestResult._exc_info_to_string)NN)N)N)r   
__module____qualname____doc__r   r    r,   r-   r   r6   rJ   rD   rL   r"   r
   r
   r
   r   r      s     


)r   c                  O   s$   ddl m} |dt t| i |S )Nr   )warnzln() has moved to nose.util from nose.result and will be removed from nose.result in a future release. Please update your imports )warningsrP   DeprecationWarning_ln)argkwrP   r
   r
   r   r      s
    r   )rO   loggingZunittest.runnerr   ImportErrorZunittestZnose.configr   Z	nose.utilr   r   rS   Z	getLoggerlogr   r   r
   r
   r
   r   <module>   s   

 #