Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib/python3.7/site-packages/xmlrunner/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/xmlrunner/__pycache__/result.cpython-37.opt-1.pyc

B

�A^�W�@s0ddlZddlZddlZddlZddlZddlZddlZddlZddlmZddlm	Z	ddlmZddl
mZmZm
Z
ddd	d
ddd
gZejdkr�e�ddddddddddddddddg�dd �eD�Ze�d!d"�e��Zd#Zd$Zd0d&d'�Zd(d)�ZGd*d+�d+ej�ZGd,d-�d-e�ZGd.d/�d/e�ZdS)1�N)�path)�StringIO)�time�)�
TestResult�_TextTestResult�failfast)r�)��)��)��)��)i�i�)i��i��i)i��i��)i��i��)i��i��)i��i��)i��i��)i��i��)i��i��)i��i��)i��	i��	)i��
i��
)i��i��)i��i��)i��
i��
)i��i��)i��i��)i��i��cCs$g|]\}}dt|�t|�f�qS)z%s-%s)�chr)�.0ZlowZhigh�r�A/opt/alt/python37/lib/python3.7/site-packages/xmlrunner/result.py�
<listcomp>)srz[%s]�z
Stdout:
%sz
Stderr:
%s�utf8cCst|�}t�d|�S)z�Return a unicode string containing only valid XML characters.

    encoding - if data is a byte string it is first decoded to unicode
        using this encoding.
    r)�str�INVALID_XML_1_0_UNICODE_RE�sub)�data�encodingrrr�safe_unicode4srcCs,t|�}|jd}|dkrd}||j}|S)N�.z	__main__.r)�type�
__module__�__name__)�test_method�testcase�module�resultrrr�
testcase_name>s

r'csHeZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	�Z
S)�_DuplicateWriterz�
    Duplicate output from the first handle to the second handle

    The second handle is expected to be a StringIO and not to block.
    cstt|���||_||_dS)N)�superr(�__init__�_first�_second)�self�first�second)�	__class__rrr*Psz_DuplicateWriter.__init__cCs|j��|j��dS)N)r+�flushr,)r-rrrr1Us
