
—àW  ã               @   s‚   d  Z  d d l Z d d l Z d d l Z d d l m Z d d l m Z d Z d d „  Z	 d	 Z
 d
 Z Gd d „  d e ƒ Z d S)zTest result objecté    Né   )Úutil)ÚwrapsTc                s"   t  ˆ  ƒ ‡  f d d †  ƒ } | S)Nc                s,   t  |  d d ƒ r |  j ƒ  ˆ  |  | | Ž S)NÚfailfastF)ÚgetattrÚstop)ÚselfÚargsÚkw)Úmethod© ú;/afs/.cs/s/python-3.5.2/amd64_ubu14/lib/python3.5/result.pyÚinner   s    
zfailfast.<locals>.inner)r   )r   r   r   )r   r   r      s    r   z
Stdout:
%sz
Stderr:
%sc               @   s?  e  Z d  Z d Z d Z d Z d Z d d d d d „ Z d d „  Z d d	 „  Z	 d
 d „  Z
 d d „  Z d d „  Z d d „  Z d d „  Z e d d „  ƒ Z e d d „  ƒ Z d d „  Z d d „  Z d d „  Z d d „  Z e d  d! „  ƒ Z d" d# „  Z d$ d% „  Z d& d' „  Z d( d) „  Z d* d+ „  Z d, d- „  Z d S).Ú
TestResultaÙ  Holder 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.
    NFc             C   s‘   d |  _  g  |  _ g  |  _ d |  _ g  |  _ g  |  _ g  |  _ d |  _ d |  _ d |  _	 d  |  _
 d  |  _ t j |  _ t j |  _ d |  _ d  S)NFr   )r   ÚfailuresÚerrorsÚtestsRunÚskippedÚexpectedFailuresÚunexpectedSuccessesÚ
shouldStopÚbufferÚ	tb_localsÚ_stdout_bufferÚ_stderr_bufferÚsysÚstdoutÚ_original_stdoutÚstderrÚ_original_stderrÚ_mirrorOutput)r   ÚstreamZdescriptionsÚ	verbosityr   r   r   Ú__init__&   s    												zTestResult.__init__c             C   s   d S)z#Called by TestRunner after test runNr   )r   r   r   r   ÚprintErrors7   s    zTestResult.printErrorsc             C   s&   |  j  d 7_  d |  _ |  j ƒ  d S)z-Called when the given test is about to be runr   FN)r   r    Ú_setupStdout)r   Útestr   r   r   Ú	startTest:   s    	zTestResult.startTestc             C   sR   |  j  rN |  j d  k r6 t j ƒ  |  _ t j ƒ  |  _ |  j t _ |  j t _ d  S)N)r   r   ÚioÚStringIOr   r   r   r   )r   r   r   r   r%   @   s    	zTestResult._setupStdoutc             C   s   d S)zpCalled once before any tests are executed.

        See startTest for a method called before each test.
        Nr   )r   r   r   r   ÚstartTestRunH   s    zTestResult.startTestRunc             C   s   |  j  ƒ  d |  _ d S)z'Called when the given test has been runFN)Ú_restoreStdoutr    )r   r&   r   r   r   ÚstopTestN   s    
zTestResult.stopTestc             C   sì   |  j  rè |  j r– t j j ƒ  } t j j ƒ  } | rc | j d ƒ sO | d 7} |  j j t	 | ƒ | r– | j d ƒ s‚ | d 7} |  j
 j t | ƒ |  j t _ |  j
 t _ |  j j d ƒ |  j j ƒ  |  j j d ƒ |  j j ƒ  d  S)NÚ
r   )r   r    r   r   Úgetvaluer   Úendswithr   ÚwriteÚSTDOUT_LINEr   ÚSTDERR_LINEr   ÚseekÚtruncater   )r   ÚoutputÚerrorr   r   r   r+   S   s$    		

zTestResult._restoreStdoutc             C   s   d S)zmCalled once after all tests are executed.

        See stopTest for a method called after each test.
        Nr   )r   r   r   r   ÚstopTestRunh   s    zTestResult.stopTestRunc             C   s/   |  j  j | |  j | | ƒ f ƒ d |  _ d S)zmCalled when an error has occurred. 'err' is a tuple of values as
        returned by sys.exc_info().
        TN)r   ÚappendÚ_exc_info_to_stringr    )r   r&   Úerrr   r   r   ÚaddErrorn   s    "zTestResult.addErrorc             C   s/   |  j  j | |  j | | ƒ f ƒ d |  _ d S)zdCalled when an error has occurred. 'err' is a tuple of values as
        returned by sys.exc_info().TN)r   r8   r9   r    )r   r&   r:   r   r   r   Ú
