ó [Z-Lc@s<dZdZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z ddl m Z de fd„ƒYZ d„Zd „Zd „Zd ejfd „ƒYZd e fd„ƒYZdejfd„ƒYZdejfd„ƒYZeZedkr8eddƒndS(s XML Test Runner for PyUnit sU$Id: /private/python/stdlib/xmlrunner.py 16654 2007-11-12T12:46:35.368945Z srittau $iÿÿÿÿN(tStringIO(tescapet _TestInfocBs)eZdZd„Zd„Zd„ZRS(sOInformation about a particular test. Used by _XMLTestResult. cCsX|jƒjdƒ}dj|d ƒ|d|_|_||_d|_d|_dS(Nt.iÿÿÿÿ( tidtsplittjoint_classt_methodt_timetNonet_errort_failure(tselfttestttimet_pieces((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyt__init__s $  cCs|jdi|jd6|jd6|jd6ƒ|jdkrW|j|d|jƒn|jdkr|j|d|jƒn|jdƒdS( s^Print information about this test case in XML format to the supplied stream. sF tclasstmethodRtfailureterrors N(twriteRRR R R t _print_errorR (R tstream((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyt print_report's   cCsÂtt|dƒƒ}|jdƒ|jd|t|dtƒrO|djp\t|dƒ|fƒtƒ}tj|dd|ƒ|jt|j ƒƒƒ|jd|ƒ|jdƒdS( sAPrint information from a failure or error to the supplied stream.is s <%s type="%s">%s iis s N( RtstrRt issubclasst Exceptiont__name__Rt tracebacktprint_tbR tgetvalue(R RttagnameRttextt tb_stream((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyR8s  ; (Rt __module__t__doc__RRR(((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyRs  cCs t||ƒS(s2Create a _TestInfo instance for a successful test.(R(RR((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pytcreate_successEscCst||ƒ}||_|S(s.Create a _TestInfo instance for a failed test.(RR (RRRtinfo((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pytcreate_failureIs cCst||ƒ}||_|S(s2Create a _TestInfo instance for an erroneous test.(RR (RRRR'((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyt create_errorOs t_XMLTestResultcBsDeZdZd„Zd„Zd„Zd„Zd„Zd„ZRS(sPA test result class that stores result as XML. Used by XMLTestRunner. cCsAtjj|ƒ||_d|_g|_d|_d|_dS(N( tunittestt TestResultRt _test_nameR t _start_timet_testsR R (R t classname((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyR]s     cCs8tjj||ƒd|_d|_tjƒ|_dS(N(R+R,t startTestR R R RR.(R R((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyR1es  cCs‹tjƒ|j}tjj||ƒ|jrGt|||jƒ}n0|jrht|||jƒ}nt ||ƒ}|j j |ƒdS(N( RR.R+R,tstopTestR R)R R(R&R/tappend(R Rt time_takenR'((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyR2ks  cCs#tjj|||ƒ||_dS(N(R+R,taddErrorR (R Rterr((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyR5vscCs#tjj|||ƒ||_dS(N(R+R,t addFailureR (R RR6((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyR7zscCs±|jdit|jƒd6t|jƒd6ƒ|jdi|jd6|jd6|d6ƒx|jD]}|j|ƒqgW|jd|ƒ|jd |ƒ|jd ƒd S( sÊPrints the XML report to the supplied stream. The time the tests took to perform as well as the captured standard output and standard error streams must be passed in.a s+ tnttRs* s* s N(RtlenterrorstfailuresR-ttestsRunR/R(R RR4toutR6R'((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyR~s (    ( RR$R%RR1R2R5R7R(((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyR*Us    t XMLTestRunnercBsAeZdZd„Zd„Zd„Zed„eddƒZRS(s®A test runner that stores results in XML format compatible with JUnit. XMLTestRunner(stream=None) -> XML test runner The XML file is written to the supplied stream. If stream is None, the results are stored in a file called TEST-..xml in the current working directory (if not overridden with the path property), where and are the module and class name of the test class. cOs1|jdƒ|_|jdƒ|_d|_dS(NRtfilenameR(tgett_streamt _filenamet_path(R targstkwargs((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyR¡sc Cs‹|j}|jd|j}|jdkr|d|}|jrK|j}nttjj |j |ƒdƒ}|j dƒn |j}t |ƒ}t j ƒ}tj}tj} tƒt_tƒt_zh||ƒytjjƒ} Wntk rd} nXytjjƒ} Wntk r-d} nXWd|t_| t_Xt j ƒ|} |j|| | | ƒ|jdkr‡|jƒn|S(s&Run the given test case or test suite.Rs TEST-%s.xmltws' tN(t __class__R$RRDR REtfiletostpathRRFRR*RtsyststdouttstderrRR tAttributeErrorRtclose( R Rtclass_R0RBRtresultt start_timet old_stdoutt old_stderrtout_sterr_sR4((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pytrun¦s@    !              cCs ||_dS(N(RF(R RN((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyt _set_pathÑscCs|jS(N(RF(R ((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pytÔss•The path where the XML files are stored. This property is ignored when the XML file is written to a file stream.N( RR$R%RR[R\tpropertyR RN(((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyRA”s    + tXMLTestRunnerTestcBsxeZd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Z de fd „ƒYZ d „Z d „Z RS( cCstƒ|_dS(N(RRD(R ((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pytsetUpÜscCs‡t|jƒ}|jtj|ƒƒ|jjƒ}tjdd|ƒ}tjdd|ƒ}tjdd|ƒ}|j||ƒdS(sVRun the test suite against the supplied test class and compare the XML result against the expected XML string. Fail if the expected string doesn't match the actual string. All time attribute in the expected string should have the value "0.000". All error and failure messages are reduced to "Foobar". stime="\d+\.\d+"s time="0.000"s (?s).*?sFoobars(?s).*?sFoobarN( RARDR[R+t makeSuiteR tretsubt assertEqual(R t test_classtexpectedtrunnertgot((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyt _try_test_runßs cCs-dtjfd„ƒY}|j|dƒdS(smRegression test: Check whether a test run without any tests matches a previous run. tTestTestcBseZRS((RR$(((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyRjüss² N(R+tTestCaseRi(R Rj((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyt test_no_tests÷s cCs-dtjfd„ƒY}|j|dƒdS(srRegression test: Check whether a test run with a successful test matches a previous run. RjcBseZd„ZRS(cSsdS(N((R ((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyttest_foo s(RR$Rm(((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyRj ss N(R+RkRi(R Rj((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyt test_successs cCs-dtjfd„ƒY}|j|dƒdS(soRegression test: Check whether a test run with a failing test matches a previous run. RjcBseZd„ZRS(cSs|jtƒdS(N(tassert_tFalse(R ((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyRms(RR$Rm(((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyRjssG Foobar N(R+RkRi(R Rj((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyt test_failures cCs-dtjfd„ƒY}|j|dƒdS(sqRegression test: Check whether a test run with a erroneous test matches a previous run. RjcBseZd„ZRS(cSs tƒ‚dS(N(t IndexError(R ((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyRm*s(RR$Rm(((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyRj)ss? Foobar N(R+RkRi(R Rj((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyt test_error$s cCs-dtjfd„ƒY}|j|dƒdS(sqRegression test: Check whether a test run with output to stdout matches a previous run. RjcBseZd„ZRS(cSs dGHdS(NtTest((R ((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyRm;s(RR$Rm(((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyRj:ss  N(R+RkRi(R Rj((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyttest_stdout_capture5s cCs-dtjfd„ƒY}|j|dƒdS(sqRegression test: Check whether a test run with output to stderr matches a previous run. RjcBseZd„ZRS(cSstjjdƒdS(NsTest (RORQR(R ((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyRmKs(RR$Rm(((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyRjJss  N(R+RkRi(R Rj((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyttest_stderr_captureEs t NullStreamcBseZdZd„ZRS(s:A file-like object that discards everything written to it.cCsdS(N((R tbuffer((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyRWs(RR$R%R(((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyRwUscCsBdtjfd„ƒY}t|jƒ}|jtj|ƒƒdS(sŒCheck whether the XMLTestRunner recovers gracefully from unit tests that change stdout, but don't change it back properly. RjcBseZd„ZRS(cSstjƒt_dS(N(R_RwRORP(R ((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyRm`s(RR$Rm(((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyRj_sN(R+RkRARDR[Ra(R RjRg((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyttest_unittests_changing_stdoutZscCsBdtjfd„ƒY}t|jƒ}|jtj|ƒƒdS(sŒCheck whether the XMLTestRunner recovers gracefully from unit tests that change stderr, but don't change it back properly. RjcBseZd„ZRS(cSstjƒt_dS(N(R_RwRORQ(R ((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyRmls(RR$Rm(((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyRjksN(R+RkRARDR[Ra(R RjRg((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyttest_unittests_changing_stderrfs(RR$R`RiRlRnRqRsRuRvtobjectRwRyRz(((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyR_Ûs        tXMLTestProgramcBseZd„ZRS(cCs2|jdkrtƒ|_ntjj|ƒdS(N(t testRunnerR RAR+t TestProgramtrunTests(R ((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyRts(RR$R(((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyR|sst__main__tmodule(R%t __revision__tos.pathRMRbRORRR+Rtxml.sax.saxutilsRR{RR&R(R)R,R*RARkR_R~R|tmainRR (((sD/opt/freeware/lib/python2.7/site-packages/Cheetah/Tests/xmlrunner.pyts*      .   ?G˜