z_DuplicateWriter.flushcCsdS)NTr)r-rrr�writableYsz_DuplicateWriter.writablecCs
|j��S)N)r,�getvalue)r-rrrr3\sz_DuplicateWriter.getvaluecCs|j�|�|j�|�dS)N)r+�
writelinesr,)r-�linesrrrr4_sz_DuplicateWriter.writelinescCs^t|jtj�r:|j�|�}|dk	r6|j�|d|��|S|j�|�|j�|�t|�SdS)N)�
isinstancer+�io�
TextIOBase�writer,�len)r-�bZwroterrrr9csz_DuplicateWriter.write)r"r!�__qualname__�__doc__r*r1r2r3r4r9�
__classcell__rr)r0rr(Isr(c@s`eZdZdZed�\ZZZZedededediZ	eddddfdd�Z
d	d
�Zdd�Zd
d�Z
dS)�	_TestInfozW
    This class keeps useful information about the execution of a
    test method.
    �NZfailure�error�skippedcCs�||_||_d|_tjjjdd���|_|dk	rf|jtj	kr\t
|dj�|_t
|d�|_
n
t
|�|_
|j|_|j|_|j�|�|_||j|j	fkr�dn|j�||�|_t|�|_|��|_|r�|��|_|j�|�|_||_||_dS)Nr)�microsecondrr)�test_result�outcome�elapsed_time�datetime�min�replace�	isoformat�	timestampr?�SKIPrr"�test_exception_name�test_exception_message�_stdout_data�stdout�_stderr_data�stderr�getDescription�test_description�SUCCESS�_exc_info_to_string�test_exception_infor'�	test_name�id�test_id�filename�lineno)r-rDr#rE�err�subTestr[r\rrrr*�s,




z_TestInfo.__init__cCs|jS)N)rZ)r-rrrrY�sz_TestInfo.idcCs8|jj|jj|_tj�|jj�}|jdd���|_dS)zCSave info that can only be calculated once a test has run.
        r)rCN)	rD�	stop_time�
start_timerFrGZ
fromtimestamprIrJrK)r-rKrrr�
test_finished�sz_TestInfo.test_finishedcCs|jS)z_
        Return a text representation of an exception thrown by a test
        method.
        )rW)r-rrr�get_error_info�sz_TestInfo.get_error_info)r"r!r<r=�rangerU�FAILURE�ERRORrL�OUTCOME_ELEMENTSr*rYrarbrrrrr?ss r?cseZdZdZejdddddfdd�Zdd�Zd	d
�Z�fdd�Z	�fd
d�Z
dd�Zdd�Zdd�Z
edd��Zedd��Zdd�Zdd�Zdd�Zedd ��Zd!d"�Zd#d$�Zd%d&�Zee�Zd'd(�Zee�Zd)d*�Zee�Zd+d,�Zee�Zd-d.�Zee�Zd/d0�Z�fd1d2�Z�ZS)3�_XMLTestResultzh
    A test result class that can express test results in a XML report.

    Used by XMLTestRunner.
    rTNcCsvt�||||�d|_d|_t�|_d|_t�|_d|_g|_	d|_
||_||_d|_
d|_|dkrlt|_n||_dS)N)rr*rOrQr�_stdout_capture�_XMLTestResult__stdout_saved�_stderr_capture�_XMLTestResult__stderr_saved�	successes�callback�
elapsed_times�
propertiesr[r\r?�	infoclass)r-�streamZdescriptions�	verbosityrnrorprrrr*�s z_XMLTestResult.__init__cs6�j�_�j�_|�������fdd�}|�_dS)z�
        Appends a `infoclass` to the given target list and sets a callback
        method to be called by stopTest method.
        csX����jsd�_�_�jr8�j�d��jf�n�jrJ�j�	���j�
�dS)zcPrints the test method outcome to the stream, as well as
            the elapsed time.
            rz
%s (%.3fs)N)rarnr`r_�showAllrq�writelnrFZdotsr9r1r)r-�	short_str�	test_info�verbose_strrrrm�sz2_XMLTestResult._prepare_callback.<locals>.callbackN)r[r\�appendrm)r-rvZtarget_listrwrurmr)r-rurvrwr�_prepare_callback�s

