Plan 9 from Bell Labs’s /usr/web/sources/contrib/jas/root/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�9�c@s>dZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
m
Z
ddlmZddl
mZddlmZddlmZejd	�Zejd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zdefd��YZdefd��YZdS(s�This 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.

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(tUNICODE_STRINGSs[\000-\010\013\014\016-\037]s^(.*?)(\(.*\))$cCstjd|�S(s)Replaces invalid XML characters with '?'.t?(tCONTROL_CHARACTERStsub(tvalue((s6/sys/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[(R
treplace(tcdata((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pytescape_cdata?scCsatj|�}|rM|j�\}}|jdd�\}}|||gS|jdd�SdS(Nt.i(tTEST_IDtmatchtgroupstrsplit(tidvaltmtnametfargstheadttail((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pytid_splitCs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/sys/lib/python2.7/site-packages/nose/plugins/xunit.pytnice_classnameLs		cCs�|d}|dkr#|d}nUyt|�}WnBtk
rwyt|�}Wqxtk
rs|jd}qxXnXt|�S(sReturn the exception's message.iiN(tNonetstrtUnicodeEncodeErrortunicodetUnicodeErrortargsR
(texc_infotexctresult((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pytexc_messagecs



cCsX|\}}}t|t�r>djtj|��}||Sdjtj|��SdS(Nt(t
isinstancet
basestringtjoint	tracebackt	format_tbtformat_exception(R+tectevttbttb_data((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyR5us
tTeecBs#eZd�Zd�Zd�ZRS(cGs
||_dS(N(t_streams(tselfR*((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyt__init__�scGs%x|jD]}|j|�q
WdS(N(R;twrite(R<R*ts((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyR>�scCs"x|jD]}|j�q
WdS(N(R;tflush(R<R?((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyR@�s(Rt
__module__R=R>R@(((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyR:�s		tXunitcBs�eZdZdZdZdZdZd�Zd�Z	d�Z
d�Zd�Zd	�Z
d
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zdd�Zddd�Zdd�Zd�ZRS(sCThis plugin provides test results in the standard XUnit XML format.txuniti�sUTF-8cCs2tt|�j�g|_d|_d|_dS(N(tsuperRBR=t_capture_stackR%t_currentStdoutt_currentStderr(R<((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyR=�s		cCs,t|d�r"t�|j}nd}|S(Nt_timerg(thasattrRRH(R<ttaken((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyt
_timeTaken�scCsDt|�}t|t�r7tr7|j|j�}ntj|�S(s.Escape an XML attribute. Value can be unicode.(R
R0R(RtencodetencodingRt	quoteattr(R<tattr((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyt
_quoteattr�scCsNtj|||�|jdddddddd|jd	d
�dd�d
S(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]N(Rtoptionst
add_optiontget(R<tparsertenv((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyRZ�scCs{tj|||�||_|jrwidd6dd6dd6dd6|_g|_tj|jd|j	d�|_
ndS(	sConfigures the xunit plugin.iterrorstfailurestpassestskippedtwRN(Rt	configuretconfigtenabledtstatst	errorlisttcodecstopenRTRMterror_report_file(R<RZRe((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyRd�s		

	cCs�|j|jd<|jd|jd|jd|jd|jd<|jjd|j�|jjdjg|jD]}|j|�^qu��|jjd	�|jj�|jj	d
kr�j
dd�|j
d
|jj�ndS(smWrites an Xunit-formatted XML file

        The file includes a report of test errors and failures.

        RMR_R`RaRbttotalu�<?xml version="1.0" encoding="%(encoding)s"?><testsuite name="nosetests" tests="%(total)d" errors="%(errors)d" failures="%(failures)d" skip="%(skipped)d">uu</testsuite>it-iFsXML: %sN(RMRgRkR>R2Rht
_forceUnicodetcloseRet	verbositytwritelnR(R<tstreamte((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pytreport�s5	&
cCsh|jjtjtjf�t�|_t�|_t|jtj�t_t|jtj�t_dS(N(	REtappendtsyststdouttstderrRRFRGR:(R<((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyt
_startCapture�s
cCs|j�dS(N(Ry(R<tcontext((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pytstartContext�scCst�|_|j�dS(s+Initializes a timer before starting a test.N(RRHRy(R<ttest((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyt
beforeTest�scCs+|jr'|jj�\t_t_ndS(N(REtpopRvRwRx(R<((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyt_endCapture�s	cCs |j�d|_d|_dS(N(RR%RFRG(R<R|((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyt	afterTest�s
	cCsx|jr|j�qWdS(N(RER(R<R|((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pytfinalize�scCs3|jr/|jj�}|r/dt|�SndS(Ns'<system-out><![CDATA[%s]]></system-out>R/(RFtgetvalueR
(R<R	((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyt_getCapturedStdout�s	cCs3|jr/|jj�}|r/dt|�SndS(Ns'<system-err><![CDATA[%s]]></system-err>R/(RGR�R
(R<R	((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyt_getCapturedStderr�s	cCs|j�}t|dt�r;d}|jdcd7<nd}|jdcd7<t|�}|j�}|jjdi	|jt	|�d�d6|jt	|�d�d	6|d
6|d6|jt
|d��d6|jt|��d
6t|�d6|j
�d6|j�d6�dS(s*Add error output to Xunit report.
        iRbiterrorR_s�<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�RRJttypeterrtypetmessageR8t	systemoutt	systemerrN(RKt
issubclassRRgR5tidRhRuRPRR$R.R
R�R�(R<R|terrtcaptRJR�R8R�((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pytaddErrors&	

cCs�|j�}t|�}|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`is�<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�RRJR�R�R8R�R�N(
RKR5RgR�RhRuRPRR$R.R
R�R�(R<R|R�R�ttb_infoRJR8R�((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyt
addFailure#s	

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�RRJR�R�N(	RKRgR�RhRuRPRR�R�(R<R|R�RJR�((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyt
addSuccess8s	
cCs4ts0t|t�r0|j|jd�}q0n|S(NR(RR0R&tdecodeRM(R<R?((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyRnHsN(RRAt__doc__RtscoreRMR%RkR=RKRPRZRdRtRyR{R}RR�R�R�R�R�R�R�Rn(((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyRB�s.		
												(R�RitdoctesttosRvR3treRt	cStringIORRtxml.saxRtnose.plugins.baseRtnose.excRtnose.pyversionRtcompileRRR
R
RR$R.R5tobjectR:RB(((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyt<module>&s.							


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].