Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib/python3.5/site-packages/nose/plugins/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib/python3.5/site-packages/nose/plugins/__pycache__/xunit.cpython-35.pyc



�^�]}-�@sJdZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
m
Z
ddlmZddl
mZddlmZddlmZmZejd	�Zejd
�Zdd�Zd
d�Zdd�Zdd�Zdd�ZGdd�de�ZGdd�de�ZdS)aUThis plugin provides test results in the standard XUnit XML format.

It's designed for the `Jenkins`_ (previously Hudson) continuous build
system, but will probably work for anything else that understands an
XUnit-formatted XML representation of test results.

Add this shell command to your builder ::

    nosetests --with-xunit

And by default a file named nosetests.xml will be written to the
working directory.

In a Jenkins builder, tick the box named "Publish JUnit test result report"
under the Post-build Actions and enter this value for Test report XMLs::

    **/nosetests.xml

If you need to change the name or location of the file, you can set the
``--xunit-file`` option.

If you need to change the name of the test suite, you can set the
``--xunit-testsuite-name`` option.

Here is an abbreviated version of what an XML test report might look like::

    <?xml version="1.0" encoding="UTF-8"?>
    <testsuite name="nosetests" tests="1" errors="1" failures="0" skip="0">
        <testcase classname="path_to_test_suite.TestSomething"
                  name="test_it" time="0">
            <error type="exceptions.TypeError" message="oops, wrong type">
            Traceback (most recent call last):
            ...
            TypeError: oops, wrong type
            </error>
        </testcase>
    </testsuite>

.. _Jenkins: http://jenkins-ci.org/

�N)�StringIO)�time)�saxutils)�Plugin)�SkipTest)�
force_unicode�format_exceptionz[\000-\010\013\014\016-\037]z^(.*?)(\(.*\))$cCstjd|�S)z)Replaces invalid XML characters with '?'.�?)�CONTROL_CHARACTERS�sub)�value�r
�C/opt/alt/python35/lib/python3.5/site-packages/nose/plugins/xunit.py�xml_safe>srcCst|�jdd�S)z)Escape a string for an XML CDATA section.z]]>z]]>]]&gt;<![CDATA[)r�replace)Zcdatar
r
r�escape_cdataBsrcCsatj|�}|rM|j�\}}|jdd�\}}|||gS|jdd�SdS)N�.�)�TEST_ID�match�groups�rsplit)Zidval�m�nameZfargs�head�tailr
r
r�id_splitFsrcCs�tj|�r|j}n|jj}tj|�}|rx|j}|jd�rj|td�d�}d||fS|SdS)z�Returns a nice name for class object or class instance.

        >>> nice_classname(Exception()) # doctest: +ELLIPSIS
        '...Exception'
        >>> nice_classname(Exception) # doctest: +ELLIPSIS
        '...Exception'

    zorg.python.core.Nz%s.%s)�inspect�isclass�__name__�	__class__�	getmodule�
startswith�len)�objZcls_name�modrr
r
r�nice_classnameOs		r&cCs�|d}|dkr#|d}nWyt|�}WnDtk
ryyt|�}Wntk
rt|jd}YnXYnXt|d�}t|�S)zReturn the exception's message.rNrzUTF-8)�str�UnicodeEncodeError�UnicodeError�argsrr)�exc_info�exc�resultr
r
r�exc_messagefs



