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.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)�.0�low�high�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_unicode4sr cCs,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/rrrr3Us
z_DuplicateWriter.flushcCsdS)NTr)r/rrr�writableYsz_DuplicateWriter.writablecCs
|j��S)N)r.�getvalue)r/rrrr5\sz_DuplicateWriter.getvaluecCs|j�|�|j�|�dS)N)r-�
writelinesr.)r/�linesrrrr6_sz_DuplicateWriter.writelinescCs^t|jtj�r:|j�|�}|dk	r6|j�|d|��|S|j�|�|j�|�t|�SdS)N)�
isinstancer-�io�
TextIOBase�writer.�len)r/�bZwroterrrr;csz_DuplicateWriter.write)r$r#�__qualname__�__doc__r,r3r4r5r6r;�
__classcell__rr)r2rr*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�	timestamprA�SKIPr r$�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/rFr%rG�err�subTestr]r^rrrr,�s,




z_TestInfo.__init__cCs|jS)N)r\)r/rrrr[�sz_TestInfo.idcCs8|jj|jj|_tj�|jj�}|jdd���|_dS)zCSave info that can only be calculated once a test has run.
        r)rEN)	rF�	stop_time�
start_timerHrI�
fromtimestamprKrLrM)r/rMrrr�
test_finished�sz_TestInfo.test_finishedcCs|jS)z_
        Return a text representation of an exception thrown by a test
        method.
        )rY)r/rrr�get_error_info�sz_TestInfo.get_error_info)r$r#r>r?�rangerW�FAILURE�ERRORrN�OUTCOME_ELEMENTSr,r[rdrerrrrrAss rAcseZdZdZejdddddfdd�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,rQrSr�_stdout_capture�_XMLTestResult__stdout_saved�_stderr_capture�_XMLTestResult__stderr_saved�	successes�callback�
elapsed_times�
propertiesr]r^rA�	infoclass)r/�streamZdescriptions�	verbosityrqrrrsrrrr,�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)rdrqrbra�showAllrt�writelnrHZdotsr;r3r)r/�	short_str�	test_info�verbose_strrrrp�sz2_XMLTestResult._prepare_callback.<locals>.callbackN)r]r^�appendrp)r/ryZtarget_listrzrxrpr)r/rxryrzr�_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 ... )rrbr�	startTest�getattrr}r]r^Z_testMethodNamer"�inspect�
getsourcefile�getsourcelines�AttributeError�IOError�	TypeErrorrvrtr;rUr3)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+rj�_setupStdout�sysrRrlr*rkrTrnrm)r/)r2rrr�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)rlr�rRrnrTrk�seek�truncatermr+rj�_restoreStdout)r/)r2rrr�s

z_XMLTestResult._restoreStdoutcCs|j��|_|j��|_dS)N)rkr5rQrmrS)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�stopTestrrarp�callable)r/r�rrrr�-sz_XMLTestResult.stopTestcCs&|��|�|�||�|jdd�dS)z;
        Called when a test executes successfully.
        �okr!N)r�r|rsro)r/r�rrr�
addSuccess<sz_XMLTestResult.addSuccesscCsH|��|�|||jj|�}|j�||�||�f�|�|gdd�dS)z2
        Called when a test method fails.
        �FAIL�FN)r�rsrg�failuresr{rXr|)r/r�r_�testinforrr�
addFailureEsz_XMLTestResult.addFailurecCsH|��|�|||jj|�}|j�||�||�f�|�|gdd�dS)z<
        Called when a test method raises an error.
        rh�EN)r�rsrh�errorsr{rXr|)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�rh)r`)�
issubclassZfailureExceptionrsrgr�rhr�r�r{rXr|)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�rsrNrOrPrDr{r|)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�rsrNrO�formatrP�expectedFailuresr{rXr|)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�rsrhrGrOrP�unexpectedSuccessesr{r|)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)rtrwZ
separator1rHrVZ
separator2rer3)r/Zflavourr�ry�dummyrrr�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)
ror�r�rDr�r�r8�tuplerZr{)r/Ztests_by_testcase�testsryr)rrr�_get_info_by_testcase�s

z$_XMLTestResult._get_info_by_testcasecCsf|rb|�d�}|�|�xH|��D]<\}}|�d�}|�dt|��|�dt|��|�|�q"WdS)Nrr�property�name�value)�
createElement�appendChild�items�setAttributer)�
xml_testsuite�xml_documentrrZxml_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.
        �	testsuiter!r�/z.pyr�r��filerz%.3fcSs|jS)N)rH)�errr�<lambda>��z2_XMLTestResult._report_testsuite.<locals>.<lambda>rMcSs|jS)N)rM)r�rrrr��r�cSs|j|jkS)N)rGrg)r�rrrr��r�r�cSs|j|jkS)N)rGrh)r�rrrr��r�r�cSs|jtjkS)N)rGrArN)r�rrrr��r�rD)r�r��
rpartitionrKr�rr<�sum�map�max�filter�listrjr��_report_testcase)�
suite_namer�r��
parentElementrrr��module_name�	file_namer�r�Zskipsr�rrr�_report_testsuite�s.



z _XMLTestResult._report_testsuitecCs|�d�dS)z/
        Returns the test method name.
        r!���)�split)r\rrr�_test_method_name�sz _XMLTestResult._test_method_namecCsvt|�}|�d�}xJ|dkr\|d|d�}|�|�}|�|�||dd�}|�d�}qW|�|�}|�|�dS)Nz]]>r�)r �findZcreateCDATASectionr�)Zxmldoc�node�text�pos�tmpZcdatarrr�_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__.rr!r�	classnamer�rz%.3frMNz../r��liner"�messagez
system-outz
system-err)r�r��rerr[r�r�rjr�r\rHrMr]�osr�relpath�
startswithr^rrirGrOrPrer r�rRrT)
rFr�r�r&�
class_namer]Zresult_elem_nameZresult_elem�
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�r8�outputrr�r�exists�makedirsr�r�r�Z	outsuffixrjr�rrZtoprettyxmlr�join�openr;rvrtrwr�)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+rjrX)r/r_r�)r2rrrX�sz"_XMLTestResult._exc_info_to_string) r$r#r>r?r�rTr,r|rr�r�r�r�r�rr�r�r�r�r�r�r�r�r��staticmethodr�r�r�r�r�rXr@rr)r2rrj�s< 
	

&88rj)r)r�r9r�r�rIr�	tracebackr�rr�unittestrrrZ_illegal_unichrs�
maxunicode�extendZ_illegal_ranges�compiler�rZSTDOUT_LINEZSTDERR_LINEr r)r:r*�objectrArjrrrr�<module>sD



*C