
    daf6                     P   d dl Z d dlZd dlZd dlZ G d dej                        Z G d d      Z G d de      Z G d d	ej                        Z G d
 de      Z	 G d de      Z
d Zd Z ee      ZddZd Z G d dej                        Zedk(  r ej$                          yy)    Nc                   $    e Zd Zd Zd Zd Zd Zy)TestGetProfilec                 .    t        j                  d        y Nsys
setprofileselfs    3/root/Python-3.12.4/Lib/test/test_sys_setprofile.pysetUpzTestGetProfile.setUp       t    c                 .    t        j                  d        y r   r   r
   s    r   tearDownzTestGetProfile.tearDown   r   r   c                 J    | j                  t        j                                y r   )assertIsNoner   
getprofiler
   s    r   
test_emptyzTestGetProfile.test_empty   s    #..*+r   c                 |    d }t        j                  |       | j                  t        j                         |       y )Nc                       y r    argss    r   fnz&TestGetProfile.test_setget.<locals>.fn       r   )r   r	   assertIsr   )r   r   s     r   test_setgetzTestGetProfile.test_setget   s*    	 	rcnn&+r   N)__name__
__module____qualname__r   r   r   r   r   r   r   r   r      s    ,,r   r   c                   &    e Zd Zd Zd ZddZd Zy)HookWatcherc                      g | _         g | _        y r   )frameseventsr
   s    r   __init__zHookWatcher.__init__   s    r   c                 H    |dk(  s
|dk(  s|dk(  r| j                  ||       y y )Ncallreturn	exception	add_eventr   frameeventargs       r   callbackzHookWatcher.callback   s,    VO #NN5%( $r   Nc                 6   |t        j                  d      }	 | j                  j                  |      }| j                  j                  ||t        |      f       y# t        $ r3 t        | j                        }| j                  j                  |       Y cw xY w)zAdd an event to the log.N   )	r   	_getframer%   index
ValueErrorlenappendr&   ident)r   r0   r/   framenos       r   r-   zHookWatcher.add_event#   s~    =MM!$E	&kk''.G
 	GUE%L9:	  	&$++&GKKu%	&s   A 9BBc                     t        | j                  j                        t        t               g}d| _        | j                  D cg c]  }|d   |vs| c}S c c}w )zRemove calls to add_event().N   )r:   r-   __func__r%   r&   )r   
disalloweditems      r   
get_eventszHookWatcher.get_events0   sI    DNN334eElC
!%JQz0IJJJs   AAr   )r   r    r!   r'   r2   r-   rA   r   r   r   r#   r#      s    );Kr   r#   c                   B    e Zd Zd Zd Zd Zd Zd Zd ZeeeeeedZ	y)	ProfileSimulatorc                 J    || _         g | _        t        j                  |        y r   )testcasestackr#   r'   )r   rE   s     r   r'   zProfileSimulator.__init__9   s     
T"r   c                 0     | j                   |   | |       y r   )dispatchr.   s       r   r2   zProfileSimulator.callback>   s    eT5)r   c                 ^    | j                  d|       | j                  j                  |       y )Nr)   )r-   rF   r9   r   r/   s     r   
trace_callzProfileSimulator.trace_callB   s"    vu%

% r   c                 \    | j                  d|       | j                  j                          y )Nr*   )r-   rF   poprJ   s     r   trace_returnzProfileSimulator.trace_returnF   s    x'

