
    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dlm	Z	 dZ
 G d d	e      Z G d
 dej                        Z G d de      Zy)zRunning tests    N   )result)_SubTest)registerResultTc                   $    e Zd ZdZd Zd ZddZy)_WritelnDecoratorz@Used to decorate file-like objects with a handy 'writeln' methodc                     || _         y N)stream)selfr   s     &/usr/lib/python3.12/unittest/runner.py__init__z_WritelnDecorator.__init__   s	        c                 L    |dv rt        |      t        | j                  |      S )N)r   __getstate__)AttributeErrorgetattrr   )r   attrs     r   __getattr__z_WritelnDecorator.__getattr__   s'    -- &&t{{4((r   Nc                 L    |r| j                  |       | j                  d       y N
)write)r   args     r   writelnz_WritelnDecorator.writeln   s    JJsO

4r   r
   )__name__
__module____qualname____doc__r   r   r    r   r   r   r      s    J)
r   r   c                        e Zd ZdZdZdZdd fd
Zd Z fdZd	 Z	 fd
Z
 fdZ fdZ fdZ fdZ fdZ fdZd Zd Z xZS )TextTestResultzhA test result class that can print formatted text results to a stream.

    Used by TextTestRunner.
    zF======================================================================zF----------------------------------------------------------------------N	durationsc                    t         t        |   |||       || _        |dkD  | _        |dk(  | _        || _        d| _        || _        y)zwConstruct a TextTestResult. Subclasses should accept **kwargs
        to ensure compatibility as the interface changes.r   TN)	superr"   r   r   showAlldotsdescriptions_newliner$   )r   r   r)   	verbosityr$   	__class__s        r   r   zTextTestResult.__init__&   sK     	nd,V\9M 1}N	("r   c                     |j                         }| j                  r|rdj                  t        |      |f      S t        |      S r   )shortDescriptionr)   joinstr)r   testdoc_first_lines      r   getDescriptionzTextTestResult.getDescription1   s=    ..099c$i899t9r   c                    t         t        |   |       | j                  rg| j                  j                  | j                  |             | j                  j                  d       | j                  j                          d| _        y y )N ... F)	r&   r"   	startTestr'   r   r   r3   flushr*   r   r1   r,   s     r   r6   zTextTestResult.startTest8   sd    nd-d3<<KKd11$78KKg&KK!DM	 r   c                    t        |t              }|s| j                  r| j                  s| j                  j	                          |r| j                  j                  d       | j                  j                  | j                  |             | j                  j                  d       | j                  j	                  |       | j                  j                          d| _        y )Nz  r5   T)
isinstancer   r*   r   r   r   r3   r7   )r   r1   status
is_subtests       r   _write_statuszTextTestResult._write_status@   s    h/
==##%!!$'KKd11$78KKg&F#r   c                    || j                   r?t        |d   |j                        r| j                  |d       n| j                  |d       nv| j                  rjt        |d   |j                        r| j
                  j                  d       n| j
                  j                  d       | j
                  j                          t        t        | +  |||       y )Nr   FAILERRORFE)r'   
issubclassfailureExceptionr=   r(   r   r   r7   r&   r"   
addSubTest)r   r1   subtesterrr,   s       r   rE   zTextTestResult.addSubTestM   s    ?||c!fg&>&>?&&w7&&w8c!fg&>&>?KK%%c*KK%%c*!!#nd.tWcBr   c                     t         t        |   |       | j                  r| j	                  |d       y | j
                  r6| j                  j                  d       | j                  j                          y y )Nok.)	r&   r"   
addSuccessr'   r=   r(   r   r   r7   r8   s     r   rK   zTextTestResult.addSuccess\   sW    nd.t4<<tT*YYKKc"KK r   c                     t         t        |   ||       | j                  r| j	                  |d       y | j
                  r6| j                  j                  d       | j                  j                          y y )Nr@   rB   )	r&   r"   addErrorr'   r=   r(   r   r   r7   r   r1   rG   r,   s      r   rM   zTextTestResult.addErrord   sY    nd,T37<<tW-YYKKc"KK r   c                     t         t        |   ||       | j                  r| j	                  |d       y | j
                  r6| j                  j                  d       | j                  j                          y y )Nr?   rA   )	r&   r"   
