eaiovnaovbqoebvqoeavibavo B YI~dp@sddgZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m ZddlZdZGdddZdd Zd d ZGd ddZd dZddZdddZddZGdddZddZedkredS)TraceCoverageResultsN) monotonicz#pragma NO COVERc@seZdZdddZddZdS)_IgnoreNcCs:|s tnt||_|sgn dd|D|_ddi|_dS)NcSsg|]}tj|qS)ospathnormpath).0drr*/opt/alt/python37/lib64/python3.7/trace.py Hsz$_Ignore.__init__..z)set_mods_dirs_ignore)selfmodulesdirsrrr __init__Fs z_Ignore.__init__cCs||jkr|j|S||jkr,d|j|<dSx*|jD] }||dr4d|j|<dSq4W|dkrnd|j|<dSx,|jD]"}||tjrvd|j|<dSqvWd|j|<dS)Nr.r)rr startswithrrsep)rfilename modulenamemodr rrr namesLs$          z _Ignore.names)NN)__name__ __module__ __qualname__rrrrrr rEs rcCs tj|}tj|\}}|S)N)rrbasenamesplitext)rbaserextrrr _modnamews r%cCstj|}d}xJtjD]@}tj|}||r|t|tjkrt|t|kr|}qW|rv|t|dd}n|}tj|\}}|tjd}tj r|tj d}tj |\}}| dS)Nrr) rrnormcasesysrlenr splitdrivereplacealtsepr"lstrip)rZ comparepathZlongestdirr#Zdriverr$rrr _fullmodname~s    r/c@s:eZdZdddZddZddZdd d Zdd d ZdS)rNc Cs||_|jdkri|_|j|_||_|jdkr8i|_|j|_||_|jdkrZi|_|j|_||_||_|jry@t|jd}t |\}}}WdQRX| | |||Wn@t t tfk r}ztd|j|ftjdWdd}~XYnXdS)NrbzSkipping counts file %r: %s)file)countscopyZcounter calledfuncscallersinfileoutfileopenpickleloadupdate __class__OSErrorEOFError ValueErrorprintr(stderr)rr2r4r6r5r7ferrrrr rs,      zCoverageResults.__init__cCs|do|dS)N<>)rendswith)rrrrr is_ignored_filenamesz#CoverageResults.is_ignored_filenamec Csz|j}|j}|j}|j}|j}|j}x$|D]}||d||||<q*Wx|D] }d||<qPWx|D] }d||<qfWdS)Nrr)r2r4r5get) rotherr2r4r5Z other_countsZother_calledfuncsZ other_callerskeyrrr r;s    zCoverageResults.updateTFc! Cs|jrDttd|j}x(t|D]\}}}td|||fq$W|jrttdd}} xvt|jD]h\\} } } \} }}| |krttd| d| }d} | | kr| | krtd| | } td| | ||fqlWi}x8|jD].\}}||i}||<|j||f||<qWi}x$|D]\}}||r@q&|drX|dd }|dkrt j t j |}t |}n$|}t j |st |t|}|rt|}ni}t|}t j ||d }t|d }t|j\}}WdQRX||||||\}}|r&|r&td ||}||||f||<q&W|r|rtd x2t|D]&}||\}}}}td||q`W|jry&t|j|j|jft|jddWn6tk r} ztd| tj dWdd} ~ XYnXdS)Nzfunctions called:z*filename: %s, modulename: %s, funcname: %szcalling relationships:r&z***z -->z %s.%s -> %s.%sz.pycz.coverr0dzlines cov% module (path)z%5d %3d%% %s (%s)wbrz"Can't save counts files because %s)r1)!r4r@sortedr5r2rHitemsrGrFrrdirnameabspathr%existsmakedirsr/_find_executable_linenos linecachegetlinesjoinr8tokenizedetect_encodingreadlinewrite_results_fileintr7r9dumpr=r(rA)!rZ show_missingsummarycoverdirZcallsrrfuncnameZlastfileZ lastcfileZpfileZpmodZpfunccfileZcmodZcfuncZper_filelineno lines_hitZsumscountr.lnotabsourceZ coverpathfpencoding_n_hitsn_linespercentmrCrrr write_resultss|              zCoverageResults.write_resultsc Csyt|d|d}Wn8tk rJ}ztd||ftjddSd}~XYnXd}d} |xt|dD]r\} } | |kr|d|| | d7} |d7}n.| |krt| kr|d |d7}n |d || d qfWWdQRX| |fS) Nw)rhz3trace: Could not open %r for writing: %s - skipping)r1)rrrrz%5d: z>>>>>> z ) r8r=r@r(rA enumeratewritePRAGMA_NOCOVER expandtabs) rrlinesrercrhr7rCrkrjrblinerrr r[(s(    z"CoverageResults.write_results_file)NNNNN)TFN)N)rrr rrGr;rnr[rrrr rs   [cCs0i}x&t|D]\}}||krd||<qW|S)Nr)disZfindlinestarts)codestrslinenosrirbrrr _find_lines_from_codeHs  r{cCs8t||}x(|jD]}t|r|t||qW|S)N)r{ co_constsinspectZiscoder; _find_lines)rxryrzcrrr r~Rs    r~c Csi}tj}t||dr}t|j}x^|D]V\}}}} } |tjkr||tjkr||\} } | \} }xt| | dD] }d||<qlW|}q*WWdQRX|S)N)rhr)tokenINDENTr8rXgenerate_tokensrZSTRINGrange)rrhr Z prev_ttyperBtokZttypeZtstrstartendrvZslineZscolZelineZecolirrr _find_strings^s    rc Csy(t|}|}|j}WdQRXWn8tk r`}ztd||ftjdiSd}~XYnXt||d}t ||}t ||S)Nz%Not printing coverage data for %r: %s)r1exec) rXr8readrhr=r@r(rAcompilerr~)rrBprogrhrCrxryrrr rTus   rTc @speZdZdddZdd Zdd d Zd d ZddZddZddZ ddZ ddZ ddZ ddZ ddZdS) rrrrNFc Cs||_||_t|||_i|_i|_d|_||_i|_i|_ i|_ d|_ | rTt |_ |rb|j |_nZ|rp|j|_nL|r|r|j|_|j|_n2|r|j|_|j|_n|r|j|_|j|_nd|_dS)Nrr)r6r7rignorer2Zpathtobasename donothingtrace _calledfuncs_callers _caller_cache start_time_timeglobaltrace_trackcallers globaltraceglobaltrace_countfuncsglobaltrace_ltlocaltrace_trace_and_count localtracelocaltrace_tracelocaltrace_count) rrdr countfuncs countcallers ignoremods ignoredirsr6r7timingrrr rs6      zTrace.__init__cCs ddl}|j}||||dS)Nr)__main____dict__runctx)rcmdrdictrrr runsz Trace.runc Csh|dkr i}|dkri}|js6t|jt|jzt|||Wd|jsbtdtdXdS)N)r threadingsettracerr(r)rrglobalslocalsrrr rs   z Trace.runctxc Ost|dkr|^}}}n>|s&tdn0d|krB|d}|^}}ntdt|dd}|jslt|jz|||}Wd|jstdX|S)Nz8descriptor 'runfunc' of 'Trace' object needs an argumentfuncz7runfunc expected at least 1 positional argument, got %dr)r) TypeErrorpoprr(rr)argskwrrresultrrr runfuncs"       z Trace.runfuncc Cs|j}|j}|rt|}nd}|j}d}||jkrL|j|dk r|j|}nd|j|<ddt|D}t|dkrddt|dD}t|dkrddt|dD} t| dkr| dj}||j|<|dk rd||f}|||fS)NcSsg|]}t|r|qSr)r}Z isfunction)r rBrrr r sz1Trace.file_module_function_of..rcSsg|]}t|tr|qSr) isinstancer)r r rrr r srcSsg|]}t|dr|qS) __bases__)hasattr)r rrrr r sz%s.%s) f_code co_filenamer%co_namergcZ get_referrersr)r) rframerxrrr`ZclsnameZfuncsZdictsclassesrrr file_module_function_ofs,          zTrace.file_module_function_ofcCs0|dkr,||}||j}d|j||f<dS)Ncallr)rf_backr)rrwhyarg this_funcZ parent_funcrrr rs  zTrace.globaltrace_trackcallerscCs |dkr||}d|j|<dS)Nrr)rr)rrrrrrrr rs zTrace.globaltrace_countfuncscCsj|dkrf|j}|jdd}|rbt|}|dk rf|j||}|sf|jrZtd||jf|j SndSdS)Nr__file__z! --- modulename: %s, funcname: %s) r f_globalsrHr%rrrr@rr)rrrrrxrrZ ignore_itrrr rszTrace.globaltrace_ltcCs|dkr~|jj}|j}||f}|j|dd|j|<|jrTtdt|jddtj |}td||t ||fdd|j S) Nrvrrz%.2f )rz %s(%d): %sr&)rrf_linenor2rHrr@rrrr!rUgetliner)rrrrrrbrJbnamerrr r3s z Trace.localtrace_trace_and_countcCsd|dkr^|jj}|j}|jr4tdt|jddtj|}td||t ||fdd|j S)Nrvz%.2fr)rz %s(%d): %sr&) rrrrr@rrrr!rUrr)rrrrrrbrrrr rBs zTrace.localtrace_tracecCs<|dkr6|jj}|j}||f}|j|dd|j|<|jS)Nrvrr)rrrr2rHr)rrrrrrbrJrrr rOs zTrace.localtrace_countcCst|j|j|j|j|jdS)N)r6r7r4r5)rr2r6r7rr)rrrr resultsWs z Trace.results) rrrrrrNNF)NN)rrr rrrrrrrrrrrrrrrr rs 0 )   c stddl}|}|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|jd5d6d7d8|jd9|jd:d8|}|jrvt d;t d<fd=d>d?d@|j D|_ fdAd@|jD|_|j r|j s| dBt|j |j dC}||j|j|jSt|j|j|j|jgs| dD|jr0|js&|jr0| dE|jrJ|jsJ| dF|jdkr`| dG|jf|jt_tj|jtjd<t|j|j|j|j|j |j|j |j |j dH }yJt!|j}t"|#|jdI}WdQRX|jdJdddK} |$|| | WnPt%k r6} zt&dLtjd| fWdd} ~ XYnt'k rJYnX|(}|j)sp||j|j|jdS)MNrz --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).r?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_dirszmain..parse_ignore_dircSs$g|]}|dD] }|qqS),)splitstrip)r rrrrr r szmain..cs&g|]}|tjD] }|qqSr)rrpathsep)r rr)rrr r sz-r/--report requires -f/--file)r6r7zLmust 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 --reportz3filename is missing: required with the main options)rrrrr6r7rrr)rr __package__ __cached__zCannot run file %r because: %s)*argparseArgumentParser add_argumentadd_argument_groupadd_mutually_exclusive_group REMAINDER parse_argsZ ignore_dir sysconfigZget_pathZ ignore_moduleZreportr1errorrrnmissingr^r_anyrrdZ listfuncsZ trackcallsrrr(argvrrrPrrr8rrrr=exit SystemExitrZ no_report) rparserZgrpZ_grpZoptsrtrgrxZglobsrCr)rrrr main]s                         (rr)N)__all__rUrrer(rrrXr}rrwr9Ztimerrrrsrr%r/rr{r~rrTrrrrrrr 2s: 2/  [