Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/Cython/Tests/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/Cython/Tests/__pycache__/xmlrunner.cpython-37.pyc

B

Z��Z�9�@s�dZddlmZddlZddlZddlZddlmZmZm	Z	ddl
ZyddlmZWn e
k
rtddlmZYnXGdd�dejjj�ZGdd	�d	e�ZGd
d�de�ZGdd
�d
e	�ZdS)a!unittest-xml-reporting is a PyUnit-based TestRunner that can export test
results to XML files that can be consumed by a wide range of tools, such as
build systems, IDEs and Continuous Integration servers.

This module provides the XMLTestRunner class, which is heavily based on the
default TextTestRunner. This makes the XMLTestRunner very simple to use.

The script below, adapted from the unittest documentation, shows how to use
XMLTestRunner in a very simple way. In fact, the only difference between this
script and the original one is the last line:

import random
import unittest
import xmlrunner

class TestSequenceFunctions(unittest.TestCase):
    def setUp(self):
        self.seq = range(10)

    def test_shuffle(self):
        # make sure the shuffled sequence does not lose any elements
        random.shuffle(self.seq)
        self.seq.sort()
        self.assertEqual(self.seq, range(10))

    def test_choice(self):
        element = random.choice(self.seq)
        self.assert_(element in self.seq)

    def test_sample(self):
        self.assertRaises(ValueError, random.sample, self.seq, 20)
        for element in random.sample(self.seq, 5):
            self.assert_(element in self.seq)

if __name__ == '__main__':
    unittest.main(testRunner=xmlrunner.XMLTestRunner(output='test-reports'))
�)�absolute_importN)�
TestResult�_TextTestResult�TextTestRunner)�StringIOc@seZdZdd�ZdS)�XMLDocumentcCsd|kr|�|�S|�|�S)Nz]]>)ZcreateTextNodeZcreateCDATASection)�self�data�r
�I/opt/alt/python37/lib64/python3.7/site-packages/Cython/Tests/xmlrunner.py�createCDATAOrText7s
zXMLDocument.createCDATAOrTextN)�__name__�
__module__�__qualname__rr
r
r
rr6src@sDeZdZdZed�\ZZZedfdd�Zdd�Z	dd	�Z
d
d�ZdS)�	_TestInfoz\This class is used to keep useful information about the execution of a
    test method.
    �NcCsP||_||_||_||_|jr,|j����p.d|_|jrF|j����pHd|_dS)z#Create a new instance of _TestInfo.�N)�test_result�test_method�outcome�err�stdout�getvalue�strip�stderr)rrrrrr
r
r�__init__Esz_TestInfo.__init__cCs|jj|jjS)zUReturn the time that shows how long the test method took to
        execute.
        )r�	stop_time�
start_time)rr
r
r�get_elapsed_timeNsz_TestInfo.get_elapsed_timecCs|j�|j�S)z0Return a text representation of the test method.)r�getDescriptionr)rr
r
r�get_descriptionTsz_TestInfo.get_descriptioncCs|js
dS|j�|j|j�S)zVReturn a text representation of an exception thrown by a test
        method.
        r)rrZ_exc_info_to_stringr)rr
r
r�get_error_infoXsz_TestInfo.get_error_info)r
rr�__doc__�range�SUCCESS�FAILURE�ERRORrrr r!r
r
r
rr=s	rc@s�eZdZdZejdddfdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zee�Zdd�Zee�Zdd�Zee�Zd d!�Zd"S)#�_XMLTestResultzcA test result class that can express test results in a XML report.

    Used by XMLTestRunner.
    �TcCs,t�||||�g|_d|_||_d|_dS)z(Create a new instance of _XMLTestResult.NF)rr�	successes�callback�
elapsed_times�output_patched)r�stream�descriptions�	verbosityr+r
r
rrgs
z_XMLTestResult.__init__cs&|�������fdd�}|�_dS)zxAppend a _TestInfo to the given target list and sets a callback
        method to be called by stopTest method.
        csH�jsd�_�_�jr2�j�d����f�n�jrD�j���dS)zqThis callback prints the test method outcome to the stream,
            as well as the elapsed time.
            rz
