
    0hh#                        S r SSKrSSKrSSKrSSKrSSKJr  SSKJr  SSK	J
r
JrJrJr  SSKJrJr  SSKrSSKJrJr  SSKJrJr   " S	 S
\R0                  5      rS r\S 5       rS r0 rS\S'   S\S'   S\S'   \S:X  a  \" 5         gg)z"Test suite for the profile module.    N)unified_diff)StringIO)TESTFNunlinktemp_dir
change_cwd)contextmanagerredirect_stdout)testfunctimer)assert_python_failureassert_python_okc                       \ rS rSr\R
                  r\r/ SQrSr	S r
S r\S 5       rS rS rS	 rS
 rS rS rS rSrg)ProfileTest   )print_statsprint_callersprint_calleesz:0(max)c                 "    [        [        5        g N)r   r   selfs    :/opt/python-3.13.8/usr/lib/python3.13/test/test_profile.pytearDownProfileTest.tearDown   s	    v    c                     [         $ r   )_ProfileOutputr   s    r   get_expected_outputProfileTest.get_expected_output   s    r   c                    / nU R                  [        S5      n[        5       nUR                  S[        5       [	        5       5        UR                  [        5       U-
  5        U R                   H  n[        5       n[        R                  " X%S9nUR                  5       R                  S5        [        Xd5      " 5         UR                  5       R                  5       n[        R                   R#                  SS5      S   nU V	s/ s H  oU	;   d  M
  U	R%                  5       PM     nn	UR                  SR'                  U5      5        M     U$ s  sn	f )NMbP?
testfunc()streamstdname.   
)profilerclassr   runctxglobalslocalsappendmethodnamesr   pstatsStats
strip_dirs
sort_statsgetattrgetvalue
splitlinesr   
__module__rsplitrstripjoin)
clsresultsprofstart_timer
methodnamesstatsoutputmod_namelines
             r   do_profilingProfileTest.do_profiling   s     .gL')VX6uw,-//J
ALL0E)))4E&(ZZ\,,.F**11#q9!<H 17Kd:JmdkkmFKNN499V,- *  Ls   	EEc           	         U R                  5       nU R                  5       nU R                  US   S5        / n[        U R                  5       H{  u  pEX%   nXS-      nXg:w  d  M  UR                  SU SU R                  R                   S35        UR                  [        UR                  S5      UR                  S5      SS	95        M}     U(       a!  U R                  SR                  U5      5        g g )
Nr   i  r(   z
Stats.z output for z does not fit expectation:r)    )lineterm)rE   r   assertEqual	enumerater/   r.   r*   __name__extendr   splitfailr:   )r   r<   expectedrO   imethodabs           r   test_cprofileProfileTest.test_cprofile3   s    ##%++-T*"4#3#34IA A!Avhvhl#11::; <99 : L%') * 5 IIdiio& r   c           	      d   / SQnU H  n[        5       nU R                  [        S5      nUR                  U[	        5       [        5       5        [        R                  " XCS9nUR                  5         UR                  5       nU R                  U R                  USR                  X&5      5        M     g )N)zmax([0])zmax([0], key=int)zmax([0], **dict(key=int))zmax(*([0],))zmax(*([0],), key=int)zmax(*([0],), **dict(key=int))r"   r$   z&Profiling {0!r} didn't report max:
{1})r   r*   r   r+   r,   r-   r0   r1   r   r5   assertInexpected_max_outputformat)r   stmtsstmtr@   r=   rA   ress          r   test_calling_conventions$ProfileTest.test_calling_conventionsD   s    
 D
A%%eU3DKKgi2LL0E**,CMM$22C9@@KM r   c                 "   [        5          U R                  R                  S5        S S S 5        U R                  R                  S[        S9  U R	                  [
        R                  R                  [        5      5        g ! , (       d  f       N_= f)Nint('1')filename)silentprofilermodulerunr   
