B ž@`}-ã@sèdZddlZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z ddl mZddlmZddlmZmZe d ¡Ze d ¡Zd d „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:: Traceback (most recent call last): ... TypeError: oops, wrong type .. _Jenkins: http://jenkins-ci.org/ éN)ÚStringIO)Útime)Úsaxutils)ÚPlugin)ÚSkipTest)Ú force_unicodeÚformat_exceptionz[\000-\010\013\014\016-\037]z^(.*?)(\(.*\))$cCs t d|¡S)z)Replaces invalid XML characters with '?'.ú?)ÚCONTROL_CHARACTERSÚsub)Úvalue©r ú6/tmp/pip-unpacked-wheel-r6rbwcnk/nose/plugins/xunit.pyÚxml_safe>srcCst|ƒ dd¡S)z)Escape a string for an XML CDATA section.z]]>z]]>]]>>> 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'c Csz|d}|dkr|d}nNy t|ƒ}Wn@tk rfy t|ƒ}Wntk r`|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@s4eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd S) ÚTeecGs||_||_dS)N)Ú _encodingÚ_streams)ÚselfÚencodingr+r r rÚ__init__zsz Tee.__init__cCs*t||jƒ}x|jD]}| |¡qWdS)N)rr1r2Úwrite)r3ÚdataÚsr r rr6~s  z Tee.writecCsx|D]}| |¡qWdS)N)r6)r3ÚlinesÚliner r rÚ writelinesƒs zTee.writelinescCsx|jD] }| ¡qWdS)N)r2Úflush)r3r8r r rr<‡s z Tee.flushcCsdS)NFr )r3r r rÚisatty‹sz Tee.isattyN)r Ú __module__Ú __qualname__r5r6r;r<r=r r r rr0ys r0cs¾eZdZdZdZdZdZdZ‡fdd„Zdd „Z d d „Z d d „Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd*d$d%„Zd+d&d'„Zd,d(d)„Z‡ZS)-ÚXunitzCThis plugin provides test results in the standard XUnit XML format.ZxunitiÜzUTF-8Ncs$tt|ƒ ¡g|_d|_d|_dS)N)Úsuperr@r5Ú_capture_stackÚ_currentStdoutÚ_currentStderr)r3)r!r rr5–szXunit.__init__cCs t|dƒrtƒ|j}nd}|S)NÚ_timerg)ÚhasattrrrE)r3Útakenr r rÚ _timeTakenœs zXunit._timeTakencCst|ƒ}t |¡S)z.Escape an XML attribute. Value can be unicode.)rrÚ quoteattr)r3Úattrr r rÚ _quoteattr¦szXunit._quoteattrc CsNt |||¡|jdddd| dd¡dd|jd dd d | d d ¡dddS)z%Sets additional command line options.z --xunit-fileÚstoreÚ xunit_fileÚFILEZNOSE_XUNIT_FILEz nosetests.xmlzrPath to xml file to store the xunit report in. Default is nosetests.xml in the working directory [NOSE_XUNIT_FILE])ÚactionÚdestÚmetavarÚdefaultÚhelpz--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)r3ÚparserÚenvr r rrU«s  z Xunit.optionscCsLt |||¡||_|jrHdddddœ|_g|_tj |j ¡|_ |j |_ dS)zConfigures the xunit plugin.r)ÚerrorsÚfailuresÚpassesÚskippedN) rÚ configureÚconfigZenabledÚstatsÚ errorlistÚosÚpathÚrealpathrMÚerror_report_file_namerT)r3rUr_r r rr^½s zXunit.configurecsÒt ˆjdˆjd¡ˆ_ˆjˆjd<ˆjˆjd<ˆjdˆjdˆjdˆjdˆjd <ˆj d ˆj¡ˆj d  ‡fd d „ˆj Dƒ¡¡ˆj d¡ˆj  ¡ˆj j dkrÎ|  d¡|  dˆjj¡dS)zmWrites an Xunit-formatted XML file The file includes a report of test errors and failures. Úwrr4Ztestsuite_namerZr[r\r]Útotalz£Úcsg|]}t|ˆjƒ‘qSr )rr4)Ú.0Úe)r3r rú Üsz Xunit.report..z rzF----------------------------------------------------------------------zXML: %sN)ÚcodecsÚopenrer4Úerror_report_filer`rTr6ÚjoinraÚcloser_Ú verbosityÚwritelnr)r3Ústreamr )r3rÚreportËs    .     z Xunit.reportcCsP|j tjtjf¡tƒ|_tƒ|_t|j |jtjƒt_t|j |jtjƒt_dS)N) rBÚappendÚsysÚstdoutÚstderrrrCrDr0r4)r3r r rÚ _startCaptureäs zXunit._startCapturecCs | ¡dS)N)ry)r3Úcontextr r rÚ startContextëszXunit.startContextcCs | ¡dS)N)Ú _endCapture)r3rzr r rÚ stopContextîszXunit.stopContextcCstƒ|_| ¡dS)z+Initializes a timer before starting a test.N)rrEry)r3Útestr r rÚ beforeTestñszXunit.beforeTestcCs|jr|j ¡\t_t_dS)N)rBÚpoprvrwrx)r3r r rr|öszXunit._endCapturecCs| ¡d|_d|_dS)N)r|rCrD)r3r~r r rÚ afterTestúszXunit.afterTestcCsx|jr| ¡qWdS)N)rBr|)r3r~r r rÚfinalizeÿszXunit.finalizecCs$|jr |j ¡}|r dt|ƒSdS)Nz'rh)rCÚgetvaluer)r3r r r rÚ_getCapturedStdouts  zXunit._getCapturedStdoutcCs$|jr |j ¡}|r dt|ƒSdS)Nz'rh)rDrƒr)r3r r r rÚ_getCapturedStderr s  zXunit._getCapturedStderrc CsÀ| ¡}t|dtƒr.d}|jdd7<nd}|jdd7<t||jƒ}| ¡}|j d|  t |ƒd¡|  t |ƒd¡|||  t |dƒ¡|  t |ƒ¡t |ƒ| ¡| ¡dœ ¡d S) z*Add error output to Xunit report. rr]rÚerrorrZz®<%(type)s type=%(errtype)s message=%(message)s>%(systemout)s%(systemerr)séÿÿÿÿ) ÚclsrrGÚtypeÚerrtypeÚmessageÚtbÚ systemoutÚ systemerrN)rHÚ issubclassrr`rr4ÚidrarurKrr'r/rr„r…)r3r~ÚerrÚcaptrGr‰rŒrr r rÚaddErrors&  zXunit.addErrorc Cs”| ¡}t||jƒ}|jdd7<| ¡}|j d| t|ƒd¡| t|ƒd¡|| t |dƒ¡| t |ƒ¡t |ƒ|  ¡|  ¡dœ¡dS)z,Add failure output to Xunit report. r[rz¬%(systemout)s%(systemerr)srr‡)rˆrrGrŠr‹rŒrrŽN)rHrr4r`rrarurKrr'r/rr„r…)r3r~r‘r’Ztb_inforGrŒrr r rÚ addFailure1s  zXunit.addFailurec Csf| ¡}|jdd7<| ¡}|j d| t|ƒd¡| t|ƒd¡|| ¡| ¡dœ¡dS)z,Add success output to Xunit report. r\rzb%(systemout)s%(systemerr)srr‡)rˆrrGrrŽN) rHr`rrarurKrr„r…)r3r~r’rGrr r rÚ addSuccessGszXunit.addSuccess)N)NN)N)r r>r?Ú__doc__rZscorer4rnr5rHrKrUr^rtryr{r}rr|rr‚r„r…r“r”r•Ú __classcell__r r )r!rr@s.    r@)r–rlÚdoctestrbrvÚ tracebackÚrerÚiorrZxml.saxrZnose.plugins.baserZnose.excrZnose.pyversionrrÚcompiler rrrrr'r/Úobjectr0r@r r r rÚ)s,