J9Qc@s>dZddlZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z ddl mZddlmZddlmZejd Zejd Zd Zd Zd ZdZdZdZdefdYZdefdYZdS(sThis 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:: Traceback (most recent call last): ... TypeError: oops, wrong type .. _Jenkins: http://jenkins-ci.org/ iN(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|jddS(s)Escape a string for an XML CDATA section.s]]>s]]>]]>>> 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.pyt exc_messagecs     cCsX|\}}}t|tr>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#eZdZdZdZRS(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]}|jq 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  tXunitcBseZdZdZdZdZdZdZdZ dZ dZ dZ d Z d Zd Zd Zd ZdZdZdZdZddZdddZddZdZRS(sCThis plugin provides test results in the standard XUnit XML format.txunitisUTF-8cCs2tt|jg|_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|dr"t|j}nd}|S(Nt_timerg(thasattrRRH(R<ttaken((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyt _timeTakenscCsDt|}t|tr7t 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 _quoteattrs c CsNtj||||jdddddddd|jd d d d 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.pyRZs   cCs{tj|||||_|jrwidd6dd6dd6dd6|_g|_tj|jd|j d|_ ndS( sConfigures the xunit plugin.iterrorstfailurestpassestskippedtwR N( Rt configuretconfigtenabledtstatst errorlisttcodecstopenRTRMterror_report_file(R<RZRe((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyRds     cCs|j|jd<|jd|jd|jd|jd|jd<|jjd|j|jjdjg|jD]}|j|^qu|jjd |jj|jj d kr|j d d |j d |jj ndS(smWrites an Xunit-formatted XML file The file includes a report of test errors and failures. RMR_R`RaRbttotaluuu it-iFsXML: %sN( RMRgRkR>R2Rht _forceUnicodetcloseRet verbositytwritelnR(R<tstreamte((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pytreports5  & cCsh|jjtjtjft|_t|_t|jtjt_t|jtjt_dS(N( REtappendtsyststdouttstderrRRFRGR:(R<((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyt _startCaptures   cCs|jdS(N(Ry(R<tcontext((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyt startContextscCst|_|jdS(s+Initializes a timer before starting a test.N(RRHRy(R<ttest((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyt beforeTests cCs+|jr'|jj\t_t_ndS(N(REtpopRvRwRx(R<((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyt _endCaptures cCs |jd|_d|_dS(N(RR%RFRG(R<R|((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyt afterTests  cCsx|jr|jqWdS(N(RER(R<R|((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pytfinalizes cCs3|jr/|jj}|r/dt|SndS(Ns'R/(RFtgetvalueR (R<R ((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyt_getCapturedStdouts   cCs3|jr/|jj}|r/dt|SndS(Ns'R/(RGRR (R<R ((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyt_getCapturedStderrs   cCs|j}t|dtr;d}|jdcd7<%(type)s type=%(errtype)s message=%(message)s>%(systemout)s%(systemerr)stclsiRRJttypeterrtypetmessageR8t systemoutt systemerrN(RKt issubclassRRgR5tidRhRuRPRR$R.R RR(R<R|terrtcaptRJRR8R((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pytaddErrors&      cCs|j}t|}|jdcd7<|j}|jjdi|jt|dd6|jt|dd6|d6|jt|dd 6|jt |d 6t |d 6|j d 6|j d 6dS(s,Add failure output to Xunit report. R`is%(systemout)s%(systemerr)siRiRRJRRR8RRN( RKR5RgRRhRuRPRR$R.R RR(R<R|RRttb_infoRJR8R((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyt addFailure#s      cCs|j}|jdcd7<|j}|jjdi|jt|dd6|jt|dd6|d6|jd 6|jd 6d S( s,Add success output to Xunit report. Raisb%(systemout)s%(systemerr)siRiRRJRRN( RKRgRRhRuRPRRR(R<R|RRJR((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyt addSuccess8s    cCs4ts0t|tr0|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}RRRRRRRRRn(((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyRBs.              (RRitdoctesttosRvR3treRt cStringIORRtxml.saxRtnose.plugins.baseRtnose.excRtnose.pyversionRtcompileRRR R RR$R.R5tobjectR:RB(((s6/sys/lib/python2.7/site-packages/nose/plugins/xunit.pyt&s.