addFailurer'   r=   r(   r   r   r7   rN   s      r   rP   zTextTestResult.addFailurel   sY    nd.tS9<<tV,YYKKc"KK r   c                    t         t        |   ||       | j                  r"| j	                  |dj                  |             y | j                  r6| j                  j                  d       | j                  j                          y y )Nzskipped {0!r}s)
r&   r"   addSkipr'   r=   formatr(   r   r   r7   )r   r1   reasonr,   s      r   rS   zTextTestResult.addSkipt   sd    nd+D&9<<t_%;%;F%CDYYKKc"KK r   c                 6   t         t        |   ||       | j                  r6| j                  j                  d       | j                  j                          y | j                  r6| j                  j                  d       | j                  j                          y y )Nzexpected failurex)	r&   r"   addExpectedFailurer'   r   r   r7   r(   r   rN   s      r   rX   z!TextTestResult.addExpectedFailure|   sl    nd6tSA<<KK 23KKYYKKc"KK r   c                 4   t         t        |   |       | j                  r6| j                  j                  d       | j                  j                          y | j                  r6| j                  j                  d       | j                  j                          y y )Nzunexpected successu)	r&   r"   addUnexpectedSuccessr'   r   r   r7   r(   r   r8   s     r   r[   z#TextTestResult.addUnexpectedSuccess   sj    nd8><<KK 45KKYYKKc"KK r   c                    | j                   s| j                  r4| j                  j                          | j                  j	                          | j                  d| j                         | j                  d| j                         t        | dd      }|rt| j                  j                  | j                         |D ]/  }| j                  j                  d| j                  |              1 | j                  j	                          y y )Nr@   r?   unexpectedSuccessesr    zUNEXPECTED SUCCESS: )r(   r'   r   r   r7   printErrorListerrorsfailuresr   
separator1r3   )r   r]   r1   s      r   printErrorszTextTestResult.printErrors   s    99KK!KKGT[[1FDMM2%d,A2FKK0+ X##&:4;N;Nt;T:U$VWXKK	 r   c                 z   |D ]  \  }}| j                   j                  | j                         | j                   j                  |d| j                  |             | j                   j                  | j                         | j                   j                  d|z         | j                   j                           y )Nz: z%s)r   r   ra   r3   
separator2r7   )r   flavourr_   r1   rG   s        r   r^   zTextTestResult.printErrorList   s     	 ID#KK0KKGD4G4G4M NOKK0KKs
+KK	 r   )r   r   r   r   ra   rd   r   r3   r6   r=   rE   rK   rM   rP   rS   rX   r[   rb   r^   __classcell__)r,   s   @r   r"   r"      sY     JJEI 	#"C        r   r"   c                   :    e Zd ZdZeZ	 	 d	ddddZd Zd Zd Z	y)
TextTestRunnerzA test runner class that displays results in textual form.

    It prints out the names of tests as they are run, errors as they
    occur, and a summary of the results at the end of the test run.
    NF)	tb_localsr$   c                    |t         j                  }t        |      | _        || _        || _        || _        || _        || _        |	| _	        || _
        ||| _        yy)zConstruct a TextTestRunner.

        Subclasses should accept **kwargs to ensure compatibility as the
        interface changes.
        N)sysstderrr   r   r)   r+   failfastbufferri   r$   warningsresultclass)