assertTrueospathexistsr   s    r   test_runProfileTest.test_runY   sZ    X##J/ 
V<v./ Xs   B  
Bc                     [        [        5       5       nU R                  R                  SSS9  S S S 5        U R	                  SWR                  5       5        g ! , (       d  f       N/= f)Nra   )tottimer&   )sortz(Ordered by: internal time, standard name)r
   r   re   rf   rX   r5   )r   fs     r   test_run_with_sort_by_values(ProfileTest.test_run_with_sort_by_values_   sK    XZ(A##J5K#L )@!**,O )(s   A
A&c                 j   [        5          U R                  R                  S[        5       [	        5       5        S S S 5        U R                  R                  S[        5       [	        5       [
        S9  U R                  [        R                  R                  [
        5      5        g ! , (       d  f       Nq= f)Nr#   rb   )
rd   re   r+   r,   r-   r   rg   rh   ri   rj   r   s    r   test_runctxProfileTest.test_runctxd   so    X&&|WYI ""<FH+1 	# 	3v./	 Xs   .B$$
B2c                     [        SU R                  R                  S5        [        SU R                  R                  SS5        [        SU R                  R                  SSSS5        g )N-mrandom_module_xyztimeitz-n1)r   re   rL   r   r   s    r   test_run_profile_as_module&ProfileTest.test_run_profile_as_modulek   s]    dD$7$7$@$@$G 	dD$7$7$@$@"$7	9 	t22;;xs	4r   c           	         [        5        n[        U5         [        R                  " S5        [	        SSSS9 nUR                  S5        S S S 5        [        SU R                  R                  SS	S5        U R                  [        R                  R                  S	5      5        S S S 5        S S S 5        g ! , (       d  f       Np= f! , (       d  f       N(= f! , (       d  f       g = f)
Ndestzdemo.pywzutf-8)encodingzimport os; os.chdir("dest")rw   z-oz
out.pstats)r   r   rh   mkdiropenwriter   re   rL   rg   ri   rj   )r   tmpdirrp   s      r   (test_output_file_when_changing_directory4ProfileTest.test_output_file_when_changing_directoryw   s    Z6:f#5HHViw7156 8 d))22l OOBGGNN<89 $6ZZ77 $6#5ZZs:   C"CB5AC$C5
C?C
C	C
C% N)rL   r7   __qualname____firstlineno__profileProfiler*   re   r/   rY   r   r   classmethodrE   rU   r^   rk   rq   rt   r{   r   __static_attributes__r   r   r   r   r      s^    OOMNCK#  ('"M*0P
0
4:r   r   c           
      B   U R                  S5      n [        SU -  5        UR                  5       n/ n[        U S5       nU H,  nUR	                  U5        UR                  S5      (       d  M,    O   S S S 5        [        U S5       nUR                  U5        UR                  S5        [        UR                  5       H$  u  pgUR                  SU< SX&S	-      < S
35        M&     UR                  S5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)NcozRegenerating %s...rz#--cutr   z_ProfileOutput = {}
z_ProfileOutput[z	] = """\
r(   z"""
z'
if __name__ == "__main__":
    main()
)
r9   printrE   r   r.   
startswith
writelinesr   rK   r/   )rc   r;   r<   newfilerp   rD   rQ   rR   s           r   regenerate_expected_outputr      s    t$H	

)* GG	h	DNN4 x((  
 
h		W	'("3??3IAGGGaCL* + 4 	
<= 
	 
	 
	s   +C?-C?A1D?
D
Dc               #      #    [         R                  n  [        5       [         l        S v   U [         l        g ! U [         l        f = f7fr   )sysstdoutr   )r   s    r   rd   rd      s-     ZZFZ

V
s   A7 AAAc                      S[         R                  ;  a  [        R                  " 5         g [	        [
        [        5        g )Nz-r)r   argvunittestmainr   __file__r   r   r   r   r   r      s!    388"8[9r   a         28   27.972    0.999   27.972    0.999 profilee.py:110(__getattr__)
        1  269.996  269.996  999.769  999.769 profilee.py:25(testfunc)
     23/3  149.937    6.519  169.917   56.639 profilee.py:35(factorial)
       20   19.980    0.999   19.980    0.999 profilee.py:48(mul)
        2   39.986   19.993  599.830  299.915 profilee.py:55(helper)
        4  115.984   28.996  119.964   29.991 profilee.py:73(helper1)
        2   -0.006   -0.003  139.946   69.973 profilee.py:84(helper2_indirect)
        8  311.976   38.997  399.912   49.989 profilee.py:88(helper2)
        8   63.976    7.997   79.960    9.995 profilee.py:98(subhelper)r   a  :0(append)                        <- profilee.py:73(helper1)(4)  119.964
:0(exception)                     <- profilee.py:73(helper1)(4)  119.964
:0(hasattr)                       <- profilee.py:73(helper1)(4)  119.964
                                     profilee.py:88(helper2)(8)  399.912
profilee.py:110(__getattr__)      <- :0(hasattr)(12)   11.964
                                     profilee.py:98(subhelper)(16)   79.960
profilee.py:25(testfunc)          <- <string>:1(<module>)(1)  999.767
profilee.py:35(factorial)         <- profilee.py:25(testfunc)(1)  999.769
                                     profilee.py:35(factorial)(20)  169.917
                                     profilee.py:84(helper2_indirect)(2)  139.946
profilee.py:48(mul)               <- profilee.py:35(factorial)(20)  169.917
profilee.py:55(helper)            <- profilee.py:25(testfunc)(2)  999.769
profilee.py:73(helper1)           <- profilee.py:55(helper)(4)  599.830
profilee.py:84(helper2_indirect)  <- profilee.py:55(helper)(2)  599.830
profilee.py:88(helper2)           <- profilee.py:55(helper)(6)  599.830
                                     profilee.py:84(helper2_indirect)(2)  139.946
profilee.py:98(subhelper)         <- profilee.py:88(helper2)(8)  399.912r   a  :0(hasattr)                       -> profilee.py:110(__getattr__)(12)   27.972
<string>:1(<module>)              -> profilee.py:25(testfunc)(1)  999.769
profilee.py:110(__getattr__)      ->
profilee.py:25(testfunc)          -> profilee.py:35(factorial)(1)  169.917
                                     profilee.py:55(helper)(2)  599.830
profilee.py:35(factorial)         -> profilee.py:35(factorial)(20)  169.917
                                     profilee.py:48(mul)(20)   19.980
profilee.py:48(mul)               ->
profilee.py:55(helper)            -> profilee.py:73(helper1)(4)  119.964
                                     profilee.py:84(helper2_indirect)(2)  139.946
                                     profilee.py:88(helper2)(6)  399.912
profilee.py:73(helper1)           -> :0(append)(4)   -0.004
profilee.py:84(helper2_indirect)  -> profilee.py:35(factorial)(2)  169.917
                                     profilee.py:88(helper2)(2)  399.912
profilee.py:88(helper2)           -> :0(hasattr)(8)   11.964
                                     profilee.py:98(subhelper)(8)   79.960
profilee.py:98(subhelper)         -> profilee.py:110(__getattr__)(16)   27.972r   __main__)__doc__r   r0   r   rh   difflibr   ior   test.support.os_helperr   r   r   r   
contextlibr	   r
   r   test.profileer   r   test.support.script_helperr   r   TestCaser   r   rd   r   r   rL   r   r   r   <module>r      s    ( 
   	    G G 6  ) Nr:(## r:j>(  : 	!K} #L $#R & zF r   