r   c                 :    | j                   j                  d       y )Nz2the profiler should never receive exception events)rE   failrJ   s     r   trace_exceptionz ProfileSimulator.trace_exceptionJ   s    @	Br   c                      y r   r   rJ   s     r   
trace_passzProfileSimulator.trace_passN   s    r   )r)   r+   r*   c_callc_returnc_exceptionN)
r   r    r!   r'   r2   rK   rN   rQ   rS   rH   r   r   r   rC   rC   8   s<    #
*!B $!
Hr   rC   c                       e Zd Zd Zy)TestCaseBasec                     t        || j                               }||k7  r>| j                  dt        j                  |      dt        j                  |             y y )NzExpected events:
z
Received events:
)capture_eventsnew_watcherrP   pprintpformat)r   callableexpectedr&   s       r   check_eventszTestCaseBase.check_events\   sN    $*:*:*<=XII16>>&3IK L r   N)r   r    r!   r`   r   r   r   rX   rX   [   s    Lr   rX   c                   f    e 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 Zd Zd Zd Zy)ProfileHookTestCasec                     t               S r   )r#   r
   s    r   r[   zProfileHookTestCase.new_watcherd   s
    }r   c                 T    d }t        |      }| j                  |dd|fdd|fg       y )Nc                      y r   r   ps    r   fz*ProfileHookTestCase.test_simple.<locals>.fh   r   r   r4   r)   r*   r:   r`   r   rh   f_idents      r   test_simplezProfileHookTestCase.test_simpleg   8    	(!q&'2 (G4  	!r   c                 T    d }t        |      }| j                  |dd|fdd|fg       y )Nc                     ddz   y Nr4   r   r   rf   s    r   rh   z-ProfileHookTestCase.test_exception.<locals>.fp   	    aCr   r4   r)   r*   ri   rj   s      r   test_exceptionz"ProfileHookTestCase.test_exceptiono   8    	(!q&'2 (G4  	!r   c                 T    d }t        |      }| j                  |dd|fdd|fg       y )Nc                     ddz   y #  Y y xY wrp   r   rf   s    r   rh   z4ProfileHookTestCase.test_caught_exception.<locals>.fx       1D    r4   r)   r*   ri   rj   s      r   test_caught_exceptionz)ProfileHookTestCase.test_caught_exceptionw   :    	 (!q&'2 (G4  	!r   c                 T    d }t        |      }| j                  |dd|fdd|fg       y )Nc                     ddz   y #  Y y xY wrp   r   rf   s    r   rh   z;ProfileHookTestCase.test_caught_nested_exception.<locals>.f   rv   rw   r4   r)   r*   ri   rj   s      r   test_caught_nested_exceptionz0ProfileHookTestCase.test_caught_nested_exception   ry   r   c                 T    d }t        |      }| j                  |dd|fdd|fg       y )Nc                     ddz   y rp   r   rf   s    r   rh   z4ProfileHookTestCase.test_nested_exception.<locals>.f   rq   r   r4   r)   r*   ri   rj   s      r   test_nested_exceptionz)ProfileHookTestCase.test_nested_exception   s:    	(!q&'2  !(G4	  	!r   c                     d fd}t              }t        |      }| j                  |dd|fdd|fdd|fdd|fdd|fdd|fg       y )Nc                     ddz   y rp   r   rf   s    r   rh   z>ProfileHookTestCase.test_exception_in_except_clause.<locals>.f   rq   r   c                 F    	  |        y #   |        Y y #  Y Y y xY wxY wr   r   rg   rh   s    r   gz>ProfileHookTestCase.test_exception_in_except_clause.<locals>.g   s#    !qTs       r4   r)   r=   r*      ri   r   r   rk   g_identrh   s       @r   test_exception_in_except_clausez3ProfileHookTestCase.test_exception_in_except_clause   sq    		 ((!q&'2 &'2 (G4 &'2 (G4 (G4  	!r   c           
          d fd}t              }t        |      }| j                  |dd|fdd|fdd|fdd|fdd|fg       y )Nc                     ddz   y rp   r   rf   s    r   rh   z9ProfileHookTestCase.test_exception_propagation.<locals>.f   rq   r   c                 d     |        | j                  d       y # | j                  d       w xY w)Nfalling throughr,   r   s    r   r   z9ProfileHookTestCase.test_exception_propagation.<locals>.g   s%    1[[!23Q[[!23s    /r4   r)   r=   r*   r   ri   r   s       @r   test_exception_propagationz.ProfileHookTestCase.test_exception_propagation   sh    		4 ((!q&'2 &'2 (G4 "3W= (G4	  	!r   c                 T    d }t        |      }| j                  |dd|fdd|fg       y )Nc                 &    ddz   y #  ddz   Y y xY wrp   r   rf   s    r   rh   z/ProfileHookTestCase.test_raise_twice.<locals>.f   s    1AaCs    r4   r)   r*   ri   rj   s      r   test_raise_twicez$ProfileHookTestCase.test_raise_twice   s:    	 (!q&'2 (G4  	!r   c                 T    d }t        |      }| j                  |dd|fdd|fg       y )Nc                     ddz   y #   xY wrp   r   rf   s    r   rh   z1ProfileHookTestCase.test_raise_reraise.<locals>.f   s    1Es    
