
    /hh&                         S r SSKrSSKrSSKrSSKJrJr  SSKJr  SSK	J
r
   " S S\5      r " S S	\R                  5      rS
 r0 rS\S'   S\S'   S\S'   \S:X  a  \" 5         gg)z#Test suite for the cProfile module.    N)ProfileTestregenerate_expected_output)assert_python_failure)supportc                   j    \ rS rSr\R
                  r\rSrS r	S r
S rS rS rS rS	 rS
 rS rSrg)CProfileTest   z{built-in method builtins.max}c                     [         $ N)_ProfileOutput)selfs    ;/opt/python-3.13.8/usr/lib/python3.13/test/test_cprofile.pyget_expected_output CProfileTest.get_expected_output   s        c                 B   SS K n[        R                  " 5        nUR                  S 5      nUR	                  5         UR                  5         UR                  5         U R                  UR                  R                  [        5        S S S 5        g ! , (       d  f       g = f)Nr   c                      [         $ r   )int r   r   <lambda>>CProfileTest.test_bad_counter_during_dealloc.<locals>.<lambda>   s    3r   )_lsprofr   catch_unraisable_exceptionProfilerenabledisableclearassertEqual
unraisableexc_type	TypeError)r   r   cmobjs       r   test_bad_counter_during_dealloc,CProfileTest.test_bad_counter_during_dealloc   sd    //1R"";/CJJLKKMIIKR]]33Y? 211s   A-B
Bc           	      L   SS K nUR                  5       [        R                  " 5       4 HT  nS HK  nU R	                  X#S9   [        X#5      nU R                  [        5         U" 5         S S S 5        S S S 5        MM     MV     g ! , (       d  f       N= f! , (       d  f       Mt  = f)Nr   )_pystart_callback_pyreturn_callback_ccall_callback_creturn_callback)profilemethod)r   r   cProfileProfilesubTestgetattrassertRaisesr!   )r   r   r+   r,   
method_objs        r   test_crash_with_not_enough_args,CProfileTest.test_crash_with_not_enough_args!   s    ((*H,<,<,>?G \\'\A!(!9J**95" 6 BA @ 65 BAs$   !B"B	*B
BB
B#c                   ^ SS K n " U4S jS5      n[        R                  " 5        nUR                  U" S5      5      mTR	                  5         S " 5         TR                  5         TR                  5         U R                  UR                  R                  [        5        S S S 5        [        R                  " 5        nUR                  U" S5      5      mTR	                  5         S " 5         TR                  5         TR                  5         U R                  UR                  R                  [        5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)Nr   c                   (   > \ rS rSrS rU 4S jrSrg)8CProfileTest.test_evil_external_timer.<locals>.EvilTimer5   c                     SU l         Xl        g )Nr   countdisable_count)r   r<   s     r   __init__ACProfileTest.test_evil_external_timer.<locals>.EvilTimer.__init__6   s    
%2"r   c                    > U =R                   S-  sl         U R                   U R                  :X  a  TR                  5         U R                   $ )N   )r;   r<   r   )r   profiler_with_evil_timers    r   __call__ACProfileTest.test_evil_external_timer.<locals>.EvilTimer.__call__:   s8    

a
::!3!33,446zz!r   r:   N)__name__
__module____qualname____firstlineno__r=   rB   __static_attributes__)rA   s   r   	EvilTimerr7   5   s    3" "r   rI   r@   c                      g r   r   r   r   r   r   7CProfileTest.test_evil_external_timer.<locals>.<lambda>F       Tr      c                      g r   r   r   r   r   r   rK   Q   rL   r   )r   r   r   r   r   r   r   r   r   r    RuntimeError)r   r   rI   r"   rA   s       @r   test_evil_external_timer%CProfileTest.test_evil_external_timer1   s    			" 		" //1R'.'7'7	!'E$$++-$,,.$**,R]]33\B 2 //1R'.'7'7	!'E$$++-$,,.$**,R]]33\B 21 21 21s   A:E?A:E
E
E!c                    U R                  5       nU R                  UR                  5        UR                  5         U R	                  [
        R                  R                  [
        R                  R                  5      S5        UR                  5         U R                  [
        R                  R                  [
        R                  R                  5      S 5        g Nr-   )
profilerclass
addCleanupr   r   r   sys
monitoringget_toolPROFILER_IDassertIsr   profs     r   test_profile_enable_disable(CProfileTest.test_profile_enable_disableV   s    !!#%NN##CNN$>$>?	M 	cnn--cnn.H.HI4Pr   c                    U R                  5       nU R                  UR                  5        U nU R                  X5        U R	                  [
        R                  R                  [
        R                  R                  5      S5        S S S 5        U R                  [
        R                  R                  [
        R                  R                  5      S 5        g ! , (       d  f       NV= frS   )	rT   rU   r   rZ   r   rV   rW   rX   rY   )r   r\   "_CProfileTest__enter__return_values      r   test_profile_as_context_manager,CProfileTest.test_profile_as_context_managerb   s    !!#%*MM$6 ''(B(BCZQ  	cnn--cnn.H.HI4P Ts   AC
C%c                     U R                  5       nU R                  5       nUR                  5         U R                  [        UR                  5        UR	                  5         g r   )rT   r   r1   
ValueErrorr   )r   prpr2s      r   test_second_profiler!CProfileTest.test_second_profilers   sD    !  "
		*cjj1


r   c                 X   U R                  5       nUR                  5         [        S S 5       5        UR                  5         UR	                  5         UR
                  R                  5        H:  u  nu  p4    nUS   S:X  d  M  U R                  US5        U R                  US5        M<     g)a*  
gh-106152
generator.throw() should trigger a call in cProfile
In the any() call below, there should be two entries for the generator:
    * one for the call to __next__ which gets a True and terminates any
    * one when the generator is garbage collected which will effectively
      do a throw.
c              3   *   #    U  H	  oS :H  v   M     g7f)r@   Nr   ).0as     r   	<genexpr>*CProfileTest.test_throw.<locals>.<genexpr>   s     #FqFFs   )r@   rM   rM   z	<genexpr>r@   N)rT   r   anyr   create_statsstatsitemsr   )r   re   funcccnc_s         r   
test_throwCProfileTest.test_throwz   s     !
		#F##



')xx~~'7#D#21aAw+%  Q'  Q' (8r   c                     U R                  5        nU R                  [        5         [        R	                  [        5       5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = fr   )rT   r1   r!   bytesfindstrr[   s     r   test_bad_descriptor CProfileTest.test_bad_descriptor   sK     !T""9-

35! . "!-- "!s"   A'AA'
A$	 A''
A5r   N)rD   rE   rF   rG   r-   r.   rT   profilermoduleexpected_max_outputr   r$   r3   rP   r]   ra   rg   rw   r}   rH   r   r   r   r   r      sJ    $$MN:
@% #CJ
QQ"(("r   r   c                       \ rS rSrS rSrg)TestCommandLine   c                 n    [        SSSS5      u  pnU R                  US5        U R                  SU5        g )Nz-mr-   z-sdemor   s!   option -s: invalid choice: 'demo')r   assertGreaterassertIn)r   rcouterrs       r   	test_sortTestCommandLine.test_sort   s5    ,T:tVL2q!:C@r   r   N)rD   rE   rF   rG   r   rH   r   r   r   r   r      s    Ar   r   c                      S[         R                  ;  a  [        R                  " 5         g [	        [
        [        5        g )Nz-r)rV   argvunittestmainr   __file__r   r   r   r   r   r      s!    388"8\:r   a         28    0.028    0.001    0.028    0.001 profilee.py:110(__getattr__)
        1    0.270    0.270    1.000    1.000 profilee.py:25(testfunc)
     23/3    0.150    0.007    0.170    0.057 profilee.py:35(factorial)
       20    0.020    0.001    0.020    0.001 profilee.py:48(mul)
        2    0.040    0.020    0.600    0.300 profilee.py:55(helper)
        4    0.116    0.029    0.120    0.030 profilee.py:73(helper1)
        2    0.000    0.000    0.140    0.070 profilee.py:84(helper2_indirect)
        8    0.312    0.039    0.400    0.050 profilee.py:88(helper2)
        8    0.064    0.008    0.080    0.010 profilee.py:98(subhelper)print_statsa  profilee.py:110(__getattr__)                      <-      16    0.016    0.016  profilee.py:98(subhelper)
profilee.py:25(testfunc)                          <-       1    0.270    1.000  <string>:1(<module>)
profilee.py:35(factorial)                         <-       1    0.014    0.130  profilee.py:25(testfunc)
                                                        20/3    0.130    0.147  profilee.py:35(factorial)
                                                           2    0.006    0.040  profilee.py:84(helper2_indirect)
profilee.py:48(mul)                               <-      20    0.020    0.020  profilee.py:35(factorial)
profilee.py:55(helper)                            <-       2    0.040    0.600  profilee.py:25(testfunc)
profilee.py:73(helper1)                           <-       4    0.116    0.120  profilee.py:55(helper)
profilee.py:84(helper2_indirect)                  <-       2    0.000    0.140  profilee.py:55(helper)
profilee.py:88(helper2)                           <-       6    0.234    0.300  profilee.py:55(helper)
                                                           2    0.078    0.100  profilee.py:84(helper2_indirect)
profilee.py:98(subhelper)                         <-       8    0.064    0.080  profilee.py:88(helper2)
{built-in method builtins.hasattr}                <-       4    0.000    0.004  profilee.py:73(helper1)
                                                           8    0.000    0.008  profilee.py:88(helper2)
{built-in method sys.exception}                   <-       4    0.000    0.000  profilee.py:73(helper1)
{method 'append' of 'list' objects}               <-       4    0.000    0.000  profilee.py:73(helper1)print_callersa;  <string>:1(<module>)                              ->       1    0.270    1.000  profilee.py:25(testfunc)
profilee.py:110(__getattr__)                      ->
profilee.py:25(testfunc)                          ->       1    0.014    0.130  profilee.py:35(factorial)
                                                           2    0.040    0.600  profilee.py:55(helper)
profilee.py:35(factorial)                         ->    20/3    0.130    0.147  profilee.py:35(factorial)
                                                          20    0.020    0.020  profilee.py:48(mul)
profilee.py:48(mul)                               ->
profilee.py:55(helper)                            ->       4    0.116    0.120  profilee.py:73(helper1)
                                                           2    0.000    0.140  profilee.py:84(helper2_indirect)
                                                           6    0.234    0.300  profilee.py:88(helper2)
profilee.py:73(helper1)                           ->       4    0.000    0.004  {built-in method builtins.hasattr}
profilee.py:84(helper2_indirect)                  ->       2    0.006    0.040  profilee.py:35(factorial)
                                                           2    0.078    0.100  profilee.py:88(helper2)
profilee.py:88(helper2)                           ->       8    0.064    0.080  profilee.py:98(subhelper)
profilee.py:98(subhelper)                         ->      16    0.016    0.016  profilee.py:110(__getattr__)
{built-in method builtins.hasattr}                ->      12    0.012    0.012  profilee.py:110(__getattr__)print_callees__main__)__doc__rV   r   r-   test.test_profiler   r   test.support.script_helperr   testr   r   TestCaser   r   r   rD   r   r   r   <module>r      s    ) 
   E < G"; G"TAh'' A; 	!K} #k "#p $ zF r   