(%.3fs) %sN)	r+rr�showAllr-�writelnrZdots�writer
)r�	short_str�	test_info�verbose_strr
rr*vsz2_XMLTestResult._prepare_callback.<locals>.callbackN)�appendr*)rr4Ztarget_listr5r3r*r
)rr3r4r5r�_prepare_callbackps
z _XMLTestResult._prepare_callbackcCsB|jstjtj|_|_d|_t�t�f\t_t_\|_|_dS)zwReplace the stdout and stderr streams with string-based streams
        in order to capture the tests' output.
        TN)r,�sysrr�
old_stdout�
old_stderrr)rr
r
r�_patch_standard_output�sz%_XMLTestResult._patch_standard_outputcCs|j|jt_t_d|_dS)z&Restore the stdout and stderr streams.FN)r9r:r8rrr,)rr
r
r�_restore_standard_output�sz'_XMLTestResult._restore_standard_outputcCsJ|��t��|_t�||�|jrF|j�d|�|��|j�d�dS)z'Called before execute each test method.z  z ... N)	r;�timerr�	startTestr0r-r2r)r�testr
r
rr>�s
z_XMLTestResult.startTestcCs@|��t�||�t��|_|jr<t|j�r<|��d|_dS)z&Called after execute each test method.N)r<r�stopTestr=rr*�callable)rr?r
r
rr@�s
z_XMLTestResult.stopTestcCs|�t||�|jdd�dS)z)Called when a test executes successfully.�OK�.N)r7rr))rr?r
r
r�
addSuccess�sz_XMLTestResult.addSuccesscCs"|�t||tj|�|jdd�dS)z Called when a test method fails.ZFAIL�FN)r7rr%�failures)rr?rr
r
r�
addFailure�sz_XMLTestResult.addFailurecCs"|�t||tj|�|jdd�dS)z*Called when a test method raises an error.r&�EN)r7rr&�errors)rr?rr
r
r�addError�sz_XMLTestResult.addErrorcCsx�|D]�}t|t�r|\}}y|��}Wntk
r@d}YnXy|��}Wn>tk
r�y|��}Wntk
r�t|�}YnXYnXy|��}Wntk
r�t|�}YnX|j�	|j
�|j�	d|||f�|j�	|j�|j�	d|�qWdS)z=Write some information about the FAIL or ERROR to the stream.rz%s [%.3fs]: %sz%sN)�
isinstance�tupler�AttributeErrorr r�strr!r-r1Z
separator1�
separator2)rZflavourrIr4�exc_info�t�descrZerr_infor
r
r�printErrorList�s,


z_XMLTestResult.printErrorListcCs�i}x�|j|j|jfD]t}xn|D]f}t|t�s>td|f�q t|j�}|jd}|dkr^d}||j	}||krxg||<||�
|�q WqW|S)z�This method organizes test results by TestCase module. This
        information is used during the report generation, where a XML report
        will be generated for each TestCase.
        zUnexpected test result type: %rrCz	__main__.r)r)rFrIrKr�print�typerrr
r6)rZtests_by_testcase�testsr4�testcase�moduleZ
testcase_namer
r
r�_get_info_by_testcase�s




z$_XMLTestResult._get_info_by_testcasecCs�|�d�}|�|�|�dt|��|�dtt|���|�ddtdd�|D���tdd�|D��}|�d	t|��td
d�|D��}|�dt|��|S)z2Appends the testsuite section to the XML document.�	testsuite�namerVr=z%.3fcSsg|]}|���qSr
)r)�.0�er
r
r�
<listcomp>�sz4_XMLTestResult._report_testsuite.<locals>.<listcomp>cSsg|]}|jtjkrd�qS)r()rrr%)r\r]r
r
rr^�srFcSsg|]}|jtjkrd�qS)r()rrr&)r\r]r
r
rr^�srI)�
createElement�appendChild�setAttributerN�len�sum)�
suite_namerV�xml_documentrZrFrIr
r
r�_report_testsuite�s