r4   r)   r*   ri   rj   s      r   test_raise_reraisez&ProfileHookTestCase.test_raise_reraise   s:    	 (!q&'2 (G4  	!r   c                 T    d }t        |      }| j                  |dd|fdd|fg       y )Nc                     t               r   )	Exceptionrf   s    r   rh   z)ProfileHookTestCase.test_raise.<locals>.f   s
    +r   r4   r)   r*   ri   rj   s      r   
test_raisezProfileHookTestCase.test_raise   s8    	(!q&'2 (G4  	!r   c                   	
 d fdfd		fd

fd}t              }t              }t        	      }t        
      }t        |      }| j                  |dd|fdd|fd	d|fd
d|fdd|fdd|fd
d|fd	d|fdd|fdd|fg
       y )Nc                      ddz   y rp   r   r   r   r   rh   z5ProfileHookTestCase.test_distant_exception.<locals>.f   rq   r   c                                y r   r   rh   s   r   r   z5ProfileHookTestCase.test_distant_exception.<locals>.g       Cr   c                                y r   r   r   s   r   hz5ProfileHookTestCase.test_distant_exception.<locals>.h   r   r   c                                y r   r   r   s   r   iz5ProfileHookTestCase.test_distant_exception.<locals>.i   r   r   c                              y r   r   rg   r   s    r   jz5ProfileHookTestCase.test_distant_exception.<locals>.j   r   r   r4   r)   r=   r         r*   ri   r   r   rk   r   h_identi_identj_identrh   r   r   r   s          @@@@r   test_distant_exceptionz*ProfileHookTestCase.test_distant_exception       					(((((!q&'2 &'2 &'2 &'2 &'2 (G4 (G4 (G4 (G4 (G4
  
	!r   c                     d fd}t              }t        |      }| j                  |dd|fdd|fdd|fdd|fdd|fdd|fdd|fdd|fg       y )Nc               3   4   K   t        d      D ]  } |   y wNr=   ranger   s    r   rh   z-ProfileHookTestCase.test_generator.<locals>.f        1X    c                             D ]  } y r   r   rg   r   rh   s     r   r   z-ProfileHookTestCase.test_generator.<locals>.g       S r   r4   r)   r=   r*   ri   r   s       @r   test_generatorz"ProfileHookTestCase.test_generator   s    		 ((!q&'2 &'2 (G4 &'2 (G4  !&'2 (G4 (G4  	!r   c           	          d fd}t              }t        |      }| j                  |dd|fdd|fdd|fdd|fg       y )Nc               3   4   K   t        d      D ]  } |   y wr   r   r   s    r   rh   z8ProfileHookTestCase.test_unfinished_generator.<locals>.f  r   r   c                 &    t                       y r   )nextr   s    r   r   z8ProfileHookTestCase.test_unfinished_generator.<locals>.g  s    Ir   r4   r)   r=   r*   ri   r   s       @r   test_unfinished_generatorz-ProfileHookTestCase.test_unfinished_generator  s]    		 ((!q&'2 &'2 (G4 (G4  	!r   c                     d fd}t              }t        |      }| j                  |dd|fdd|fdd|fdd|fdd|fdd|fdd|fdd|fg       y )Nc               3   4   K   t        d      D ]  } |   y wr   r   r   s    r   rh   z2ProfileHookTestCase.test_stop_iteration.<locals>.f  r   r   c                             D ]  } y r   r   r   s     r   r   z2ProfileHookTestCase.test_stop_iteration.<locals>.g  r   r   r4   r)   r=   r*   ri   r   s       @r   test_stop_iterationz'ProfileHookTestCase.test_stop_iteration  s    		 ((!q&'2 &'2 (G4 &'2 (G4 &'2 (G4 (G4
  
	!r   N)r   r    r!   r[   rl   rr   rx   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   rb   rb   c   sM    !!!!	!!&!!!!!8!,!!r   rb   c                   H    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)ProfileSimulatorTestCasec                     t        |       S r   )rC   r
   s    r   r[   z$ProfileSimulatorTestCase.new_watcher(  s    %%r   c                 T    d }t        |      }| j                  |dd|fdd|fg       y )Nc                      y r   r   rf   s    r   rh   z/ProfileSimulatorTestCase.test_simple.<locals>.f,  r   r   r4   r)   r*   ri   rj   s      r   rl   z$ProfileSimulatorTestCase.test_simple+  rm   r   c                 T    d }t        |      }| j                  |dd|fdd|fg       y )Nc                     ddz   y rp   r   rf   s    r   rh   z8ProfileSimulatorTestCase.test_basic_exception.<locals>.f4  rq   r   r4   r)   r*   ri   rj   s      r   test_basic_exceptionz-ProfileSimulatorTestCase.test_basic_exception3  rs   r   c                 T    d }t        |      }| j                  |dd|fdd|fg       y )Nc                     ddz   y #  Y y xY wrp   r   rf   s    r   rh   z9ProfileSimulatorTestCase.test_caught_exception.<locals>.f<  rv   rw   r4   r)   r*   ri   rj   s      r   rx   z.ProfileSimulatorTestCase.test_caught_exception;  ry   r   c                   	
 d fdfd		fd

