a 5dg"@sdZddlZddlZddlZddlZddlmZddlmZddl m Z m Z m Z m Z mZddlmZddlZddlmZmZddlmZmZGd d d ejZd d Zed dZddZddZiZded<ded<ded<edkredS)z"Test suite for the profile module.N) unified_diff)StringIO)TESTFN run_unittestunlinktemp_dir change_cwd)contextmanager)testfunctimer)assert_python_failureassert_python_okc@sneZdZejZeZgdZdZddZ ddZ e ddZ d d Z d d Zd dZddZddZddZdS) ProfileTest) print_stats print_callers print_calleesz:0(max)cCs ttdSN)rrselfr-/usr/local/lib/python3.9/test/test_profile.pytearDownszProfileTest.tearDowncCstSr)_ProfileOutputrrrrget_expected_outputszProfileTest.get_expected_outputcsg}|td}t}|dtt|t||jD]r}t}tj ||d}| dt ||| }tjdddfdd|D}|d |q>|S) NMbP? testfunc()streamZstdname.csg|]}|vr|qSr)rstrip).0lineZmod_namerr /z,ProfileTest.do_profiling.. ) profilerclassr runctxglobalslocalsappend methodnamesrpstatsStatsZ strip_dirsZ sort_statsgetattrgetvalue splitlinesr __module__rsplitjoin)clsresultsprofZ start_timerZ methodnamesstatsoutputrr#r do_profilings    zProfileTest.do_profilingcCs|}|}||ddg}t|jD]`\}}||}||d}||kr.|d|d|jjd|t | d| ddd q.|r| d |dS) Nrirz Stats.z output for z does not fit expectation:r&)Zlineterm) r;rZ assertEqual enumerater,r+r'__name__extendrsplitfailr4)rr6ZexpectedrAimethodabrrr test_cprofile3s     zProfileTest.test_cprofilec Cspgd}|D]^}t}|td}||tttj||d}|| }| |j |d ||q dS)N)zmax([0])zmax([0], key=int)zmax([0], **dict(key=int))z max(*([0],))zmax(*([0],), key=int)zmax(*([0],), **dict(key=int))rrz&Profiling {0!r} didn't report max: {1}) rr'r r(r)r*r-r.rr0ZassertInexpected_max_outputformat)rZstmtsZstmtr8r7r9resrrrtest_calling_conventionsDs   z$ProfileTest.test_calling_conventionscCsXt|jdWdn1s(0Y|jjdtd|tjtdS)Nzint('1')filename)silentprofilermodulerunr assertTrueospathexistsrrrrtest_runYs*zProfileTest.test_runcCsht$|jdttWdn1s00Y|jjdtttd|tj tdS)NrrK) rMrNr(r)r*rrPrQrRrSrrrr test_runctx_s 2zProfileTest.test_runctxcCs<td|jjdtd|jjddtd|jjdddddS)N-mZrandom_module_xyzZtimeitz-n1)r rNr>r rrrrtest_run_profile_as_modulefs  z&ProfileTest.test_run_profile_as_modulec Cst}t|ttdtdd}|dWdn1sF0Ytd|jjddd| tj dWdn1s0YWdn1s0YdS)Ndestzdemo.pywzimport os; os.chdir("dest")rVz-oz out.pstats) rrrQmkdiropenwriter rNr>rPrRrS)rZtmpdirfrrr(test_output_file_when_changing_directoryrs  (z4ProfileTest.test_output_file_when_changing_directoryN)r>r2 __qualname__profileZProfiler'rNr,rGrr classmethodr;rFrJrTrUrXr_rrrrrs  rc Cs|d}td||}g}t|d2}|D]}|||dr2qPq2Wdn1sd0Yt|d\}|||dt|j D]"\}}|d|||dfq|d Wdn1s0YdS) NcozRegenerating %s...rz#--cutrZz_ProfileOutput = {} z _ProfileOutput[%r] = """\ %s""" rz' if __name__ == "__main__": main() ) r printr;r\r+ startswith writelinesr]r=r,)rLr5r6newfiler^r"rBrCrrrregenerate_expected_outputs"     $    riccs,tj}ztt_dVW|t_n|t_0dSr)sysstdoutr)rkrrrrMs rMcCs ttdSr)rrrrrr test_mainsrlcCs dtjvrtn tttdS)Nz-r)rjargvrlri__file__rrrrrmains roa 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)ra:0(append) <- profilee.py:73(helper1)(4) 119.964 :0(exc_info) <- 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) <- :1()(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.912ra:0(hasattr) -> profilee.py:110(__getattr__)(12) 27.972 :1() -> 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__rjr-ZunittestrQZdifflibriorZ test.supportrrrrr contextlibr raZ test.profileer r Ztest.support.script_helperr r ZTestCaserrirMrlrorr>rrrrs.   p