j f@sdZddlZddlZddlZddlmZddlmZdZddZ d Z d Z Gd d d e Z dS) zTest result objectN)util)wrapsTcs"tfdd}|S)Ncs/t|ddr|jn|||S)NfailfastF)getattrstop)selfargskw)method4/opt/alt/python34/lib64/python3.4/unittest/result.pyinner s zfailfast..inner)r)r rr )r r r srz Stdout: %sz Stderr: %sc@s?eZdZdZdZdZdZdddddZddZdd Z d d Z d d Z ddZ ddZ ddZeddZeddZddZddZddZddZed d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-ZdS). TestResultaHolder for test result information. Test results are automatically managed by the TestCase and TestSuite classes, and do not need to be explicitly manipulated by writers of tests. Each instance holds the total number of tests run, and collections of failures and errors that occurred among those test runs. The collections contain tuples of (testcase, exceptioninfo), where exceptioninfo is the formatted traceback of the error that occurred. NFcCsd|_g|_g|_d|_g|_g|_g|_d|_d|_d|_ d|_ t j |_ t j|_d|_dS)NFr)rfailureserrorstestsRunskippedexpectedFailuresunexpectedSuccesses shouldStopbuffer_stdout_buffer_stderr_buffersysstdout_original_stdoutstderr_original_stderr _mirrorOutput)rstreamZ descriptions verbosityr r r __init__&s             zTestResult.__init__cCsdS)z#Called by TestRunner after test runNr )rr r r printErrors6szTestResult.printErrorscCs&|jd7_d|_|jdS)z-Called when the given test is about to be runrFN)rr _setupStdout)rtestr r r startTest9s zTestResult.startTestcCsX|jrT|jdkr9tj|_tj|_n|jt_|jt_ndS)N)rrioStringIOrrrr)rr r r r$?s   zTestResult._setupStdoutcCsdS)zpCalled once before any tests are executed. See startTest for a method called before each test. Nr )rr r r startTestRunGszTestResult.startTestRuncCs|jd|_dS)z'Called when the given test has been runFN)_restoreStdoutr)rr%r r r stopTestMs zTestResult.stopTestcCs|jr|jrtjj}tjj}|ri|jdsR|d7}n|jjt |n|r|jds|d7}n|j jt |qn|jt_|j t_|j j d|j j|jj d|jjndS)N r)rrrrgetvaluerendswithrwrite STDOUT_LINEr STDERR_LINErseektruncater)routputerrorr r r r*Rs$       zTestResult._restoreStdoutcCsdS)zmCalled once after all tests are executed. See stopTest for a method called after each test. Nr )rr r r stopTestRungszTestResult.stopTestRuncCs/|jj||j||fd|_dS)zmCalled when an error has occurred. 'err' is a tuple of values as returned by sys.exc_info(). TN)rappend_exc_info_to_stringr)rr%errr r r addErrorms"zTestResult.addErrorcCs/|jj||j||fd|_dS)zdCalled when an error has occurred. 'err' is a tuple of values as returned by sys.exc_info().TN)rr7r8r)rr%r9r r r addFailureus"zTestResult.addFailurecCs|dk rt|ddr+|jnt|d|jrM|j}n |j}|j||j||fd|_ndS)zCalled at the end of a subtest. 'err' is None if the subtest ended successfully, otherwise it's a tuple of values as returned by sys.exc_info(). NrFrT) rr issubclassfailureExceptionrrr7r8r)rr%Zsubtestr9rr r r addSubTest|s    zTestResult.addSubTestcCsdS)z-Called when a test has completed successfullyNr )rr%r r r addSuccessszTestResult.addSuccesscCs|jj||fdS)zCalled when a test is skipped.N)rr7)rr%reasonr r r addSkipszTestResult.addSkipcCs&|jj||j||fdS)z.Called when an expected failure/error occured.N)rr7r8)rr%r9r r r addExpectedFailures zTestResult.addExpectedFailurecCs|jj|dS)z5Called when a test was expected to fail, but succeed.N)rr7)rr%r r r addUnexpectedSuccessszTestResult.addUnexpectedSuccesscCsQt|jt|jko)dknoPt|d pPt|jdkS)z/Tells whether or not this result was a success.rr)lenrrhasattrr)rr r r wasSuccessfuls.zTestResult.wasSuccessfulcCs d|_dS)z+Indicates that the tests should be aborted.TN)r)rr r r rszTestResult.stopc Cs%|\}}}x"|r3|j|r3|j}qW||jkrm|j|}tj||||}ntj|||}|jrtjj }tj j } |r|j ds|d7}n|j t |n| r| j ds| d7} n|j t| qndj|S)z>Converts a sys.exc_info()-style tuple of values into a string.r,)_is_relevant_tb_leveltb_nextr=_count_relevant_tb_levels tracebackformat_exceptionrrrr-rr.r7r0r1join) rr9r%exctypevaluetblengthZmsgLinesr4r5r r r r8s&    zTestResult._exc_info_to_stringcCsd|jjkS)N __unittest)tb_frame f_globals)rrPr r r rHsz TestResult._is_relevant_tb_levelcCs:d}x-|r5|j| r5|d7}|j}q W|S)Nrr)rHrI)rrPrQr r r rJs   z$TestResult._count_relevant_tb_levelscCs5dtj|j|jt|jt|jfS)Nz!<%s run=%i errors=%i failures=%i>)rZstrclass __class__rrDrr)rr r r __repr__s!zTestResult.__repr__)__name__ __module__ __qualname____doc__Z_previousTestClassZ_testRunEnteredZ_moduleSetUpFailedr"r#r&r$r)r+r*r6rr:r;r>r?rArBrCrFrr8rHrJrVr r r r rs2                r)rZr'rrKrGr functoolsrrRrr0r1objectrr r r r s