z _XMLTestResult._report_testsuitec	Cs�|�d�}|�|�|�dt|��|�d|j��pFt|jdt|j���|�dd|���|jt	j
kr�d|jd}|�|�}|�|�|�d	t|jd
j��|�dt|jd��|�
�}|�|�}|�|�dS)
z/Appends a testcase section to the XML document.rW�	classnamer[Z_testMethodNamer=z%.3f)�failure�errorr(rUr�messageN)r_r`rarNrZshortDescription�getattrrrrr$rr
r!r)	rdr�
xml_testsuitererWZ	elem_namerh�
error_infoZfailureTextr
r
r�_report_testcases 




z_XMLTestResult._report_testcasec	CsT|�d�}|�|�|�|�}|�|�|�d�}|�|�|�|�}|�|�dS)zCAppends the system-out and system-err sections to the XML document.z
system-outz
system-errN)r_r`r)	�test_runnerrlrerrZ	systemoutZsystemout_textZ	systemerrZsystemerr_textr
r
r�_report_outputs






z_XMLTestResult._report_outputc
Cs:|��}t|j�tkr0tj�|j�s0t�|j��x|��D]�\}}t	�}t
�|||�}gg}}xT|D]L}	t
�||	||�|	j
r�|�d|	��|	j
g�|	jrh|�d|	��|	jg�qhWt
�|||d�|�d�|��|jdd�}
t|j�tk�r&td|jtj|fd�}z|�|
�Wd|��Xq<|j�|
�q<WdS)z:Generates the XML reports to a given XMLTestRunner object.z*****************�
�	)�indentz%s%sTEST-%s.xml�wN)rYrU�outputrN�os�path�exists�makedirs�itemsrr'rfrnr�extendr rrp�joinZtoprettyxml�open�sepr2�close)rroZall_resultsZsuiterV�docrZrrr?Zxml_contentZreport_filer
r
r�generate_reports+s0


z_XMLTestResult.generate_reportsN)r
rrr"r8rrr7r;r<r>r@rDrGrJrSrYrf�staticmethodrnrpr�r
r
r
rr'bs(


r'c@s*eZdZdZddd�Zdd	�Zd
d�ZdS)
�
XMLTestRunnerzJA test runner class that outputs the results in JUnit like XML files.
    rCNTFcCs6|dkrtj}d|}t�||||�||_||_dS)z'Create a new instance of XMLTestRunner.N)r(�)r8rrrrur+)rrur-r.�verboser+r/r
r
rrRszXMLTestRunner.__init__cCst|j|j|j|j�S)zoCreate the TestResult object which will be used to store
        information about the executed tests.
        )r'r-r.r/r+)rr
r
r�_make_result[s
zXMLTestRunner._make_resultc	Cs:|��}|j��|j�d�|j�|j�t��}||�t��}||}|j��|j�d�|�|�|��|j�|j�|j}|j�d||dkr�dp�d|f�|j��|���s*|j�	d�t
|j�t
|j�}}|r�|j�	d|�|�r|�r|j�	d	�|j�	d
|�|j�d�n|j�d�|S)
z&Run the given test case or test suite.zRunning tests...zGenerating XML reports...zRan %d test%s in %.3fsr(�srzFAILED (zfailures=%dz, z	errors=%d�)rB)
r�r-r1rOr=r�ZprintErrorsZtestsRunZ
wasSuccessfulr2rbrFrI)	rr?�resultrrZ
time_taken�run�failedZerroredr
r
rr�bs:




zXMLTestRunner.run)rCNTFT)r
rrr"rr�r�r
r
r
rr�Os
	r�)r"�
__future__rrvr8r=ZunittestrrrZxml.dom.minidom�xmlr�ImportError�io�domZminidomZDocumentr�objectrr'r�r
r
r
r�<module>'s%n