B
    Ր<[U                 @   s   d Z ddlZy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"   yt | S    dt| j S d S )Nz<unprintable %s object>)strtype__name__)exc r
   *lib/python3.7/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   |\}}}y|  ||}W n tk
r8   |  |}Y nX xZt| j D ]H\}\}}	}
t|rJt||rJ|
rtd|_|||f | 	|	| dS qJW | 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 )N)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   messageZdetailr
   r
   r   r   V   s    
zTextTestResult.printLabelc             C   s`   t |  x6t| j D ]$}| j| \}}}|r| || qW t| dr\| jj	| j
 dS )z<Overrides to print all errorClasses errors as well.
        r   N)r   printErrorsr"   r   keysZprintErrorListhasattrr   ZpluginsZreportr   )r   r)   r   r   r   r
   r
   r   r4   d   s    

zTextTestResult.printErrorsc             C   s2  | j j}| j j}t|| }| j}|dkr.dp0d}|| j |d|||f  |  i }t| j }	x2|	D ]*}
| j|
 \}}}t	|}|sql|||< qlW t	| 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   r2   r/   floatZtestsRunZ
separator2r"   r   r5   lenr9   r%   wasSuccessfulr#   sortr0   )r   startstopr2   r/   ZtakenrunZpluralZsummaryZeckeysr)   r   r   r   r;   r#   r
   r
   r   printSummaryp   s>    





zTextTestResult.printSummaryc             C   sJ   | j s| jrdS x4t| j D ]"}| j| \}}}|s:q |r dS q W 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%   r9   r"   r   r5   )r   r)   r   r   r   r
   r
   r   r@      s    zTextTestResult.wasSuccessfulc             C   sj   y|  ||}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   r.   r   r2   r1   )r   r   r&   r(   r
   r
   r   	_addError   s    zTextTestResult._addErrorc             C   sb   ddl m} t|d r2t|d |r2t|d S yt| ||S  tk
r\   t| |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   r4   rE   r@   rG   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 )warningsrK   DeprecationWarning_ln)argkwrK   r
   r
   r   r      s    r   )rJ   ZloggingZunittest.runnerr   ImportErrorZunittestZnose.configr   Z	nose.utilr   r   rN   Z	getLoggerlogr   r   r
   r
   r
   r   <module>	   s   
 #