U
    ZeU                     @   s   d Z ddlZzddlmZ W n  ek
r<   ddlmZ Y nX 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 X d S )Nz<unprintable %s object>)strtype__name__)exc r
   j/mounts/lovelace/software/anaconda3/envs/qiime2-amplicon-2024.2/lib/python3.8/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 kri }|| _ |d k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k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k
r8   |  |}Y nX t| j D ]J\}\}}	}
t|rHt||rH|
rrd|_|||f | 	|	|  dS qH| 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   err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 k	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   message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   pluginsreportr   r   r,   r   r   r   r
   r
   r   r8   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FAILED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   r5   r2   floatZtestsRunZ
separator2r$   r   r9   lenr@   r'   wasSuccessfulr%   sortr3   )r   startstopr5   r2   ZtakenrunpluralsummaryZeckeysr,   r   r   r   rC   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   r9   r=   r
   r
   r   rH      s    zTextTestResult.wasSuccessfulc                 C   sj   z|  ||}W n tk
r.   |  |}Y nX | j||f | jrT| jd n| jrf| jd d S )Nr!   E)r"   r#   r'   r   r1   r   r5   r4   )r   r   r(   r+   r
   r
   r   	_addError   s    zTextTestResult._addErrorc                 C   sh   ddl m} t|d r2t|d |r2t|d S zt| ||W S  tk
rb   t| | Y S X 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   r8   rO   rH   rQ   r"   r
   r
   r
   r   r      s     


)r   c                  O   s    ddl m} |dt t| |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 )warningsrU   DeprecationWarning_ln)argkwrU   r
   r
   r   r      s
    r   )rT   loggingZunittest.runnerr   ImportErrorZunittestZnose.configr   Z	nose.utilr   r   rX   	getLoggerlogr   r   r
   r
   r
   r   <module>   s   

 #