B
    v9a                 @   s8  d dl Z d dlZd dlZd dlZd dlZd dlZd dlm  mZ	 d dl
m
Z
 G dd dejZG dd dZddd	Zdd
dZedkr4G dd dejZe Zeee e Zeedd ejD ZeejZeeZe de!  e ddd x(e	"e# D ]Z$e e$% dd qW e   dS )    N)datetimec                   s   e Zd ZdZdZ fddZedd Z fddZd"d
dZ	dd Z
e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d d! Z  ZS )#RegressionTestResultzG======================================================================
zG----------------------------------------------------------------------
c                s\   t  j||dd d| _td| _| jdt 	d d | _
d | _g | _t|| _d S )Nr   )streamdescriptions	verbosityTZ	testsuitestart )super__init__bufferETZElement_RegressionTestResult__suitesetr   ZutcnowZ	isoformat_RegressionTestResult__e!_RegressionTestResult__start_timeZ_RegressionTestResult__resultsbool_RegressionTestResult__verbose)selfr   r   r   )	__class__  /usr/lib/python3.7/testresult.pyr
      s    zRegressionTestResult.__init__c             C   sL   y
|j }W n tk
r"   t|S X y| S  tk
rB   t|S X t|S )N)idAttributeErrorstr	TypeErrorrepr)clstestZtest_idr   r   r   Z__getId   s    


zRegressionTestResult.__getIdc                sV   t  | t| jd | _}t | _| j	rR| j
| | d | j
  d S )NZtestcasez ... )r	   	startTestr   
SubElementr   r   timeperf_counterr   r   r   writegetDescriptionflush)r   r   e)r   r   r   r   +   s    
zRegressionTestResult.startTestFc          	   K   sL  | j }d | _ |d krd S |d|d| | |d|dd |d|dd | jrz|dt | j d |r| jd k	r| j 	 }|t
|d_| jd k	r| j 	 }|t
|d	_x|| D ]p\}}|r|sqt
||}	t|d
r:xD| D ],\}
}|
r(|	|
t| n
t||	_qW qt||	_qW d S )NnamestatusrunresultZ	completedr    z0.6fz
system-outz
system-erritems)r   r   pop_RegressionTestResult__getIdr   r    r!   Z_stdout_buffergetvaluerstripr   r   textZ_stderr_bufferr*   hasattrr   )r   r   Zcaptureargsr%   stdoutstderrkvZe2Zk2Zv2r   r   r   _add_result3   s4    

z RegressionTestResult._add_resultc             C   s   | j r| j| d d S )N
)r   r   r"   )r   cZwordr   r   r   Z__writeS   s    zRegressionTestResult.__writec             C   sl   t |tr0|jdkr|j}q8|j d|j }nt|}t||d }t|||}|d|d|dS )Nbuiltins. )typemessager;   )
isinstancer<   
__module____name__r   	tracebackformat_exceptionjoin)r   Zerr_typeZ	err_valueZerr_tbtypenamemsgtbr   r   r   Z__makeErrorDictW   s    

z$RegressionTestResult.__makeErrorDictc                s4   | j |d| j| d t || | dd d S )NT)errorEERROR)r6   $_RegressionTestResult__makeErrorDictr	   addError_RegressionTestResult__write)r   r   err)r   r   r   rK   j   s    zRegressionTestResult.addErrorc                s4   | j |d| j| d t || | dd d S )NT)outputxzexpected failure)r6   rJ   r	   addExpectedFailurerL   )r   r   rM   )r   r   r   rP   o   s    z'RegressionTestResult.addExpectedFailurec                s4   | j |d| j| d t || | dd d S )NT)ZfailureFFAIL)r6   rJ   r	   
addFailurerL   )r   r   rM   )r   r   r   rS   t   s    zRegressionTestResult.addFailurec                s2   | j ||d t || | dd| d S )N)ZskippedSzskipped )r6   r	   addSkiprL   )r   r   reason)r   r   r   rU   y   s    zRegressionTestResult.addSkipc                s&   |  | t | | dd d S )Nr:   ok)r6   r	   
addSuccessrL   )r   r   )r   r   r   rX   ~   s    
zRegressionTestResult.addSuccessc                s*   | j |dd t | | dd d S )NZUNEXPECTED_SUCCESS)Zoutcomeuzunexpected success)r6   r	   addUnexpectedSuccessrL   )r   r   )r   r   r   rZ      s    z)RegressionTestResult.addUnexpectedSuccessc             C   s2   | j r| jd | d| j | d| j d S )Nr7   rI   rR   )r   r   r"   printErrorListerrorsfailures)r   r   r   r   printErrors   s    z RegressionTestResult.printErrorsc             C   s`   xZ|D ]R\}}| j | j | j | d| | d | j | j | j d|  qW d S )Nz: r7   z%s
)r   r"   
separator1r#   
separator2)r   Zflavorr\   r   rM   r   r   r   r[      s
    z#RegressionTestResult.printErrorListc             C   sH   | j }|dt| j |dtt| j |dtt| j |S )NZtestsr\   r]   )r   r   r   ZtestsRunlenr\   r]   )r   r%   r   r   r   get_xml_element   s
    z$RegressionTestResult.get_xml_element)F)r@   r?   __qualname__r_   r`   r
   classmethodr,   r   r6   rL   rJ   rK   rP   rS   rU   rX   rZ   r^   r[   rb   __classcell__r   r   )r   r   r      s"   
 r   c               @   s   e Zd ZdddZdd ZdS )QuietRegressionTestRunnerFc             C   s   t |d d| _|| j_d S )Nr   )r   r)   r   )r   r   r   r   r   r   r
      s    z"QuietRegressionTestRunner.__init__c             C   s   || j  | j S )N)r)   )r   r   r   r   r   r(      s    
zQuietRegressionTestRunner.runN)F)r@   r?   rc   r
   r(   r   r   r   r   rf      s   
rf   Fc             C   s&   | rt jtjt|| dS t jt|dS )N)Zresultclassr   r   )r   )	functoolspartialunittestZTextTestRunnerr   rf   )r   r   r   r   r   get_test_runner_class   s    rj   c             C   s   t ||| S )N)rj   )r   r   Zcapture_outputr   r   r   get_test_runner   s    rk   __main__c               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
	TestTestsc             C   s   d S )Nr   )r   r   r   r   	test_pass   s    zTestTests.test_passc             C   s   t d d S )Ng      ?)r    Zsleep)r   r   r   r   test_pass_slow   s    zTestTests.test_pass_slowc             C   s*   t dtjd t dtjd | d d S )Nr2   )filer3   zfailure message)printsysr2   r3   Zfail)r   r   r   r   	test_fail   s    zTestTests.test_failc             C   s(   t dtjd t dtjd tdd S )Nr2   )rp   r3   zerror message)rq   rr   r2   r3   RuntimeError)r   r   r   r   
test_error   s    zTestTests.test_errorN)r@   r?   rc   rn   ro   rs   ru   r   r   r   r   rm      s   rm   c             c   s   | ]}|d kV  qdS )z-vNr   ).0ar   r   r   	<genexpr>   s    rx   zOutput:zXML: r;   )end)F)F)&rg   iorr   r    rA   ri   Zxml.etree.ElementTreeZetreeZElementTreer   r   ZTextTestResultr   rf   rj   rk   r@   ZTestCaserm   Z	TestSuiteZsuiteZaddTestZ	makeSuiteStringIOr   sumargvZ
runner_clsr2   Zrunnerr(   r)   rq   r-   Ztostringlistrb   sdecoder   r   r   r   <module>   s2    	