fd}t              }t              }t        	      }t        
      }t        |      }| j                  |dd|fdd|fd	d|fd
d|fdd|fdd|fd
d|fd	d|fdd|fdd|fg
       y )Nc                      ddz   y rp   r   r   r   r   rh   z:ProfileSimulatorTestCase.test_distant_exception.<locals>.fE  rq   r   c                                y r   r   r   s   r   r   z:ProfileSimulatorTestCase.test_distant_exception.<locals>.gG  r   r   c                                y r   r   r   s   r   r   z:ProfileSimulatorTestCase.test_distant_exception.<locals>.hI  r   r   c                                y r   r   r   s   r   r   z:ProfileSimulatorTestCase.test_distant_exception.<locals>.iK  r   r   c                              y r   r   r   s    r   r   z:ProfileSimulatorTestCase.test_distant_exception.<locals>.jM  r   r   r4   r)   r=   r   r   r   r*   ri   r   s          @@@@r   r   z/ProfileSimulatorTestCase.test_distant_exceptionD  r   r   c                 ^    i fd}t        |      }| j                  |dd|fdd|fg       y )Nc                 4    t        j                  i dfi  y N*   dictgetrg   kwargss    r   rh   z7ProfileSimulatorTestCase.test_unbound_method.<locals>.fc  s    HHR&v&r   r4   r)   r*   ri   r   rh   rk   r   s      @r   test_unbound_methodz,ProfileSimulatorTestCase.test_unbound_methoda  s>    	'(!q&'2 (G46 	7r   c                 T    d }t        |      }| j                  |dd|fdd|fg       y )Nc                 ,    t         j                          y r   r   rf   s    r   rh   z?ProfileSimulatorTestCase.test_unbound_method_no_args.<locals>.fk  s    HHJr   r4   r)   r*   ri   rj   s      r   test_unbound_method_no_argsz4ProfileSimulatorTestCase.test_unbound_method_no_argsj  s8    	(!q&'2 (G46 	7r   c                 T    d }t        |      }| j                  |dd|fdd|fg       y )Nc                 8    t         j                  t        d       y r   r   r   printrf   s    r   rh   zDProfileSimulatorTestCase.test_unbound_method_invalid_args.<locals>.fs  s    HHUBr   r4   r)   r*   ri   rj   s      r    test_unbound_method_invalid_argsz9ProfileSimulatorTestCase.test_unbound_method_invalid_argsr  s8    	 (!q&'2 (G46 	7r   c                 ^    i fd}t        |      }| j                  |dd|fdd|fg       y )Nc                 0    t        j                  di  y )Nr   r   r   s    r   rh   zGProfileSimulatorTestCase.test_unbound_method_no_keyword_args.<locals>.f|  s    HHvr   r4   r)   r*   ri   r   s      @r   #test_unbound_method_no_keyword_argsz<ProfileSimulatorTestCase.test_unbound_method_no_keyword_argsz  s>    	(!q&'2 (G46 	7r   c                 ^    i fd}t        |      }| j                  |dd|fdd|fg       y )Nc                 <    t        j                  t        dfi  y r   r   r   s    r   rh   zLProfileSimulatorTestCase.test_unbound_method_invalid_keyword_args.<locals>.f  s    HHUB)&)r   r4   r)   r*   ri   r   s      @r   (test_unbound_method_invalid_keyword_argszAProfileSimulatorTestCase.test_unbound_method_invalid_keyword_args  s>    	*(!q&'2 (G46 	7r   N)r   r    r!   r[   rl   r   rx   r   r   r   r   r   r   r   r   r   r   r   '  s4    &!!!!:77777r   r   c                 |    t        | d      r| j                  }n| j                  }|j                  |j                  fS )Nf_code)hasattrr   __code__co_firstlinenoco_name)functioncodes     r   r:   r:     s5    x"  ,,r   c                 "     | |       y #  Y y xY wr   r   )rh   rg   s     r   protectr     s    	
