
    0hh:                     T   S SK r S SKrS SKrS SKr " S S\R                  5      r " S S5      r " S S\5      r " S S	\R                  5      r " S
 S\5      r	 " S S\5      r
S rS r\" \5      rSS jrS r " S S\R                  5      r\S:X  a  \R$                  " 5         gg)    Nc                   ,    \ rS rSrS rS rS rS rSrg)TestGetProfile   c                 0    [         R                  " S 5        g Nsys
setprofileselfs    A/opt/python-3.13.8/usr/lib/python3.13/test/test_sys_setprofile.pysetUpTestGetProfile.setUp       t    c                 0    [         R                  " S 5        g r   r   r   s    r   tearDownTestGetProfile.tearDown   r   r   c                 L    U R                  [        R                  " 5       5        g r   )assertIsNoner	   
getprofiler   s    r   
test_emptyTestGetProfile.test_empty   s    #..*+r   c                     S n[         R                  " U5        U R                  [         R                  " 5       U5        g )Nc                      g r    argss    r   fn&TestGetProfile.test_setget.<locals>.fn       r   )r	   r
   assertIsr   )r   r   s     r   test_setgetTestGetProfile.test_setget   s*    	 	rcnn&+r   r   N)	__name__
__module____qualname____firstlineno__r   r   r   r#   __static_attributes__r   r   r   r   r      s    ,,r   r   c                   0    \ rS rSrS rS rSS jrS rSrg)	HookWatcher   c                      / U l         / U l        g r   )frameseventsr   s    r   __init__HookWatcher.__init__   s    r   c                 N    US:X  d  US:X  d  US:X  a  U R                  X!U5        g g )Ncallreturn	exception	add_eventr   frameeventargs       r   callbackHookWatcher.callback   s,    VO #NN5- $r   Nc                 <   Uc  [         R                  " S5      n U R                  R                  U5      nU R                  R                  XA[        U5      U45        g! [         a3    [        U R                  5      nU R                  R                  U5         Ndf = f)zAdd an event to the log.N   )	r	   	_getframer.   index
ValueErrorlenappendr/   ident)r   r:   r9   r;   framenos        r   r7   HookWatcher.add_event#   s~    =MM!$E	&kk''.G
 	GE%L#>?	  	&$++&GKKu%	&s   A :BBc                     [        U R                  R                  5      [        [         5      /nSU l        U R                   Vs/ s H  o"S   U;  d  M  UPM     sn$ s  snf )zRemove calls to add_event().N   )rE   r7   __func__r.   r/   )r   
disalloweditems      r   
get_eventsHookWatcher.get_events0   sK    DNN334eElC
!%JQz0IJJJs   AA)r/   r.   )NN)	r%   r&   r'   r(   r0   r<   r7   rM   r)   r   r   r   r+   r+      s    .@Kr   r+   c                   J    \ rS rSrS rS rS rS rS rS r	\\\\	\	\	S.r
S	rg
)ProfileSimulator8   c                 H    Xl         / U l        [        R                  U 5        g r   )testcasestackr+   r0   )r   rS   s     r   r0   ProfileSimulator.__init__9   s     
T"r   c                 .    U R                   U   " X5        g r   )dispatchr8   s       r   r<   ProfileSimulator.callback>   s    eT)r   c                 ^    U R                  SU5        U R                  R                  U5        g )Nr3   )r7   rT   rD   r   r9   s     r   
trace_callProfileSimulator.trace_callB   s"    vu%

% r   c                 \    U R                  SU5        U R                  R                  5         g )Nr4   )r7   rT   poprZ   s     r   trace_returnProfileSimulator.trace_returnF   s    x'

