o ?Og-r@s ddgZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m ZddlZdZGdddZdd Zd d ZGd ddZd dZddZdddZddZGdddZddZedkrxedSdS)TraceCoverageResultsN) monotonicz#pragma NO COVERc@seZdZdddZddZdS)_IgnoreNcCs:|stnt||_|sgndd|D|_ddi|_dS)NcSsg|]}tj|qS)ospathnormpath.0drr,/opt/alt/python310/lib64/python3.10/trace.py Hsz$_Ignore.__init__..z)set_mods_dirs_ignore)selfmodulesdirsrrr __init__Fs z_Ignore.__init__cCs||jvr |j|S||jvrd|j|<dS|jD]}||dr*d|j|<dSq|dur6d|j|<dS|jD]}||tjrKd|j|<dSq9d|j|<dS)Nr.r)rr startswithrrsep)rfilename modulenamemodr rrr namesLs(          z _Ignore.namesNN)__name__ __module__ __qualname__rrrrrr rEs  rcCs" tj|}tj|\}}|SN)rrbasenamesplitext)rbaserextrrr _modnamews r(cCs tj|}d}tjD] }tj|}||r,|t|tjkr,t|t|kr,|}q |r:|t|dd}n|}tj|\}}|tjd}tj rU|tj d}tj |\}}| dS)Nrr) rrnormcasesysrlenr splitdrivereplacealtsepr%lstrip)rZ comparepathZlongestdirr&Zdriverr'rrr _fullmodname~s$    r2c@s>eZdZ  dddZddZddZdd d Zdd d ZdS)rNc Cs||_|jdur i|_|j|_||_|jduri|_|j|_||_|jdur-i|_|j|_||_||_|jrz,t|jd}t |\}}}Wdn1sVwY| |j |||dWdSt t tfy}ztd|j|ftjdWYd}~dSd}~wwdS)Nrb)callerszSkipping counts file %r: %sfile)countscopyZcounter calledfuncsr4infileoutfileopenpickleloadupdate __class__OSErrorEOFError ValueErrorprintr+stderr)rr7r9r:r4r;ferrrrr rs:      zCoverageResults.__init__cCs |do |dS)N<>)rendswith)rrrrr is_ignored_filenamesz#CoverageResults.is_ignored_filenamec Csp |j}|j}|j}|j}|j}|j}|D]}||d||||<q|D]}d||<q&|D]}d||<q/dSNrr)r7r9r4get) rotherr7r9r4Z other_countsZother_calledfuncsZ other_callerskeyrrr r?s  zCoverageResults.updateTFc" Cs |jr!ttd|j}t|D]\}}}td|||fq|jrittdd}} t|jD]4\\} } } \} }}| |krOttd| d| }d} | | kr^| | kr^td| | } td| | ||fq4i}|jD]\}}||i}||<|j||f||<qni}|D]\}}||rq|dr|dd }|durt j t j |}t |}n|}t j |st |t|}|rt|}ni}t|}t j ||d }t|d }t|j\}}Wdn1swY||||||\}}|r|rtd ||}||||f||<q|r=|r=td t|D]}||\}}}}td||q)|jrz)t|jd} t|j|j|jf| dWdWdS1scwYWdSty}!ztd|!tj dWYd}!~!dSd}!~!wwdS)Nzfunctions called:z*filename: %s, modulename: %s, funcname: %szcalling relationships:r)z***z -->z %s.%s -> %s.%sz.pycz.coverr3dzlines cov% module (path)z%5d %3d%% %s (%s)wbrz"Can't save counts files because %sr5)!r9rDsortedr4r7rMitemsrKrJrrdirnameabspathr(existsmakedirsr2_find_executable_linenos linecachegetlinesjoinr<tokenizedetect_encodingreadlinewrite_results_fileintr;r=dumprAr+rE)"rZ show_missingsummarycoverdirZcallsrrfuncnameZlastfileZ lastcfileZpfileZpmodZpfunccfileZcmodZcfuncZper_filelineno lines_hitZsumscountr1lnotabsourceZ coverpathfpencoding_n_hitsn_linesZpercentmrFrGrrr write_resultss               ( zCoverageResults.write_resultsc Cs  z t|d|d}Wnty(}ztd||ftjdWYd}~dSd}~wwd}d} |Jt|dD]9\} } | |vrO|d|| | d7} |d7}n| |vrat| vra|d |d7}n|d || d q5Wd| |fS1s|wY| |fS) Nwrmz3trace: Could not open %r for writing: %s - skippingr5)rrrrz%5d: z>>>>>> z ) r<rArDr+rE enumeratewritePRAGMA_NOCOVER expandtabs) rrlinesrjrhrmr;rGrprorglinerrr r`)s<     z"CoverageResults.write_results_file)NNNNN)TFNr#)r r!r"rrKr?rrr`rrrr rs  \cCs. i}t|D] \}}||vrd||<q|S)Nr)disZfindlinestarts)codestrslinenosrnrgrrr _find_lines_from_codeIsrcCs6 t||}|jD]}t|r|t||q |Sr#)r co_constsinspectZiscoder? _find_lines)r}r~rcrrr rSs   rcCs i}tj}t||d;}t|j}|D])\}}}} } |tjkr<|tjkr<|\} } | \} }t| | dD]}d||<q5|}qWd|S1sJwY|S)Nrtr)tokenINDENTr<r]generate_tokensr_STRINGrange)rrmr Z prev_ttyperFtokZttypeZtstrstartendr{ZslineZscolZelineZecolirrr _find_strings_s$       rc Cs zt|}|}|j}Wdn1swYWnty>}ztd||ftjdiWYd}~Sd}~wwt||d}t ||}t ||S)Nz%Not printing coverage data for %r: %sr5exec) r]r<readrmrArDr+rEcompilerr)rrFprogrmrGr}r~rrr rYvs&    rYc@sveZdZ   dddZdd Zdd d Zd d ZddZddZddZ ddZ ddZ ddZ ddZ ddZdS) rrrrNFc Cs ||_||_t|||_i|_i|_d|_||_i|_i|_ i|_ d|_ | r+t |_ |r3|j |_dS|r;|j|_dS|rI|rI|j|_|j|_dS|rU|j|_|j|_dS|ra|j|_|j|_dSd|_dSrL)r:r;rignorer7Zpathtobasename donothingtrace _calledfuncs_callers _caller_cache start_time_timeglobaltrace_trackcallers globaltraceglobaltrace_countfuncsglobaltrace_ltlocaltrace_trace_and_count localtracelocaltrace_tracelocaltrace_count) rrir countfuncs countcallers ignoremods ignoredirsr:r;timingrrr rs8       zTrace.__init__cCs ddl}|j}||||dS)Nr)__main____dict__runctx)rcmdrdictrrr runsz Trace.runc Cs|duri}|dur i}|jst|jt|jzt|||W|js2tdtddSdS|jsBtdtdwwr#)r threadingsettracerr+r)rrglobalslocalsrrr rs       z Trace.runctxc OsPd}|js t|jz||i|}W|jstd|S|js'tdwwr#)rr+rr)rfuncargskwresultrrr runfuncs   z Trace.runfuncc Cs|j}|j}|r t|}nd}|j}d}||jvr&|j|dur%|j|}nCd|j|<ddt|D}t|dkriddt|dD}t|dkriddt|dD} t| dkri| dj}||j|<|dursd||f}|||fS)NcSsg|] }t|r|qSr)rZ isfunction)r rFrrr r z1Trace.file_module_function_of..rcSsg|] }t|tr|qSr) isinstancerr rrr rrrcSsg|] }t|dr|qS) __bases__)hasattr)r rrrr rrz%s.%s) f_code co_filenamer(co_namergcZ get_referrersr,r ) rframer}rrreZclsnameZfuncsZdictsZclassesrrr file_module_function_ofs.           zTrace.file_module_function_ofcCs6 |dkr||}||j}d|j||f<dSdSNcallr)rf_backr)rrwhyarg this_funcZ parent_funcrrr rs   zTrace.globaltrace_trackcallerscCs& |dkr||}d|j|<dSdSr)rr)rrrrrrrr rs  zTrace.globaltrace_countfuncscCsr |dkr7|j}|jdd}|r5t|}|dur1|j||}|s3|jr.td||jf|j SdSdSdSdS)Nr__file__z! --- modulename: %s, funcname: %s) r f_globalsrMr(rrrrDrr)rrrrr}rrZ ignore_itrrr rs$zTrace.globaltrace_ltcCs|dkr?|jj}|j}||f}|j|dd|j|<|jr*tdt|jddtj |}td||t ||fdd|j S) Nr{rr%.2f r %s(%d): %sr))rrf_linenor7rMrrDrrrr$rZgetliner)rrrrrrgrObnamerrr r(s  z Trace.localtrace_trace_and_countcCsd|dkr/|jj}|j}|jrtdt|jddtj|}td||t ||fdd|j S)Nr{rrrrr)) rrrrrDrrrr$rZrr)rrrrrrgrrrr r7s  zTrace.localtrace_tracecCs<|dkr|jj}|j}||f}|j|dd|j|<|jS)Nr{rr)rrrr7rMr)rrrrrrgrOrrr rDs zTrace.localtrace_countcCst|j|j|j|j|jdS)N)r:r;r9r4)rr7r:r;rr)rrrr resultsLs z Trace.results) rrrrrrNNFr)r r!r"rrrrrrrrrrrrrrrr rs  2   )   c sddl}|}|jdddd|dd}|jdd d d d |jd dd dd |jddd dd |jddd dd |d}|}|jddd dd |jddd dd |jdddd |jd!d"d#d |jd$d%d d&d |jd'd(d d)d |jd*d+d d,d |d-d.}|jd/d0gd1d2|jd3d0gd4d2|jd5d d6d7d2|jd8d9d:d;|jd<|jd=d;|}|jrt d>t d?fd@dAdBdC|j D|_ fdDdC|jD|_|j r|j s| dEt|j |j dF}||j|j|jSt|j|j|j|jgs | dG|jr|js|jr| dH|jr+|js+| dI|jdur6| dJt|j|j|j|j|j |j|j |j |jdK }zk|jruddl}|j}||\} } } | jg|jt _!dL| j| j"| j#| ddM} n:|jg|jt _!t$j%&|jt j%d<t'(|j} t)| *|jdN} Wdn 1swY|jdLdddO} |+| | | Wn(t,y}zt -dPt j!d|fWYd}~nd}~wt.yYnw|/}|j0s||j|j|jdSdS)QNrz --versionversionz trace 2.0)actionrz Main optionsz(One of these (or --report) must be givenz-cz--count store_truezCount the number of times each line is executed and write the counts to .cover for each module executed, in the module's directory. See also --coverdir, --file, --no-report below.)rhelpz-tz--tracez3Print each line to sys.stdout before it is executedz-lz --listfuncszKeep track of which functions are executed at least once and write the results to sys.stdout after the program exits. Cannot be specified alongside --trace or --count.z-Tz --trackcallsz^Keep track of caller/called pairs and write the results to sys.stdout after the program exits.Z Modifiersz-rz--reportzGenerate a report from a counts file; does not execute any code. --file must specify the results file to read, which must have been created in a previous run with --count --file=FILEz-Rz --no-reportz^Do not generate the coverage report files. Useful if you want to accumulate over several runs.z-fz--filez+File to accumulate counts over several runs)rz-Cz --coverdirzDirectory where the report files go. The coverage report for . will be written to file //.coverz-mz --missingz?Annotate executable lines that were not executed with ">>>>>> "z-sz --summaryz\Write a brief summary for each file to sys.stdout. Can only be used with --count or --reportz-gz--timingzQPrefix each line with the time since the program started. Only used while tracingZFilterszCan be specified multiple timesz--ignore-moduleappendzqIgnore the given module(s) and its submodules (if it is a package). Accepts comma separated list of module names.)rdefaultrz --ignore-dirzWIgnore files in the given directory (multiple directories can be joined by os.pathsep).z--moduleFzTrace a module. progname?zfile to run as main program)nargsr argumentszarguments to the programZstdlibZ platstdlibcs4tjtj|}|dd}tj|S)Nz$prefixz $exec_prefix)rr expanduser expandvarsr.r )s) _exec_prefix_prefixrr parse_ignore_dirs zmain..parse_ignore_dircSs$g|]}|dD]}|q qS),)splitstrip)r rrrrr rs  zmain..cs&g|]}|tjD]}|q qSr)rrpathsep)r rr)rrr rs  z-r/--report requires -f/--file)r:r;zLmust specify one of --trace, --count, --report, --listfuncs, or --trackcallsz8cannot specify both --listfuncs and (--trace or --count)z3--summary can only be used with --count or --reportz3progname is missing: required with the main options)rrrrr:r;rr)r r __package__ __loader____spec__ __cached__r)rr rrzCannot run file %r because: %s)1argparseArgumentParser add_argumentZadd_argument_groupZadd_mutually_exclusive_groupZ REMAINDER parse_argsZ ignore_dir sysconfigZget_pathZ ignore_moduleZreportr6errorrrrZmissingrcrdanyrriZ listfuncsZ trackcallsrrrmodulerunpyZ_get_module_detailsrrr+argvparentloaderrrrUio open_coderrrrAexit SystemExitrZ no_report)rparserZgrpZ_grpZoptsrtrZ module_nameZmod_nameZmod_specr}ZglobsrlrGr)rrrr mainRs                        $rrr#)__all__rrZrr+rrr]rrr|r=timerrrrxrr(r2rrrrrYrrr rrrr s@ 20 O