
    =e;*                        d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlmZ  ej	         e
ed          d           ej        ej        dk    d           G d dej                                          Z ej	         e
ed          d           ej        ej        dk    d           G d	 d
e                                  Z ej	         e
ed          d           ej        ej        dk    d           G d de                                  Z ej	         e
ed          d           ej        ej        dk    d           G d de                                  Zedk    r ej                     dS dS )    N)supportkillzTest requires os.killwin32zTest cannot run on Windowsc                   r    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d Zd Zd Zd Zd ZdS )	TestBreakN   c                     t          j        t           j                  | _        | j        &t          j         t           j        | j                   d S d S N)signal	getsignalSIGINT_default_handlerint_handlerselfs    //usr/lib/python3.11/unittest/test/test_break.pysetUpzTestBreak.setUp   sE     & 0 ? ?'M&-)9::::: ('    c                     t          j         t           j        | j                   t          j                    t
          j        _        d t
          j        _        d S r
   )	r   r   r   weakrefWeakKeyDictionaryunittestsignals_results_interrupt_handlerr   s    r   tearDownzTestBreak.tearDown   s>    fmT%:;;;$+$=$?$?!.2+++r   c                    t          j        d          sd}n	|| j        }t          |          D ]}|                     |          5  |dk    r|                                  	  |             ||dz
  k    r|                                  n## ||dz
  k    r|                                  w w xY wd d d            n# 1 swxY w Y   d S )NT)cpython   )repeatr   )r   check_impl_detaildefault_repeatsrangesubTestr   r   )r   test_functionrepeatsr    s       r   withRepeatszTestBreak.withRepeats   s%   (666 	+ GG_*GGnn 	( 	(FV,, 
( 
( Q;;JJLLL(!MOOO1,, 1,, -
( 
( 
( 
( 
( 
( 
( 
( 
( 
( 
( 
( 
( 
( 
(	( 	(s*   	B<%
B/B< B--B<<C 	C 	c                    t          j        t           j                  }t          j                     |                     t          j        t           j                  |           	 t          j                    }t          j        |t           j                   n%# t          $ r | 
                    d           Y nw xY w|                     t          j        j        j                   d S NzKeyboardInterrupt not handled)r   r   r   r   installHandlerassertNotEqualosgetpidr   KeyboardInterruptfail
assertTruer   r   called)r   default_handlerpids      r   testInstallHandlerzTestBreak.testInstallHandler4   s     *6=99!!!F,V];;_MMM	7)++CGC''''  	7 	7 	7II566666	7 	(;BCCCCCs   %2B B:9B:c                 D   t          j                    }|                     |t           j        j                   t          j        |           	 |                     |t           j        j                   t          j        |           d S # t          j        |           w xY wr
   )r   
TestResultassertNotInr   r   registerResultassertInremoveResult)r   results     r   testRegisterResultzTestBreak.testRegisterResultA   s    $&&!1!:;;;'''	*MM&("2";<<<!&)))))H!&))))s   %B	 	Bc                 J      fd fd}                      |           d S )Nc                     t          j                    }t          j        |t          j                   d| _                            | j                   d S )NT)r,   r-   r   r   r   breakCaughtr0   
shouldStopr;   r3   r   s     r   testz+TestBreak.testInterruptCaught.<locals>.testL   sE    )++CGC'''!%FOOF-.....r   c                     t          j                    } t          j                     t          j        |                                t          j        t
          j                  j                   	  |            n%# t          $ r 
                    d           Y nw xY w                    | j                   d S r)   )r   r6   r*   r8   r+   r   r   r   r   r.   r/   r0   r?   r;   r   rB   s    r   r%   z4TestBreak.testInterruptCaught.<locals>.test_functionR   s    (**F#%%%#F+++ //%  
;V$ ; ; ;		9:::::;OOF./////s   4B   B"!B"r'   r   r%   rB   s   ` @r   testInterruptCaughtzTestBreak.testInterruptCaughtK   sW    	/ 	/ 	/ 	/ 	/	0 	0 	0 	0 	0 	0 	'''''r   c                      t          j        t           j                  t           j        k    r                     d            fd fd}                     |           d S )N&test requires SIGINT to not be ignoredc                    t          j                    }t          j        |t          j                   d| _                            | j                   t          j        |t          j                                       d           d S )NTz#Second KeyboardInterrupt not raised)	r,   r-   r   r   r   r?   r0   r@   r/   rA   s     r   rB   z+TestBreak.testSecondInterrupt.<locals>.testi   sl    )++CGC'''!%FOOF-...GC'''II;<<<<<r   c                  *   t          j                    } t          j                     t          j        |                                t
                    5   |            d d d            n# 1 swxY w Y                       | j                   d S r
   )r   r6   r*   r8   assertRaisesr.   r0   r?   rD   s    r   r%   z4TestBreak.testSecondInterrupt.<locals>.test_functionq   s    (**F#%%%#F+++""#455  V              OOF./////s   A..A25A2r   r   r   SIG_IGNskipTestr'   rF   s   ` @r   testSecondInterruptzTestBreak.testSecondInterruptc   s     FM**fn<<MMBCCC	= 	= 	= 	= 	=	0 	0 	0 	0 	0 	0 	'''''r   c                 <      fd}                      |           d S )Nc                     t          j                     t          j                    } t          j        |            t	          j        t          j                  }t          j                    }t          j        |                               t	          j        t          j                  |           t          j                    }	 t          j	        t          j
                    t          j                   n%# t          $ r                     d           Y nw xY w                    | j                                       |j                                       |j                   d S r)   )r   r*   r6   r8   r   r   r   assertEqualr,   r   r-   r.   r/   r0   r@   assertFalse)r;   new_handlerresult2result3r   s       r   r%   z/TestBreak.testTwoResults.<locals>.test_function}   s2   #%%%(**F#F+++ *6=99K)++G#G,,,V-fm<<kJJJ)++G;	V]3333$ ; ; ;		9:::::; OOF-...OOG.///W/00000s   0C8 8DDrE   r   r%   s   ` r   testTwoResultszTestBreak.testTwoResults|   s8    	1 	1 	1 	1 	1* 	'''''r   c                      t          j        t           j                  t           j        k    r                     d            fd}                     |           d S )NrI   c                  b   t          j                     t          j        t          j                  fd} t          j        t          j        |            	 t          j        t          j                    t          j                                       d           d S # t          $ r Y d S w xY w)Nc                       | |           d S r
    )framesignumhandlers     r   rU   zRTestBreak.testHandlerReplacedButCalled.<locals>.test_function.<locals>.new_handler   s    v&&&&&r   z6replaced but delegated handler doesn't raise interrupt)
