U e}-@sdZddlZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z ddl mZddlmZddlmZmZed Zed Zd d Zd dZddZddZddZGdddeZGdddeZdS)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_unicodeformat_exceptionz[\000-\010\013\014\016-\037]z^(.*?)(\(.*\))$cCs td|S)z)Replaces invalid XML characters with '?'.?)CONTROL_CHARACTERSsub)valuer @/opt/hc_python/lib/python3.8/site-packages/nose/plugins/xunit.pyxml_safe>srcCst|ddS)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)inspectisclass__name__ __class__ getmodule startswithlen)objcls_namemodrr r rnice_classnameOs    r(c Csz|d}|dkr|d}nNz t|}Wn@tk rfz t|}Wntk r`|jd}YnXYnXt|d}t|S)zReturn the exception's message.rNrUTF-8)strUnicodeEncodeError UnicodeErrorargsrr)exc_infoexcresultr r r exc_messagefs    r1c@s4eZdZddZddZddZddZd d Zd S) TeecGs||_||_dSN) _encoding_streams)selfencodingr-r r r__init__zsz Tee.__init__cCs&t||j}|jD]}||qdSr3)rr4r5write)r6datasr r rr9~s  z Tee.writecCs|D]}||qdSr3)r9)r6linesliner r r writelinesszTee.writelinescCs|jD] }|qdSr3)r5flush)r6r;r r rr?s z Tee.flushcCsdS)NFr r6r r risattysz Tee.isattyN)r __module__ __qualname__r8r9r>r?rAr r r rr2ys r2cseZdZdZdZdZdZdZfddZdd Z d d Z d d Z ddZ ddZ ddZddZddZddZddZddZddZd d!Zd"d#Zd*d$d%Zd+d&d'Zd,d(d)ZZS)-XunitzCThis plugin provides test results in the standard XUnit XML format.Zxunitir)Ncs$tt|g|_d|_d|_dSr3)superrDr8_capture_stack_currentStdout_currentStderrr@r!r rr8szXunit.__init__cCs t|drt|j}nd}|S)N_timerg)hasattrrrJ)r6takenr r r _timeTakens zXunit._timeTakencCst|}t|S)z.Escape an XML attribute. Value can be unicode.)rrZ quoteattr)r6attrr r r _quoteattrszXunit._quoteattrc CsNt||||jdddd|dddd|jd dd d |d d dddS)z%Sets additional command line options.z --xunit-filestore xunit_fileFILEZNOSE_XUNIT_FILEz nosetests.xmlzrPath to xml file to store the xunit report in. Default is nosetests.xml in the working directory [NOSE_XUNIT_FILE])actiondestmetavardefaulthelpz--xunit-testsuite-namexunit_testsuite_nameZPACKAGEZNOSE_XUNIT_TESTSUITE_NAMEZ nosetestszbName of the testsuite in the xunit xml, generated by plugin. Default test suite name is nosetests.N)roptions add_optionget)r6parserenvr r rrYs"  z Xunit.optionscCsLt|||||_|jrHddddd|_g|_tj|j |_ |j |_ dS)zConfigures the xunit plugin.r)errorsfailurespassesskippedN) r configureconfigenabledstats errorlistospathrealpathrQerror_report_file_namerX)r6rYrcr r rrbszXunit.configurecstjdjd_jjd<jjd<jdjdjdjdjd <jd jjd fd d j Djdj j j dkr| d| djjdS)zmWrites an Xunit-formatted XML file The file includes a report of test errors and failures. wrr7Ztestsuite_namer^r_r`ratotalzcsg|]}t|jqSr )rr7).0er@r r sz Xunit.report..z rzF----------------------------------------------------------------------zXML: %sN)codecsopenrjr7error_report_filererXr9joinrfcloserc verbositywritelnr)r6streamr r@rreports0         z Xunit.reportcCsP|jtjtjft|_t|_t|j |jtjt_t|j |jtjt_dSr3) rFappendsysstdoutstderrrrGrHr2r7r@r r r _startCaptures zXunit._startCapturecCs |dSr3)r~r6contextr r r startContextszXunit.startContextcCs |dSr3) _endCapturerr r r stopContextszXunit.stopContextcCst|_|dS)z+Initializes a timer before starting a test.N)rrJr~r6testr r r beforeTestszXunit.beforeTestcCs|jr|j\t_t_dSr3)rFpopr{r|r}r@r r rrszXunit._endCapturecCs|d|_d|_dSr3)rrGrHrr r r afterTestszXunit.afterTestcCs|jr|qdSr3)rFrrr r rfinalizeszXunit.finalizecCs$|jr |j}|r dt|SdS)Nz'rm)rGgetvaluerr6r r r r_getCapturedStdouts zXunit._getCapturedStdoutcCs$|jr |j}|r dt|SdS)Nz'rm)rHrrrr r r_getCapturedStderr s zXunit._getCapturedStderrc Cs|}t|dtr.d}|jdd7<nd}|jdd7<t||j}|}|jd| t |d| t |d||| t |d| t |t |||d d S) z*Add error output to Xunit report. rrarerrorr^z<%(type)s type=%(errtype)s message=%(message)s>%(systemout)s%(systemerr)s) clsrrLtypeerrtypemessagetb systemout systemerrN)rM issubclassrrerr7idrfrzrOrr(r1rrr)r6rerrcaptrLrrrr r raddErrors,  zXunit.addErrorc Cs|}t||j}|jdd7<|}|jd|t|d|t|d||t |d|t |t || | ddS)z,Add failure output to Xunit report. r_rz%(systemout)s%(systemerr)srr)rrrLrrrrrN)rMrr7rerrfrzrOrr(r1rrr)r6rrrZtb_inforLrrr r r addFailure1s"  zXunit.addFailurec Csf|}|jdd7<|}|jd|t|d|t|d|||ddS)z,Add success output to Xunit report. r`rzb%(systemout)s%(systemerr)srr)rrrLrrN) rMrerrfrzrOrrr)r6rrrLrr r r addSuccessGszXunit.addSuccess)N)NN)N)r rBrC__doc__rZscorer7rsr8rMrOrYrbryr~rrrrrrrrrrr __classcell__r r rIrrDs.    rD)rrqdoctestrgr{ tracebackreriorrZxml.saxrZnose.plugins.baserZnose.excrZnose.pyversionrrcompiler rrrrr(r1objectr2rDr r r rs,)