r   c                 :    U R                   R                  S5        g )Nz2the profiler should never receive exception events)rS   failrZ   s     r   trace_exception ProfileSimulator.trace_exceptionJ   s    @	Br   c                     g r   r   rZ   s     r   
trace_passProfileSimulator.trace_passN   s    r   )r3   r5   r4   c_callc_returnc_exception)rT   rS   N)r%   r&   r'   r(   r0   r<   r[   r_   rc   rf   rW   r)   r   r   r   rP   rP   8   s<    #
*!B $!
Hr   rP   c                       \ rS rSrSS jrSrg)TestCaseBase[   c           
         [        XR                  5       5      nU(       aH  XB:w  aB  U R                  S[        R                  " U5      < S[        R                  " U5      < 35        g g U VVVVs/ s H
  u  pVpxXVU4PM     snnnnU:w  aB  U R                  S[        R                  " U5      < S[        R                  " U5      < 35        g g s  snnnnf )NzExpected events:
z
Received events:
)capture_eventsnew_watcherrb   pprintpformat)	r   callableexpected
check_argsr/   rF   r:   rE   r;   s	            r   check_eventsTestCaseBase.check_events\   s    *:*:*<=!		#^^H5v~~f7MO P " KQQ&,FGE'&QU]]		#^^H5v~~f7MO P ^Qs   0C
r   N)F)r%   r&   r'   r(   rv   r)   r   r   r   rl   rl   [   s    	Pr   rl   c                   n    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rSrg)ProfileHookTestCaseh   c                     [        5       $ r   )r+   r   s    r   rp   ProfileHookTestCase.new_watcheri   s
    }r   c                 T    S n[        U5      nU R                  USSU4SSU4/5        g )Nc                     g r   r   ps    r   f*ProfileHookTestCase.test_simple.<locals>.fm   r!   r   r?   r3   r4   rE   rv   r   r   f_idents      r   test_simpleProfileHookTestCase.test_simplel   8    	(!q&'2 (G4  	!r   c                 T    S n[        U5      nU R                  USSU4SSU4/5        g )Nc                     SS-    g Nr?   r   r   r   s    r   r   -ProfileHookTestCase.test_exception.<locals>.fu   	    aCr   r?   r3   r4   r   r   s      r   test_exception"ProfileHookTestCase.test_exceptiont   8    	(!q&'2 (G4  	!r   c                 T    S n[        U5      nU R                  USSU4SSU4/5        g )Nc                     SS-    g !    g = fr   r   r   s    r   r   4ProfileHookTestCase.test_caught_exception.<locals>.f}       1D    r?   r3   r4   r   r   s      r   test_caught_exception)ProfileHookTestCase.test_caught_exception|   :    	 (!q&'2 (G4  	!r   c                 T    S n[        U5      nU R                  USSU4SSU4/5        g )Nc                     SS-    g !    g = fr   r   r   s    r   r   ;ProfileHookTestCase.test_caught_nested_exception.<locals>.f   r   r   r?   r3   r4   r   r   s      r   test_caught_nested_exception0ProfileHookTestCase.test_caught_nested_exception   r   r   c                 T    S n[        U5      nU R                  USSU4SSU4/5        g )Nc                     SS-    g r   r   r   s    r   r   4ProfileHookTestCase.test_nested_exception.<locals>.f   r   r   r?   r3   r4   r   r   s      r   test_nested_exception)ProfileHookTestCase.test_nested_exception   s:    	(!q&'2  !(G4	  	!r   c                    ^ S mU4S jn[        T5      n[        U5      nU R                  USSU4SSU4SSU4SSU4SSU4SSU4/5        g )Nc                     SS-    g r   r   r   s    r   r   >ProfileHookTestCase.test_exception_in_except_clause.<locals>.f   r   r   c                 F   >  T" U 5        g !   T" U 5         g !     g = f= fr   r   r   r   s    r   g>ProfileHookTestCase.test_exception_in_except_clause.<locals>.g   s#    !qTs       r?   r3   rI   r4      r   r   r   r   g_identr   s       @r   test_exception_in_except_clause3ProfileHookTestCase.test_exception_in_except_clause   sq    		 ((!q&'2 &'2 (G4 &'2 (G4 (G4  	!r   c           
         ^ S mU4S jn[        T5      n[        U5      nU R                  USSU4SSU4SSU4SSU4SSU4/5        g )Nc                     SS-    g r   r   r   s    r   r   9ProfileHookTestCase.test_exception_propagation.<locals>.f   r   r   c                 d   > T" U 5        U R                  S5        g ! U R                  S5        f = f)Nfalling throughr6   r   s    r   r   9ProfileHookTestCase.test_exception_propagation.<locals>.g   s%    1[[!23Q[[!23s    /r?   r3   rI   r4   r   r   r   s       @r   test_exception_propagation.ProfileHookTestCase.test_exception_propagation   sh    		4 ((!q&'2 &'2 (G4 "3W= (G4	  	!r   c                 T    S n[        U5      nU R                  USSU4SSU4/5        g )Nc                 &    SS-    g !   SS-     g = fr   r   r   s    r   r   /ProfileHookTestCase.test_raise_twice.<locals>.f   s    1AaCs    r?   r3   r4   r   r   s      r   test_raise_twice$ProfileHookTestCase.test_raise_twice   s:    	 (!q&'2 (G4  	!r   c                 T    S n[        U5      nU R                  USSU4SSU4/5        g )Nc                     SS-    g !   e = fr   r   r   s    r   r   1ProfileHookTestCase.test_raise_reraise.<locals>.f   s    1Es    
r?   r3   r4   r   r   s      r   test_raise_reraise&ProfileHookTestCase.test_raise_reraise   s:    	 (!q&'2 (G4  	!r   c                 T    S n[        U5      nU R                  USSU4SSU4/5        g )Nc                     [        5       er   )	Exceptionr   s    r   r   )ProfileHookTestCase.test_raise.<locals>.f   s
    +r   r?   r3   r4   r   r   s      r   
test_raiseProfileHookTestCase.test_raise   s8    	(!q&'2 (G4  	!r   c                 $  ^^^	^
 S mU4S jmU4S jm	U	4S jm
U
4S jn[        T5      n[        T5      n[        T	5      n[        T
5      n[        U5      nU R                  USSU4SSU4S	SU4S
SU4SSU4SSU4S
SU4S	SU4SSU4SSU4/
5        g )Nc                      SS-    g r   r   r   r   r   r   5ProfileHookTestCase.test_distant_exception.<locals>.f   r   r   c                     > T " 5         g r   r   r   s   r   r   5ProfileHookTestCase.test_distant_exception.<locals>.g       Cr   c                     > T " 5         g r   r   r   s   r   h5ProfileHookTestCase.test_distant_exception.<locals>.h   r   r   c                     > T " 5         g r   r   r   s   r   i5ProfileHookTestCase.test_distant_exception.<locals>.i   r   r   c                    > T" 5         g r   r   r   r   s    r   j5ProfileHookTestCase.test_distant_exception.<locals>.j   r   r   r?   r3   rI   r         r4   r   r   r   r   r   h_identi_identj_identr   r   r   r   s          @@@@r   test_distant_exception*ProfileHookTestCase.test_distant_exception       					(((((!q&'2 &'2 &'2 &'2 &'2 (G4 (G4 (G4 (G4 (G4
  
	!r   c                    ^ S mU4S jn[        T5      n[        U5      nU R                  USSU4SSU4SSU4SSU4SSU4SSU4SSU4SSU4/5        g )Nc               3   8   #    [        S5       H  n U v   M	     g 7fNrI   ranger   s    r   r   -ProfileHookTestCase.test_generator.<locals>.f        1X    c                 "   > T" 5        H  nM     g r   r   r   r   r   s     r   r   -ProfileHookTestCase.test_generator.<locals>.g       S r   r?   r3   rI   r4   r   r   s       @r   test_generator"ProfileHookTestCase.test_generator   s    		 ((!q&'2 &'2 (G4 &'2 (G4  !&'2 (G4 (G4  	!r   c           
         ^ S mU4S jn[        T5      n[        U5      nU R                  USSUS 4SSUS 4SSUS4SSUS 4/SS	9  g )
Nc               3   8   #    [        S5       H  n U v   M	     g 7fr   r   r   s    r   r   8ProfileHookTestCase.test_unfinished_generator.<locals>.f  r   r   c                 &   > [        T" 5       5        g r   )nextr   s    r   r   8ProfileHookTestCase.test_unfinished_generator.<locals>.g  s    Ir   r?   r3   rI   r4   r   T)ru   r   r   s       @r   test_unfinished_generator-ProfileHookTestCase.test_unfinished_generator  so    		 ((!q&'48 &'48 (GQ7 (GT:  -1	 	 	2r   c                    ^ S mU4S jn[        T5      n[        U5      nU R                  USSU4SSU4SSU4SSU4SSU4SSU4SSU4SSU4/5        g )Nc               3   8   #    [        S5       H  n U v   M	     g 7fr   r   r   s    r   r   2ProfileHookTestCase.test_stop_iteration.<locals>.f  r   r   c                 "   > T" 5        H  nM     g r   r   r   s     r   r   2ProfileHookTestCase.test_stop_iteration.<locals>.g  r   r   r?   r3   rI   r4   r   r   s       @r   test_stop_iteration'ProfileHookTestCase.test_stop_iteration  s    		 ((!q&'2 &'2 (G4 &'2 (G4 &'2 (G4 (G4
  
	!r   r   N)r%   r&   r'   r(   rp   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r)   r   r   r   ry   ry   h   sM    !!!!	!!&!!!!!8!,2!r   ry   c                   P    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rSrg)ProfileSimulatorTestCasei,  c                     [        U 5      $ r   )rP   r   s    r   rp   $ProfileSimulatorTestCase.new_watcher-  s    %%r   c                 T    S n[        U5      nU R                  USSU4SSU4/5        g )Nc                     g r   r   r   s    r   r   /ProfileSimulatorTestCase.test_simple.<locals>.f1  r!   r   r?   r3   r4   r   r   s      r   r   $ProfileSimulatorTestCase.test_simple0  r   r   c                 T    S n[        U5      nU R                  USSU4SSU4/5        g )Nc                     SS-    g r   r   r   s    r   r   8ProfileSimulatorTestCase.test_basic_exception.<locals>.f9  r   r   r?   r3   r4   r   r   s      r   test_basic_exception-ProfileSimulatorTestCase.test_basic_exception8  r   r   c                 T    S n[        U5      nU R                  USSU4SSU4/5        g )Nc                     SS-    g !    g = fr   r   r   s    r   r   9ProfileSimulatorTestCase.test_caught_exception.<locals>.fA  r   r   r?   r3   r4   r   r   s      r   r   .ProfileSimulatorTestCase.test_caught_exception@  r   r   c                 $  ^^^	^
 S mU4S jmU4S jm	U	4S jm
U
4S jn[        T5      n[        T5      n[        T	5      n[        T
5      n[        U5      nU R                  USSU4SSU4S	SU4S
SU4SSU4SSU4S
SU4S	SU4SSU4SSU4/
5        g )Nc                      SS-    g r   r   r   r   r   r   :ProfileSimulatorTestCase.test_distant_exception.<locals>.fJ  r   r   c                     > T " 5         g r   r   r   s   r   r   :ProfileSimulatorTestCase.test_distant_exception.<locals>.gL  r   r   c                     > T " 5         g r   r   r   s   r   r   :ProfileSimulatorTestCase.test_distant_exception.<locals>.hN  r   r   c                     > T " 5         g r   r   r   s   r   r   :ProfileSimulatorTestCase.test_distant_exception.<locals>.iP  r   r   c                    > T" 5         g r   r   r   s    r   r   :ProfileSimulatorTestCase.test_distant_exception.<locals>.jR  r   r   r?   r3   rI   r   r   r   r4   r   r   s          @@@@r   r   /ProfileSimulatorTestCase.test_distant_exceptionI  r   r   c                 `   ^ 0 mU4S jn[        U5      nU R                  USSU4SSU4/5        g )Nc                 6   > [         R                  " 0 S40 TD6  g N*   dictgetr   kwargss    r   r   7ProfileSimulatorTestCase.test_unbound_method.<locals>.fh  s    HHR&v&r   r?   r3   r4   r   r   r   r   r&  s      @r   test_unbound_method,ProfileSimulatorTestCase.test_unbound_methodf  s>    	'(!q&'2 (G46 	7r   c                 T    S n[        U5      nU R                  USSU4SSU4/5        g )Nc                 ,    [         R                  5         g r   r"  r   s    r   r   ?ProfileSimulatorTestCase.test_unbound_method_no_args.<locals>.fp  s    HHJr   r?   r3   r4   r   r   s      r   test_unbound_method_no_args4ProfileSimulatorTestCase.test_unbound_method_no_argso  s8    	(!q&'2 (G46 	7r   c                 T    S n[        U5      nU R                  USSU4SSU4/5        g )Nc                 8    [         R                  [        S5        g r   r#  r$  printr   s    r   r   DProfileSimulatorTestCase.test_unbound_method_invalid_args.<locals>.fx  s    HHUBr   r?   r3   r4   r   r   s      r    test_unbound_method_invalid_args9ProfileSimulatorTestCase.test_unbound_method_invalid_argsw  s8    	 (!q&'2 (G46 	7r   c                 `   ^ 0 mU4S jn[        U5      nU R                  USSU4SSU4/5        g )Nc                 2   > [         R                  " S0 TD6  g )Nr   r"  r%  s    r   r   GProfileSimulatorTestCase.test_unbound_method_no_keyword_args.<locals>.f  s    HHvr   r?   r3   r4   r   r(  s      @r   #test_unbound_method_no_keyword_args<ProfileSimulatorTestCase.test_unbound_method_no_keyword_args  s>    	(!q&'2 (G46 	7r   c                 `   ^ 0 mU4S jn[        U5      nU R                  USSU4SSU4/5        g )Nc                 >   > [         R                  " [        S40 TD6  g r   r2  r%  s    r   r   LProfileSimulatorTestCase.test_unbound_method_invalid_keyword_args.<locals>.f  s    HHUB)&)r   r?   r3   r4   r   r(  s      @r   (test_unbound_method_invalid_keyword_argsAProfileSimulatorTestCase.test_unbound_method_invalid_keyword_args  s>    	*(!q&'2 (G46 	7r   r   N)r%   r&   r'   r(   rp   r   r  r   r   r)  r.  r5  r:  r?  r)   r   r   r   r  r  ,  s4    &!!!!:77777r   r  c                     [        U S5      (       a  U R                  nOU R                  nUR                  UR                  4$ )Nf_code)hasattrrB  __code__co_firstlinenoco_name)functioncodes     r   rE   rE     s8    x""  ,,r   c                 "    U " U5        g !    g = fr   r   )r   r   s     r   protectrJ    s    	
1Ds   
 c                    Uc
  [        5       n[        R                  " 5       n[        R                  " 5          [        R
                  " UR                  5        [        X5        [        R
                  " S 5        U(       a  [        R                  " 5         UR                  5       SS $ ! U(       a  [        R                  " 5         f f = f)Nr?   )
r+   gc	isenableddisabler	   r
   r<   rJ  enablerM   )rs   r   old_gcs      r   ro   ro     s    yM \\^FJJLqzz"tIIK<<>!B IIK s   AB) )Cc                 B    SS K nUR                   " [        U 5      5        g )Nr   )rq   ro   )rs   rq   s     r   show_eventsrS    s    
MM.*+r   c                   2    \ rS rSrS rS rS rS rS rSr	g)	TestEdgeCasesi  c                     U R                  [        R                  [        R                  " 5       5        [        R                  " S 5        g r   )
addCleanupr	   r
   r   r   s    r   r   TestEdgeCases.setUp  s'    (89tr   c                    ^ S nS m " U4S jS5      n[         R                  " U" 5       5        [         R                  " U5        U R                  [         R                  " 5       T5        g )Nc                      g r   r   r   s    r   foo*TestEdgeCases.test_reentrancy.<locals>.foo      r   c                      g r   r   r   s    r   bar*TestEdgeCases.test_reentrancy.<locals>.bar  r]  r   c                   (   > \ rS rSrS rU 4S jrSrg)(TestEdgeCases.test_reentrancy.<locals>.Ai  c                     g r   r   )r   r   s     r   __call__1TestEdgeCases.test_reentrancy.<locals>.A.__call__  s    r   c                 2   > [         R                  " T5        g r   r   )r   r_  s    r   __del__0TestEdgeCases.test_reentrancy.<locals>.A.__del__  s    s#r   r   N)r%   r&   r'   r(   rd  rg  r)   )r_  s   r   Arb    s    $ $r   ri  )r	   r
   assertEqualr   )r   r[  ri  r_  s      @r   test_reentrancyTestEdgeCases.test_reentrancy  sJ    			$ 	$ 	qss)3/r   c                     S n[         R                  " U5        A[         R                  " [         R                  " 5       5        g )Nc                      g r   r   r   s    r   r[  +TestEdgeCases.test_same_object.<locals>.foo  r]  r   )r	   r
   r   )r   r[  s     r   test_same_objectTestEdgeCases.test_same_object  s+    	 	ss~~'(r   c                    S nS[         R                  " 5       l        [         R                  " 5       n[         R                  " S 5        U" 5         [         R                  " U5        [         R
                  " S 5        U" 5         g )Nc                      g r   r   r   r   r   r   9TestEdgeCases.test_profile_after_trace_opcodes.<locals>.f  r]  r   Tc                      g r   r   r   s    r   <lambda>@TestEdgeCases.test_profile_after_trace_opcodes.<locals>.<lambda>  s    4r   c                      g r   r   r   s    r   rv  rw    s    Tr   )r	   r@   f_trace_opcodesgettracesettracer
   )r   r   
prev_traces      r    test_profile_after_trace_opcodes.TestEdgeCases.test_profile_after_trace_opcodes  sR    	 +/'\\^
'(	Z )*	r   c                    ^  " S S5      n/ m[         R                  " U4S j5        U" 5       R                  5         [         R                  " S 5        U R                  T/ SQ5        g )Nc                   $    \ rS rSr\" \5      rSrg)4TestEdgeCases.test_method_with_c_function.<locals>.Ai  r   N)r%   r&   r'   r(   classmethodreprr   r)   r   r   r   ri  r    s    D!Ar   ri  c                 &   > TR                  U5      $ r   )rD   )r9   r:   r   r/   s      r   rv  ;TestEdgeCases.test_method_with_c_function.<locals>.<lambda>  s    &--2Fr   )rh   ri   rh   )r	   r
   r   rj  )r   ri  r/   s     @r   test_method_with_c_function)TestEdgeCases.test_method_with_c_function  sG    
	" 	"FG	t!ABr   r   N)
r%   r&   r'   r(   r   rk  rp  r}  r  r)   r   r   r   rU  rU    s    0$)
Cr   rU  __main__r   )rM  rq   r	   unittestTestCaser   r+   rP   rl   ry   r  rE   rJ  protect_identro   rS  rU  r%   mainr   r   r   <module>r     s    	  
 ,X&& ,"K K@ 
{  
F
P8$$ 
PA!, A!Hb7| b7J- g ",
8CH%% 8Cv zMMO r   