r   r*   r   r   r   r,   r   r-   r/   r.   )rU   r`   r   s    @r   r%   z=TestBreak.testHandlerReplacedButCalled.<locals>.test_function   s     #%%%&v}55G' ' ' ' 'M&-555T	V]333 		RSSSSS %   s   0B   
B.-B.rM   rX   s   ` r   testHandlerReplacedButCalledz&TestBreak.testHandlerReplacedButCalled   sl     FM**fn<<MMBCCC	T 	T 	T 	T 	T" 	'''''r   c                     t          j        t          j                              }|                    t          j                              }|                     |t           j        j                   d S )N)stream)	r   TextTestRunnerioStringIOrun	TestSuiter9   r   r   )r   runnerr;   s      r   
testRunnerzTestBreak.testRunner   sW     (>>>H.0011fh.788888r   c                    t          j                    }t          j        |           t          j        |          }~t          j                     t          j                     |                      |                       d S r
   )r   r6   r8   r   refgccollectassertIsNone)r   r;   rl   s      r   testWeakReferenceszTestBreak.testWeakReferences   sj    $&&'''k&!! 	
RZ\\\##%%     r   c                    t          j                    }t          j        |           t          j                     |                     t          j        |                     |                     t          j        t          j                                         	 t          j                    }t          j	        |t          j                   n# t          $ r Y nw xY w|                     |j                   d S r
   )r   r6   r8   r*   r0   r:   rT   r,   r-   r   r   r   r.   r@   )r   r;   r3   s      r   testRemoveResultzTestBreak.testRemoveResult   s    $&&'''!!!-f55666 	.x/B/D/DEEFFF	)++CGC''''  	 	 	D	 	*+++++s   2C 
CCc           
         t                      t                      t                      t                      t          j        t          j                  } G fddt                      G fddt          j                  } |d          }|                                 |                     j        dd dd dfg           |                     j	        g           |                     |j
                   |                     t          j        t          j                  |           g _        g _	         |d          }|                                 |                     j        dd dd dfg           |                     j	        g           |                     |j
                   |                     t          j        t          j                  |           d S )	Nc                   (    e Zd Zg Zg Zd Z fdZdS )5TestBreak.testMainInstallsHandler.<locals>.FakeRunnerc                 >    | j                             ||f           d S r
   )initArgsappend)r   argskwargss      r   __init__z>TestBreak.testMainInstallsHandler.<locals>.FakeRunner.__init__   s"    $$dF^44444r   c                 <    | j                             |           S r
   )runArgsrx   )r   rB   r;   s     r   rg   z9TestBreak.testMainInstallsHandler.<locals>.FakeRunner.run   s    ##D)))r   N)__name__
__module____qualname__rw   r}   r{   rg   )r;   s   r   
FakeRunnerru      sG        HG5 5 5      r   r   c                        e Zd Z fdZdS )2TestBreak.testMainInstallsHandler.<locals>.Programc                 x    d| _         | _        | _        || _        d| _        | _        | _        d | _        d S )NF)exit	verbosityfailfast
catchbreak	tb_localsrj   rB   r;   )r   r   r   r   rB   r   s     r   r{   z;TestBreak.testMainInstallsHandler.<locals>.Program.__init__   s?    !	!* (",!&", 	"r   N)r~   r   r   r{   )r   r   rB   r   s   r   Programr      s=        # # # # # # # # # #r   r   Fr]   )bufferr   r   r   warningsT)objectr   r   r   r   TestProgramrunTestsrS   rw   r}   r;   r+   )	r   r2   r   pr   r   r;   rB   r   s	       @@@@@r   testMainInstallsHandlerz!TestBreak.testMainInstallsHandler   sC   88xxHH	 *6=99	 	 	 	 	 	 	 	 	 			# 		# 		# 		# 		# 		# 		# 		# 		# 		#h* 		# 		# 		# GENN	

,tBKAIBGAE	5G 5G 0H /I 	J 	J 	J
 	+dV4446***)&-88/JJJ 

GDMM	

,tBKAIBGAE	5G 5G 0H /I 	J 	J 	J
 	+dV4446***F,V];;_MMMMMr   c                 |   t          j        t           j                  }t          j                     t          j                     |                     t          j        t           j                  |           t          j                     |                     t          j        t           j                  |           d S r
   )r   r   r   r   r*   removeHandlerrS   )r   r2   s     r   testRemoveHandlerzTestBreak.testRemoveHandler  s     *6=99!!!   )&-88/JJJ 	   )&-88/JJJJJr   c                     t          j        t           j                  t          j                     t          j         fd            } |                                  t          j        t           j                             d S )Nc                  l                         t          j        t          j                              d S r
   )rS   r   r   r   )r2   r   s   r   rB   z4TestBreak.testRemoveHandlerAsDecorator.<locals>.test  s,    V-fm<<oNNNNNr   )r   r   r   r   r*   r   r+   )r   rB   r2   s   ` @r   testRemoveHandlerAsDecoratorz&TestBreak.testRemoveHandlerAsDecorator  s     *6=99!!!			O 	O 	O 	O 	O 
 		O 	F,V];;_MMMMMr   r
   )r~   r   r   r   r"   r   r   r'   r4   r<   rG   rP   rY   ra   rj   rp   rr   r   r   r   r]   r   r   r   r      s        K O; ; ;
3 3 3( ( ( (*D D D* * *( ( (0( ( (2( ( (2( ( (29 9 9
! 
! 
!, , ,$5N 5N 5NnK K K	N 	N 	N 	N 	Nr   r   c                       e Zd Zej        ZdS )TestBreakDefaultIntHandlerN)r~   r   r   r   default_int_handlerr   r]   r   r   r   r   !  s         ,KKKr   r   c                       e Zd Zej        ZdS )TestBreakSignalIgnoredN)r~   r   r   r   rN   r   r]   r   r   r   r   &           .KKKr   r   c                       e Zd Zej        ZdS )TestBreakSignalDefaultN)r~   r   r   r   SIG_DFLr   r]   r   r   r   r   +  r   r   r   __main__)rm   re   r,   sysr   r   r   rB   r   
skipUnlesshasattrskipIfplatformTestCaser   r   r   r   r~   mainr]   r   r   <module>r      sh   				 				 				 



          WWR((*ABB')EFFQN QN QN QN QN! QN QN GF CBQNf WWR((*ABB')EFF- - - - - - - GF CB- WWR((*ABB')EFF! ! ! ! !Y ! ! GF CB! WWR((*ABB')EFF! ! ! ! !Y ! ! GF CB! zHMOOOOO r   