
    Rh#                     `    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 Z	dZ
d	Z G d
 de      Zy)zTest result object    N   )utilwrapsTc                 .     t                fd       }|S )Nc                 V    t        | dd      r| j                           | g|i |S )NfailfastF)getattrstop)selfargskwmethods      &/usr/lib/python3.12/unittest/result.pyinnerzfailfast.<locals>.inner   s-    4U+IIKd(T(R((    r   )r   r   s   ` r   r	   r	      s     
6]) ) Lr   z
Stdout:
%sz
Stderr:
%sc                       e Zd ZdZdZdZdZddZd Zd Z	d Z
d Zd	 Zd
 Zd Zed        Zed        Zd Zd Zd Zd Zed        Zd Zd Zd Zd Zd Zd Zd Zd Zy)
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                    d| _         g | _        g | _        d| _        g | _        g | _        g | _        g | _        d| _        d| _	        d| _
        d | _        d | _        t        j                  | _        t        j                   | _        d| _        y )NFr   )r	   failureserrorstestsRunskippedexpectedFailuresunexpectedSuccessescollectedDurations
shouldStopbuffer	tb_locals_stdout_buffer_stderr_buffersysstdout_original_stdoutstderr_original_stderr_mirrorOutput)r   streamdescriptions	verbositys       r   __init__zTestResult.__init__&   s     "#% "$"" #

 #

"r   c                      y)z#Called by TestRunner after test runN r   s    r   printErrorszTestResult.printErrors8       r   c                 \    | xj                   dz  c_         d| _        | j                          y)z-Called when the given test is about to be runr   FN)r   r'   _setupStdoutr   tests     r   	startTestzTestResult.startTest;   s$    "r   c                     | j                   ri| j                  2t        j                         | _        t        j                         | _        | j                  t
        _        | j                  t
        _        y y )N)r   r!   ioStringIOr    r"   r#   r%   r.   s    r   r2   zTestResult._setupStdoutA   sP    ;;""*&(kkm#&(kkm#,,CJ,,CJ r   c                      y)zpCalled once before any tests are executed.

        See startTest for a method called before each test.
        Nr-   r.   s    r   startTestRunzTestResult.startTestRunI   r0   r   c                 2    | j                          d| _        y)z'Called when the given test has been runFN)_restoreStdoutr'   r3   s     r   stopTestzTestResult.stopTestO   s    "r   c                    | j                   rQ| j                  rt        j                  j	                         }t        j
                  j	                         }|r8|j                  d      s|dz  }| j                  j                  t        |z         |r8|j                  d      s|dz  }| j                  j                  t        |z         | j                  t        _        | j                  t        _        | j                  j                  d       | j                  j                          | j                  j                  d       | j                  j                          y y )N
r   )r   r'   r"   r#   getvaluer%   endswithr$   writeSTDOUT_LINEr&   STDERR_LINEr    seektruncater!   )r   outputerrors      r   r<   zTestResult._restoreStdoutT   s   ;;!!,,.

++-!??40$))//f0DE >>$/))//e0CD..CJ..CJ$$Q'((*$$Q'((*% r   c                      y)zmCalled once after all tests are executed.

        See stopTest for a method called after each test.
        Nr-   r.   s    r   stopTestRunzTestResult.stopTestRuni   r0   r   c                 l    | j                   j                  || j                  ||      f       d| _        y)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   r4   errs      r   addErrorzTestResult.addErroro   s0    
 	D$":":3"EFG!r   c                 l    | j                   j                  || j                  ||      f       d| _        y)zdCalled when an error has occurred. 'err' is a tuple of values as
        returned by sys.exc_info().TN)r   rL   rM   r'   rN   s      r   
addFailurezTestResult.addFailurew   s0     	dD$<$<S$$GHI!r   c                     |zt        | dd      r| j                          t        |d   |j                        r| j                  }n| j
                  }|j                  || j                  ||      f       d| _        yy)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().
        Nr	   Fr   T)	r
   r   
issubclassfailureExceptionr   r   rL   rM   r'   )r   r4   subtestrO   r   s        r   
addSubTestzTestResult.addSubTest~   so     ?tZ/		#a&$"7"78MM7D$<$<S$$GHI!%D r   c                      y)z-Called when a test has completed successfullyNr-   r3   s     r   
addSuccesszTestResult.addSuccess   s    r   c                 >    | j                   j                  ||f       y)zCalled when a test is skipped.N)r   rL   )r   r4   reasons      r   addSkipzTestResult.addSkip   s    T6N+r   c                 ^    | j                   j                  || j                  ||      f       y)z/Called when an expected failure/error occurred.N)r   rL   rM   rN   s      r   addExpectedFailurezTestResult.addExpectedFailure   s+    $$4++C67	9r   c                 :    | j                   j                  |       y)z5Called when a test was expected to fail, but succeed.N)r   rL   r3   s     r   addUnexpectedSuccesszTestResult.addUnexpectedSuccess   s     	  ''-r   c                 j    t        | d      r'| j                  j                  t        |      |f       yy)zCalled when a test finished to run, regardless of its outcome.
        *test* is the test case corresponding to the test method.
        *elapsed* is the time represented in seconds, and it includes the
        execution of cleanup functions.
        r   N)hasattrr   rL   str)r   r4   elapseds      r   addDurationzTestResult.addDuration   s1     4-.##**CIw+?@ /r   c                     t        | j                        t        | j                        cxk(  xr dk(  nc xr' t        | d       xs t        | j                        dk(  S )z/Tells whether or not this result was a success.r   r   )lenr   r   rb   r   r.   s    r   wasSuccessfulzTestResult.wasSuccessful   sS    
 T]]#s4;;'7<1< 5T#899 4T--.!3	6r   c                     d| _         y)z+Indicates that the tests should be aborted.TN)r   r.   s    r   r   zTestResult.stop   s	    r   c                 "   |\  }}}| j                  ||||      }t        j                  |||| j                  d      }t	        |j                               }| j                  rt        j                  j                         }t        j                  j                         }	|r.|j                  d      s|dz  }|j                  t        |z         |	r.|	j                  d      s|	dz  }	|j                  t        |	z         dj                  |      S )z>Converts a sys.exc_info()-style tuple of values into a string.T)capture_localscompactr?    )_clean_tracebacks	tracebackTracebackExceptionr   listformatr   r"   r#   r@   r%   rA   rL   rC   rD   join)
r   rO   r4   exctypevaluetbtb_emsgLinesrG   rH   s
             r   rM   zTestResult._exc_info_to_string   s     ##GUB=++UB>>49 &;;ZZ((*FJJ'')Et,dNFf 45~~d+TMEe 34wwx  r   c                    d }d}|||fg}t        |      h}|r|j                         \  }}}|r1| j                  |      r |j                  }|r| j                  |      r ||j                  u r| j                  |       |r|}d}n||_        |o|j                  |j                  fD ]T  }	|	t        |	      |vs|j                  t        |	      |	|	j                  f       |j                  t        |	             V |r|S )NTF)idpop_is_relevant_tb_leveltb_nextrU   _remove_unittest_tb_frames__traceback__	__cause____context__rL   typeadd)
r   rt   ru   rv   r4   retfirstexcsseencs
             r   rn   zTestResult._clean_tracebacks   s   %$%5	{#'88: WeR33B7ZZ 33B7 $/////3&(# //5+<+<= (A}Ad):T!Wa$ABA(# * 
r   c                 2    d|j                   j                  v S )N
__unittest)tb_frame	f_globals)r   rv   s     r   r|   z TestResult._is_relevant_tb_level   s    r{{4444r   c                     d}|r3| j                  |      s"|}|j                  }|r| j                  |      s"|d|_        yy)a  Truncates usercode tb at the first unittest frame.

        If the first frame of the traceback is in user code,
        the prefix up to the first unittest frame is returned.
        If the first frame is already in the unittest module,
        the traceback is not modified.
        N)r|   r}   )r   rv   prevs      r   r~   z%TestResult._remove_unittest_tb_frames   sM     33B7DB 33B7 DL r   c                     dt        j                  | j                        | j                  t	        | j
                        t	        | j                        fz  S )Nz!<%s run=%i errors=%i failures=%i>)r   strclass	__class__r   rg   r   r   r.   s    r   __repr__zTestResult.__repr__   sA    3dnn-t}}c$++>NDMM"$$ 	%r   )NNN)__name__
__module____qualname____doc___previousTestClass_testRunEntered_moduleSetUpFailedr+   r/   r5   r2   r:   r=   r<   rJ   r	   rP   rR   rW   rY   r\   r^   r`   re   rh   r   rM   rn   r|   r~   r   r-   r   r   r   r      s    	 O#$.-#
+* " " " "&",9
 . .	A6!,85 %r   r   )r   r7   r"   ro   rm   r   	functoolsr   r   r	   rC   rD   objectr   r-   r   r   <module>r      s;     	 
   
 h% h%r   