Current File : //usr/lib/python2.7/site-packages/nose/plugins/xunit.pyc
�
d�Uc@s;dZddlZddlZddlZddlZddlZddlZddlZddlmZddl	m	Z	ddl
mZddlm
Z
ddlmZddlmZmZejd	�Zejd
�Zd�Zd�Zd
�Zd�Zd�Zdefd��YZde
fd��YZdS(sUThis 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/

i����N(tStringIO(ttime(tsaxutils(tPlugin(tSkipTest(t
force_unicodetformat_exceptions[\000-\010\013\014\016-\037]s^(.*?)(\(.*\))$cCstjd|�S(s)Replaces invalid XML characters with '?'.t?(tCONTROL_CHARACTERStsub(tvalue((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pytxml_safe>scCst|�jdd�S(s)Escape a string for an XML CDATA section.s]]>s]]>]]&gt;<![CDATA[(Rtreplace(tcdata((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pytescape_cdataBscCsatj|�}|rM|j�\}}|jdd�\}}|||gS|jdd�SdS(Nt.i(tTEST_IDtmatchtgroupstrsplit(tidvaltmtnametfargstheadttail((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pytid_splitFscCs}tj|�r|j}n|jj}tj|�}|ru|j}|jd�rg|td�}nd||fS|SdS(s�Returns a nice name for class object or class instance.

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

    sorg.python.core.s%s.%sN(tinspecttisclasst__name__t	__class__t	getmodulet
startswithtlen(tobjtcls_nametmodR((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pytnice_classnameOs		cCs�|d}|dkr#|d}nUyt|�}WnBtk
rwyt|�}Wqxtk
rs|jd}qxXnXt|d�}t|�S(sReturn the exception's message.iisUTF-8N(tNonetstrtUnicodeEncodeErrortunicodetUnicodeErrortargsRR(texc_infotexctresult((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pytexc_messagefs



tTeecBs5eZd�Zd�Zd�Zd�Zd�ZRS(cGs||_||_dS(N(t	_encodingt_streams(tselftencodingR+((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pyt__init__zs	cCs7t||j�}x|jD]}|j|�qWdS(N(RR1R2twrite(R3tdatats((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pyR6~scCs"x|D]}|j|�qWdS(N(R6(R3tlinestline((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pyt
writelines�s
cCs"x|jD]}|j�q
WdS(N(R2tflush(R3R8((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pyR<�scCstS(N(tFalse(R3((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pytisatty�s(Rt
__module__R5R6R;R<R>(((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pyR0ys
				tXunitcBs�eZdZdZdZdZdZd�Zd�Z	d�Z
d�Zd�Zd	�Z
d
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zdd�Zddd�Zdd�ZRS(sCThis plugin provides test results in the standard XUnit XML format.txuniti�sUTF-8cCs2tt|�j�g|_d|_d|_dS(N(tsuperR@R5t_capture_stackR&t_currentStdoutt_currentStderr(R3((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pyR5�s		cCs,t|d�r"t�|j}nd}|S(Nt_timerg(thasattrRRF(R3ttaken((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pyt
_timeTaken�scCst|�}tj|�S(s.Escape an XML attribute. Value can be unicode.(RRt	quoteattr(R3tattr((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pyt
_quoteattr�scCs�tj|||�|jdddddddd|jd	d
�dd�|jd
ddddddd|jdd�dd�dS(s%Sets additional command line options.s--xunit-filetactiontstoretdestt
xunit_filetmetavartFILEtdefaulttNOSE_XUNIT_FILEs
nosetests.xmlthelpsrPath to xml file to store the xunit report in. Default is nosetests.xml in the working directory [NOSE_XUNIT_FILE]s--xunit-testsuite-nametxunit_testsuite_nametPACKAGEtNOSE_XUNIT_TESTSUITE_NAMEt	nosetestssbName of the testsuite in the xunit xml, generated by plugin. Default test suite name is nosetests.N(Rtoptionst
add_optiontget(R3tparsertenv((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pyRZ�scCs~tj|||�||_|jrzidd6dd6dd6dd6|_g|_tjj|j	�|_
|j|_ndS(sConfigures the xunit plugin.iterrorstfailurestpassestskippedN(Rt	configuretconfigtenabledtstatst	errorlisttostpathtrealpathRPterror_report_file_nameRV(R3RZRd((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pyRc�s		

	cCs&tj|jd|jd�|_|j|jd<|j|jd<|jd|jd|jd|jd|jd	<|jjd
|j�|jjdjg|j	D]}t
||j�^q���|jjd�|jj�|jj
d
kr"|jdd�|jd|jj�ndS(smWrites an Xunit-formatted XML file

        The file includes a report of test errors and failures.

        twRR4ttestsuite_nameR_R`RaRbttotalu�<?xml version="1.0" encoding="%(encoding)s"?><testsuite name="%(testsuite_name)s" tests="%(total)d" errors="%(errors)d" failures="%(failures)d" skip="%(skipped)d">uu</testsuite>it-iFsXML: %sN(tcodecstopenRkR4terror_report_fileRfRVR6tjoinRgRtcloseRdt	verbositytwritelnR(R3tstreamte((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pytreport�s5	)
cCst|jjtjtjf�t�|_t�|_t|j	|jtj�t_t|j	|jtj�t_dS(N(
RCtappendtsyststdouttstderrRRDRER0R4(R3((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pyt
_startCapture�s
cCs|j�dS(N(R~(R3tcontext((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pytstartContext�scCs|j�dS(N(t_endCapture(R3R((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pytstopContext�scCst�|_|j�dS(s+Initializes a timer before starting a test.N(RRFR~(R3ttest((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pyt
beforeTest�scCs+|jr'|jj�\t_t_ndS(N(RCtpopR{R|R}(R3((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pyR��s	cCs |j�d|_d|_dS(N(R�R&RDRE(R3R�((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pyt	afterTest�s
	cCsx|jr|j�qWdS(N(RCR�(R3R�((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pytfinalize�scCs3|jr/|jj�}|r/dt|�SndS(Ns'<system-out><![CDATA[%s]]></system-out>t(RDtgetvalueR(R3R
((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pyt_getCapturedStdouts	cCs3|jr/|jj�}|r/dt|�SndS(Ns'<system-err><![CDATA[%s]]></system-err>R�(RER�R(R3R
((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pyt_getCapturedStderrs	cCs#|j�}t|dt�r;d}|jdcd7<nd}|jdcd7<t||j�}|j�}|jjdi	|j	t
|�d�d6|j	t
|�d�d	6|d
6|d6|j	t|d��d6|j	t|��d
6t
|�d6|j�d6|j�d6�dS(s*Add error output to Xunit report.
        iRbiterrorR_u�<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>tclsi����RRHttypeterrtypetmessagettbt	systemoutt	systemerrN(RIt
issubclassRRfRR4tidRgRzRLRR%R/RR�R�(R3R�terrtcaptRHR�R�R�((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pytaddErrors&	

cCs�|j�}t||j�}|jdcd7<|j�}|jjdi|jt|�d�d6|jt|�d�d6|d6|jt	|d��d	6|jt
|��d
6t|�d6|j�d6|j
�d
6�dS(s,Add failure output to Xunit report.
        R`iu�<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>iR�i����RRHR�R�R�R�R�N(RIRR4RfR�RgRzRLRR%R/RR�R�(R3R�R�R�ttb_infoRHR�R�((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pyt
addFailure1s	

cCs�|j�}|jdcd7<|j�}|jjdi|jt|�d�d6|jt|�d�d6|d6|j�d	6|j�d
6�dS(s,Add success output to Xunit report.
        Raisb<testcase classname=%(cls)s name=%(name)s time="%(taken).3f">%(systemout)s%(systemerr)s</testcase>iR�i����RRHR�R�N(	RIRfR�RgRzRLRR�R�(R3R�R�RHR�((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pyt
addSuccessGs	
N(RR?t__doc__RtscoreR4R&RrR5RIRLRZRcRyR~R�R�R�R�R�R�R�R�R�R�R�(((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pyR@�s.		
													(R�RptdoctestRhR{t	tracebacktreRRRtxml.saxRtnose.plugins.baseRtnose.excRtnose.pyversionRRtcompileRRRRRR%R/tobjectR0R@(((s6/usr/lib/python2.7/site-packages/nose/plugins/xunit.pyt<module>)s,