addFailurev   s    "zTestResult.addFailurec             C   s   | d k	 r{ t  |  d d ƒ r( |  j ƒ  t | d | j ƒ rJ |  j } n	 |  j } | j | |  j | | ƒ f ƒ d |  _ d S)z©Called 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().
        Nr   Fr   T)	r   r   Ú
issubclassÚfailureExceptionr   r   r8   r9   r    )r   r&   Zsubtestr:   r   r   r   r   Ú
addSubTest}   s    
	zTestResult.addSubTestc             C   s   d S)z-Called when a test has completed successfullyNr   )r   r&   r   r   r   Ú
addSuccessŽ   s    zTestResult.addSuccessc             C   s   |  j  j | | f ƒ d S)zCalled when a test is skipped.N)r   r8   )r   r&   Úreasonr   r   r   ÚaddSkip’   s    zTestResult.addSkipc             C   s&   |  j  j | |  j | | ƒ f ƒ d S)z/Called when an expected failure/error occurred.N)r   r8   r9   )r   r&   r:   r   r   r   ÚaddExpectedFailure–   s    	zTestResult.addExpectedFailurec             C   s   |  j  j | ƒ d S)z5Called when a test was expected to fail, but succeed.N)r   r8   )r   r&   r   r   r   ÚaddUnexpectedSuccess›   s    zTestResult.addUnexpectedSuccessc             C   sQ   t  |  j ƒ t  |  j ƒ k o) d k n oP t |  d ƒ pP t  |  j ƒ d k S)z/Tells whether or not this result was a success.r   r   )Úlenr   r   Úhasattrr   )r   r   r   r   ÚwasSuccessful    s    .zTestResult.wasSuccessfulc             C   s   d |  _  d S)z+Indicates that the tests should be aborted.TN)r   )r   r   r   r   r   ©   s    zTestResult.stopc             C   s%  | \ } } } x" | r3 |  j  | ƒ r3 | j } q W| | j k rU |  j | ƒ } n d } t j | | | d | d |  j ƒ} t | j ƒ  ƒ } |  j	 rt
 j j ƒ  }	 t
 j j ƒ  }
 |	 rè |	 j d ƒ s× |	 d 7}	 | j t |	 ƒ |
 r|
 j d ƒ s|
 d 7}
 | j t |
 ƒ d j | ƒ S)z>Converts a sys.exc_info()-style tuple of values into a string.NÚlimitÚcapture_localsr-   Ú )Ú_is_relevant_tb_levelÚtb_nextr>   Ú_count_relevant_tb_levelsÚ	tracebackÚTracebackExceptionr   ÚlistÚformatr   r   r   r.   r   r/   r8   r1   r2   Újoin)r   r:   r&   ÚexctypeÚvalueÚtbÚlengthZtb_eZmsgLinesr5   r6   r   r   r   r9   ­   s*    	

zTestResult._exc_info_to_stringc             C   s   d | j  j k S)NÚ
__unittest)Útb_frameÚ	f_globals)r   rU   r   r   r   rK   Ë   s    z TestResult._is_relevant_tb_levelc             C   s:   d } x- | r5 |  j  | ƒ r5 | d 7} | j } q	 W| S)Nr   r   )rK   rL   )r   rU   rV   r   r   r   rM   Î   s
    
z$TestResult._count_relevant_tb_levelsc             C   s5   d t  j |  j ƒ |  j t |  j ƒ t |  j ƒ f S)Nz!<%s run=%i errors=%i failures=%i>)r   ZstrclassÚ	__class__r   rE   r   r   )r   r   r   r   Ú__repr__Õ   s    !zTestResult.__repr__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Z_previousTestClassZ_testRunEnteredZ_moduleSetUpFailedr#   r$   r'   r%   r*   r,   r+   r7   r   r;   r<   r?   r@   rB   rC   rD   rG   r   r9   rK   rM   r[   r   r   r   r   r      s2   
	r   )r_   r(   r   rN   rJ   r   Ú	functoolsr   rW   r   r1   r2   Úobjectr   r   r   r   r   Ú<module>   s   