1Ds   
 c                 x   |
t               }t        j                         }t        j                          	 t	        j
                  |j                         t        | |       t	        j
                  d        |rt        j                          	 |j                         dd S # |rt        j                          w w xY w)Nr4   )
r#   gc	isenableddisabler   r	   r2   r   enablerA   )r^   rg   old_gcs      r   rZ   rZ     s    yM \\^FJJLqzz"!tIIK<<>!B IIK s   A B   B9c                 B    dd l } |j                   t        |              y )Nr   )r\   rZ   )r^   r\   s     r   show_eventsr     s    FMM.*+r   c                   $    e Zd Zd Zd Zd Zd Zy)TestEdgeCasesc                     | j                  t        j                  t        j                                t        j                  d        y r   )
addCleanupr   r	   r   r
   s    r   r   zTestEdgeCases.setUp  s'    (89tr   c                     d }d  G fdd      }t        j                   |              t        j                  |       | j                  t        j                                y )Nc                       y r   r   r   s    r   fooz*TestEdgeCases.test_reentrancy.<locals>.foo      r   c                       y r   r   r   s    r   barz*TestEdgeCases.test_reentrancy.<locals>.bar  r  r   c                       e Zd Zd Z fdZy)(TestEdgeCases.test_reentrancy.<locals>.Ac                      y r   r   )r   r   s     r   __call__z1TestEdgeCases.test_reentrancy.<locals>.A.__call__  s    r   c                 0    t        j                         y r   r   )r   r  s    r   __del__z0TestEdgeCases.test_reentrancy.<locals>.A.__del__  s    s#r   N)r   r    r!   r  r  )r  s   r   Ar
    s    $r   r  )r   r	   assertEqualr   )r   r  r  r  s      @r   test_reentrancyzTestEdgeCases.test_reentrancy  sJ    			$ 	$ 	qss)3/r   c                     d }t        j                  |       ~t        j                  t        j                                y )Nc                       y r   r   r   s    r   r  z+TestEdgeCases.test_same_object.<locals>.foo  r  r   )r   r	   r   )r   r  s     r   test_same_objectzTestEdgeCases.test_same_object  s+    	 	ss~~'(r   c                    d }dt        j                         _        t        j                         }t        j                  d         |        t        j                  |       t        j
                  d         |        y )Nc                       y r   r   r   r   r   rh   z9TestEdgeCases.test_profile_after_trace_opcodes.<locals>.f  r  r   Tc                       y r   r   r   s    r   <lambda>z@TestEdgeCases.test_profile_after_trace_opcodes.<locals>.<lambda>      r   c                       y r   r   r   s    r   r  z@TestEdgeCases.test_profile_after_trace_opcodes.<locals>.<lambda>  r  r   )r   r5   f_trace_opcodesgettracesettracer	   )r   rh   
prev_traces      r    test_profile_after_trace_opcodesz.TestEdgeCases.test_profile_after_trace_opcodes  sR    	 +/'\\^
'(	Z )*	r   N)r   r    r!   r   r  r  r  r   r   r   r   r     s    0$)
r   r   __main__r   )r   r\   r   unittestTestCaser   r#   rC   rX   rb   r   r:   r   protect_identrZ   r   r   r   mainr   r   r   <module>r%     s    	  
 ,X&& ,"K K@ 
{  
FL8$$ LA!, A!Hb7| b7J- g ",
*H%% *Z zHMMO r   