r   r   r)   r+   rm   rn   rp   ro   ri   r$   s
             r   r   zTextTestRunner.__init__   sc     >ZZF'/(" "" "*D #r   c                     	 | j                  | j                  | j                  | j                  | j                        S # t
        $ r4 | j                  | j                  | j                  | j                        cY S w xY w)Nr#   )rp   r   r)   r+   r$   	TypeError)r   s    r   _makeResultzTextTestRunner._makeResult   ss    	4##DKK1B1B$(NNdnn $ N N 	4##DKK1B1B$(NN4 4	4s   <? :A<;A<c                 $   |j                   sy t        |j                   d d      }| j                  dkD  r|d | j                   }| j                  j	                  d       t        |d      r%| j                  j	                  |j                         d}|D ]@  \  }}| j                  dk  r|d	k  rd}| j                  j	                  d
|z  dd|       B |r| j                  j	                  d       y | j                  j	                  d       y )Nc                     | d   S )Nr   r    )rW   s    r   <lambda>z0TextTestRunner._printDurations.<locals>.<lambda>   s
    QqT r   T)keyreverser   zSlowest test durationsrd   F   gMbP?z%.3fs10 zA
(durations < 0.001s were hidden; use -v to show these durations) )collectedDurationssortedr$   r   r   hasattrrd   r+   )r   r   lshiddenr1   elapseds         r   _printDurationszTextTestRunner._printDurations   s    ((F--> ">>AOT^^$B456<(KK 1 12 	HMD'~~!goKKg.? FG		H
 KK !B C KK#r   c                    | j                         }t        |       | j                  |_        | j                  |_        | j                  |_        t        j                         5  | j
                  rt        j                  | j
                         t        j                         }t        |dd      }| |        	  ||       t        |dd      }| |        	 t        j                         }ddd       z
  } |j                          | j                  | j                  |       t        |d      r%| j                  j!                  |j"                         |j$                  }| j                  j!                  d||dk7  xr dxs d|fz         | j                  j!                          d	x}	x}
}	 t'        t(        |j*                  |j,                  |j.                  f      }|\  }	}
}g } |j2                         sr| j                  j5                  d
       t)        |j6                        t)        |j8                        }}|r|j;                  d|z         |rS|j;                  d|z         n>|d	k(  r|s| j                  j5                  d       n| j                  j5                  d       |r|j;                  d|z         |	r|j;                  d|	z         |
r|j;                  d|
z         |r/| j                  j!                  ddj=                  |      d       n| j                  j5                  d       | j                  j?                          |S # t        |dd      }| |        w w xY w# 1 sw Y   xY w# t0        $ r Y w xY w)z&Run the given test case or test suite.startTestRunNstopTestRunrd   zRan %d test%s in %.3fsr   rR   r|   r   FAILEDzfailures=%dz	errors=%dzNO TESTS RANOKz
skipped=%dzexpected failures=%dzunexpected successes=%dz (z, )r   ) rs   r   rm   rn   ri   ro   catch_warningssimplefiltertimeperf_counterr   rb   r$   r   r   r   r   rd   testsRunmaplenexpectedFailuresr]   skippedr   wasSuccessfulr   r`   r_   appendr/   r7   )r   r1   r   	startTimer   r   stopTime	timeTakenrunexpectedFailsr]   r   resultsinfosfailederroreds                   r   r   zTextTestRunner.run   s   !!#v-->>$$& 	+}}%%dmm4))+I"6>4@L'"V%fmTB*M((*H	+ y(	>>%  (6<(KK 1 12oo4 #("2s"8b)DE 	F8999+g	B# 7 7 & : : & 0 1G ;B7M.#v##%KKh'!&//2C4FGF]V34[723AXgKKn-KKd#LL/0LL/-?@LL25HHIKK499U+; =>KKd#e &fmTB*M +	+ 	+B  		s7   #AM2:M+M221M? M//M22M<?	NN)NTr   FFNN)
r   r   r   r   r"   rp   r   rs   r   r   r    r   r   rh   rh      s3    
 !KABJN+#t+*4$,Dr   rh   )r   rk   r   ro   r|   r   caser   signalsr   
__unittestobjectr   
TestResultr"   rh   r    r   r   <module>r      sN     
     #
  C V&& C L@V @r   