r.c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�TeecGs||_||_dS)N)�	_encoding�_streams)�self�encodingr*r
r
r�__init__zs	zTee.__init__cCs7t||j�}x|jD]}|j|�qWdS)N)rr0r1�write)r2�data�sr
r
rr5~sz	Tee.writecCs"x|D]}|j|�qWdS)N)r5)r2�lines�liner
r
r�
writelines�s
zTee.writelinescCs"x|jD]}|j�q
WdS)N)r1�flush)r2r7r
r
rr;�sz	Tee.flushcCsdS)NFr
)r2r
r
r�isatty�sz
Tee.isattyN)r�
__module__�__qualname__r4r5r:r;r<r
r
r
rr/ys
r/cseZdZdZdZdZdZdZ�fdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zdd$d%�Zddd&d'�Zdd(d)�Z�S)*�XunitzCThis plugin provides test results in the standard XUnit XML format.Zxuniti�zUTF-8Ncs2tt|�j�g|_d|_d|_dS)N)�superr?r4�_capture_stack�_currentStdout�_currentStderr)r2)r r
rr4�s		zXunit.__init__cCs,t|d�r"t�|j}nd}|S)N�_timerg)�hasattrrrD)r2�takenr
r
r�
_timeTaken�szXunit._timeTakencCst|�}tj|�S)z.Escape an XML attribute. Value can be unicode.)rrZ	quoteattr)r2�attrr
r
r�
_quoteattr�szXunit._quoteattrcCs�tj|||�|jdddddddd|jd	d
�dd�|jd
ddddddd|jdd�dd�dS)z%Sets additional command line options.z--xunit-file�action�store�dest�
xunit_file�metavarZFILE�defaultZNOSE_XUNIT_FILEz
nosetests.xml�helpzrPath to xml file to store the xunit report in. Default is nosetests.xml in the working directory [NOSE_XUNIT_FILE]z--xunit-testsuite-name�xunit_testsuite_nameZPACKAGEZNOSE_XUNIT_TESTSUITE_NAMEZ	nosetestszbName of the testsuite in the xunit xml, generated by plugin. Default test suite name is nosetests.N)r�options�
add_option�get)r2�parser�envr
r
rrR�sz
Xunit.optionscCswtj|||�||_|jrsddddddddi|_g|_tjj|j	�|_
|j|_dS)zConfigures the xunit plugin.�errorsr�failures�passes�skippedN)r�	configure�config�enabled�stats�	errorlist�os�path�realpathrM�error_report_file_namerQ)r2rRr\r
r
rr[�s			zXunit.configurecstj�jd�jd��_�j�jd<�j�jd<�jd�jd�jd�jd�jd	<�jjd
�j��jjdj�fdd
��j	D����jjd��jj
��jjdkr|j
dd�|j
d�jj�dS)zmWrites an Xunit-formatted XML file

        The file includes a report of test errors and failures.

        �wrr3Ztestsuite_namerWrXrYrZ�totalz�<?xml version="1.0" encoding="%(encoding)s"?><testsuite name="%(testsuite_name)s" tests="%(total)d" errors="%(errors)d" failures="%(failures)d" skip="%(skipped)d">�cs"g|]}t|�j��qSr
)rr3)�.0�e)r2r
r�
<listcomp>�s	z Xunit.report.<locals>.<listcomp>z</testsuite>r�-�FzXML: %sN)�codecs�openrcr3�error_report_filer^rQr5�joinr_�closer\�	verbosity�writelnr)r2�streamr
)r2r�report�s5	
zXunit.reportcCst|jjtjtjf�t�|_t�|_t|j	|jtj�t_t|j	|jtj�t_dS)N)
rA�append�sys�stdout�stderrrrBrCr/r3)r2r
r
r�
_startCapture�s
zXunit._startCapturecCs|j�dS)N)ry)r2�contextr
r
r�startContext�szXunit.startContextcCs|j�dS)N)�_endCapture)r2rzr
r
r�stopContext�szXunit.stopContextcCst�|_|j�dS)z+Initializes a timer before starting a test.N)rrDry)r2�testr
r
r�
beforeTest�szXunit.beforeTestcCs(|jr$|jj�\t_t_dS)N)rA�poprvrwrx)r2r
r
rr|�s	zXunit._endCapturecCs |j�d|_d|_dS)N)r|rBrC)r2r~r
r
r�	afterTest�s
	zXunit.afterTestcCsx|jr|j�qWdS)N)rAr|)r2r~r
r
r�finalize�szXunit.finalizecCs0|jr,|jj�}|r,dt|�SdS)Nz'<system-out><![CDATA[%s]]></system-out>rf)rB�getvaluer)r2rr
r
r�_getCapturedStdouts	zXunit._getCapturedStdoutcCs0|jr,|jj�}|r,dt|�SdS)Nz'<system-err><![CDATA[%s]]></system-err>rf)rCr�r)r2rr
r
r�_getCapturedStderrs	zXunit._getCapturedStderrcCs|j�}t|dt�r9d}|jdd7<nd}|jdd7<t||j�}|j�}|jjdd|j	t
|�d�d|j	t
|�d�d	|d
|d|j	t|d��d|j	t|��d
t
|�d|j�d|j�i	�dS)z*Add error output to Xunit report.
        rrZr�errorrWz�<testcase classname=%(cls)s name=%(name)s time="%(taken).3f"><%(type)s type=%(errtype)s message=%(message)s><![CDATA[%(tb)s]]></%(type)s>%(systemout)s%(systemerr)s</testcase>�clsrrF�type�errtype�message�tb�	systemout�	systemerrN���)rG�
issubclassrr^rr3�idr_rurIrr&r.rr�r�)r2r~�err�captrFr�r�r�r
r
r�addErrors&	zXunit.addErrorcCs�|j�}t||j�}|jdd7<|j�}|jjdd|jt|�d�d|jt|�d�d|d|jt	|d��d	|jt
|��d
t|�d|j�d|j
�i�d
S)z,Add failure output to Xunit report.
        rXrz�<testcase classname=%(cls)s name=%(name)s time="%(taken).3f"><failure type=%(errtype)s message=%(message)s><![CDATA[%(tb)s]]></failure>%(systemout)s%(systemerr)s</testcase>r�rrrFr�r�r�r�r�Nr�)rGrr3r^r�r_rurIrr&r.rr�r�)r2r~r�r�Ztb_inforFr�r�r
r
r�
addFailure1s	zXunit.addFailurecCs�|j�}|jdd7<|j�}|jjdd|jt|�d�d|jt|�d�d|d|j�d	|j�i�d
S)z,Add success output to Xunit report.
        rYrzb<testcase classname=%(cls)s name=%(name)s time="%(taken).3f">%(systemout)s%(systemerr)s</testcase>r�rrrFr�r�Nr�)	rGr^r�r_rurIrr�r�)r2r~r�rFr�r
r
r�
addSuccessGs	zXunit.addSuccess)rr=r>�__doc__r�scorer3rnr4rGrIrRr[rtryr{r}rr|r�r�r�r�r�r�r�r
r
)r rr?�s.
r?)r�rl�doctestr`rv�	traceback�rer�iorrZxml.saxrZnose.plugins.baserZnose.excrZnose.pyversionrr�compiler
rrrrr&r.�objectr/r?r
r
r
r�<module>)s,