z _XMLTestResult._prepare_callbackc
Cs�t�|_t�||�yft|dd�dk	r<|jj|_|jj|_n<t||j�}t	|�}t
�|�|_t|d|�}t
�|�\}|_Wnt
ttfk
r�YnX|jr�|j�d|�|��|j�d�|j��dS)z9
        Called before execute each test method.
        �_dt_testN�funcz  z ... )rr`r�	startTest�getattrrzr[r\Z_testMethodNamer �inspectZ
getsourcefileZgetsourcelines�AttributeError�IOError�	TypeErrorrsrqr9rSr1)r-�testr#Z
test_class�_rrrr|�s"
z_XMLTestResult.startTestcsBtt|���tj|_ttj|j�t_tj|_	ttj|j
�t_dS)zN
        Capture stdout / stderr by replacing sys.stdout / sys.stderr
        N)r)rg�_setupStdout�sysrPrir(rhrRrkrj)r-)r0rrr�s
z_XMLTestResult._setupStdoutcsf|jr|jt_d|_|jr(|jt_d|_|j�d�|j��|j�d�|j��t	t
|���dS)zT
        Stop capturing stdout / stderr and recover sys.stdout / sys.stderr
        Nr)rir�rPrkrRrh�seek�truncaterjr)rg�_restoreStdout)r-)r0rrr�s

z_XMLTestResult._restoreStdoutcCs|j��|_|j��|_dS)N)rhr3rOrjrQ)r-rrr�_save_output_data)sz _XMLTestResult._save_output_datacCs>|��t�||�t�|_|jr:t|j�r:|��d|_dS)z8
        Called after execute each test method.
        N)r�r�stopTestrr_rm�callable)r-r�rrrr�-sz_XMLTestResult.stopTestcCs&|��|�|�||�|jdd�dS)z;
        Called when a test executes successfully.
        �okrN)r�ryrprl)r-r�rrr�
addSuccess<sz_XMLTestResult.addSuccesscCsH|��|�|||jj|�}|j�||�||�f�|�|gdd�dS)z2
        Called when a test method fails.
        �FAIL�FN)r�rprd�failuresrxrVry)r-r�r]�testinforrr�
addFailureEsz_XMLTestResult.addFailurecCsH|��|�|||jj|�}|j�||�||�f�|�|gdd�dS)z<
        Called when a test method raises an error.
        re�EN)r�rpre�errorsrxrVry)r-r�r]r�rrr�addErrorSsz_XMLTestResult.addErrorcCs�|dk	r�d}d}d}t|d|j�r8d}|jj}|j}nd}|jj}|j}|��|j|||||d�}|�||�	||�f�|�
|g||d�dS)z?
        Called when a subTest method raises an error.
        Nrr�re)r^)�
issubclassZfailureExceptionrprdr�rer�r�rxrVry)r-r$r�r]Z	errorTextZ
errorValueZ	errorListr�rrr�
addSubTestas$z_XMLTestResult.addSubTestcCsL|��|�|||jj|�}d|_||_|j�||f�|�|gdd�dS)z8
        Called when a test method was skipped.
        �skip�sN)r�rprLrMrNrBrxry)r-r��reasonr�rrr�addSkip~sz_XMLTestResult.addSkipcCs\|��|�|||jj|�}d|_d�|j�|_|j�||�||�f�|�	|gdd�dS)zL
        Missing in xmlrunner, copy-pasted from xmlrunner addError.
        ZXFAILzexpected failure: {}zexpected failure�xN)
r�rprLrM�formatrN�expectedFailuresrxrVry)r-r�r]r�rrr�addExpectedFailure�sz!_XMLTestResult.addExpectedFailurecCsN|��|�||�}|jj|_d|_d|_|j�|df�|�|gdd�dS)zN
        Missing in xmlrunner, copy-pasted from xmlrunner addSuccess.
        ZUnexpectedSuccesszYUnexpected success: This test was marked as expected failure but passed, please review itzunexpected success�uN)	r�rprerErMrN�unexpectedSuccessesrxry)r-r�r�rrr�addUnexpectedSuccess�s
z#_XMLTestResult.addUnexpectedSuccesscCsjxd|D]\\}}|j�|j�|j�d||j|jf�|j�|j�|j�d|���|j��qWdS)zK
        Writes information about the FAIL or ERROR to the stream.
        z%s [%.3fs]: %sz%sN)rqrtZ
separator1rFrTZ
separator2rbr1)r-Zflavourr�rvZdummyrrr�printErrorList�sz_XMLTestResult.printErrorListcCsri}xh|j|j|j|j|j|jfD]H}xB|D]:}t|t�rB|d}|j}||krXg||<||�	|�q,Wq"W|S)z�
        Organizes test results by TestCase module. This information is
        used during the report generation, where a XML report will be created
        for each TestCase.
        r)
rlr�r�rBr�r�r6�tuplerXrx)r-Ztests_by_testcase�testsrvr'rrr�_get_info_by_testcase�s

z$_XMLTestResult._get_info_by_testcasecCsf|rb|�d�}|�|�xH|��D]<\}}|�d�}|�dt|��|�dt|��|�|�q"WdS)Nro�property�name�value)�
createElement�appendChild�items�setAttributer)�
xml_testsuite�xml_documentroZxml_properties�keyr�Zproprrr�_report_testsuite_properties�s


z+_XMLTestResult._report_testsuite_propertiescCs<|�d�}|�|�|�d�d}|�dd�d}|�d|�|�dtt|���|�d|�|�d	d
ttdd�|���|r�|�d
t	tdd�|���t
dd�|�}|�dttt|����t
dd�|�}	|�dttt|	����t
dd�|�}
|�dttt|
����t�
|||�x|D]}t�|||��q W|S)zD
        Appends the testsuite section to the XML document.
        �	testsuiterr�/z.pyr�r��filerz%.3fcSs|jS)N)rF)�errr�<lambda>��z2_XMLTestResult._report_testsuite.<locals>.<lambda>rKcSs|jS)N)rK)r�rrrr��r�cSs|j|jkS)N)rErd)r�rrrr��r�r�cSs|j|jkS)N)rEre)r�rrrr��r�r�cSs|jtjkS)N)rEr?rL)r�rrrr��r�rB)r�r��
rpartitionrIr�rr:�sum�map�max�filter�listrgr��_report_testcase)�
suite_namer�r��
parentElementror�Zmodule_name�	file_namer�r�Zskipsr�rrr�_report_testsuite�s.



z _XMLTestResult._report_testsuitecCs|�d�dS)z/
        Returns the test method name.
        r���)�split)rZrrr�_test_method_name�sz _XMLTestResult._test_method_namecCsvt|�}|�d�}xJ|dkr\|d|d�}|�|�}|�|�||dd�}|�d�}qW|�|�}|�|�dS)Nz]]>r�)r�findZcreateCDATASectionr�)ZxmldocZnode�text�posZtmpZcdatarrr�_createCDATAsectionss




z#_XMLTestResult._createCDATAsectionsc
Cs�|�d�}|�|�t�dd|���}|�d�d}|�d|�|�dt�|j	��|�dd	|j
�|�d
|j�|jdk	r�t
j�|j�}|�d�r�|jn|}|�d
|�|jdk	r�|�dt|j��|j|j}|dk	�r2|�|�}|�|�|�d|j�|�d|j�|���r2t|���}t�|||�|jdk	�rb|�d�}	|�|	�t�||	|j�|jdk	�r�|�d�}	|�|	�t�||	|j�dS)zA
        Appends a testcase section to the XML document.
        r$z
^__main__.rrrZ	classnamer�rz%.3frKNz../r��liner �messagez
system-outz
system-err)r�r��rerrYr�r�rgr�rZrFrKr[�osr�relpath�
startswithr\rrfrErMrNrbrr�rPrR)
rDr�r�r$�
class_namer[Zresult_elem_nameZresult_elemZ
error_infoZ	systemoutrrrr�sN












z_XMLTestResult._report_testcasec
Cs4ddlm}|��}t|jt�}|r>tj�|j�s>t�	|j�|s`|�}|�
d�}|�|�|}x�|��D]�\}}	|r�|�}|}|}
|j
r�d||j
f}
t�|
|	|||j�}|rj|jd|jd�}t�|jd|
�}t|d��}
|
�|�Wd	QRX|jrj|j�d
�|��qjW|�s0|jd|jd�}|j�|�d	S)zL
        Generates the XML reports to a given XMLTestRunner object.
        r)�DocumentZ
testsuitesz%s-%s�	)�indentrzTEST-%s.xml�wbNzGenerated XML report: {})Zxml.dom.minidomr�r�r6�outputrr�r�exists�makedirsr�r�r�Z	outsuffixrgr�roZtoprettyxmlr�join�openr9rsrqrtr�)r-Ztest_runnerr�Zall_resultsZoutputHandledAsString�docr�r�Zsuiter�r�Zxml_contentr[Zreport_filerrr�generate_reportsOsF




z_XMLTestResult.generate_reportscstt|��||�S)z>Converts a sys.exc_info()-style tuple of values into a string.)r)rgrV)r-r]r�)r0rrrV�sz"_XMLTestResult._exc_info_to_string) r"r!r<r=r�rRr*ryr|r�r�r�r�r�rr�r�r�r�r�r�r�r�r��staticmethodr�r�r�r�r�rVr>rr)r0rrg�s< 
	

&88rg)r)r~r7r�r�rGr�	tracebackr�rrZunittestrrrZ_illegal_unichrs�
maxunicode�extendZ_illegal_ranges�compiler�rZSTDOUT_LINEZSTDERR_LINErr'r8r(�objectr?rgrrrr�<module>sD



*C