dZddlmZddlZddlmZmZmZmZm Z m Z m Z ddl m Z ddlmZddlmZddlmZmZe r dd lmZdd lmZGd d ZGd de Zd dZ d!d"dZd#dZdS)$z Results of coverage measurement.) annotationsN)CallableDictIterableListOptionalTuple TYPE_CHECKING) AutoReprMixin) ConfigError nice_pair)TArcTLineNo) CoverageData) FileReportercteZdZdZd!d Zd"d#dZd$dZd%dZd%dZd%dZ d%dZ d&dZ d'dZ d(dZ d(dZd)dZd S)*Analysisz(The results of analyzing a FileReporter.datar precisionint file_reporterr file_mapperCallable[[str], str]returnNonec p|_|_|jj_j_j_jjpg}j|}|_jjz _ j rtj _ j_j_}}t'fd|D}t'd|D} n'g_ i_t+_dx}x}} t-|dt/jt/jt/j ||| _dS)Nc3NK|]\}}|jvt|V dSN)missinglen).0kvselfs /srv/buildsys-work-dir/castor/build_node/builder-2/WGSG1/unpkd_srcs/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/coverage/results.py z$Analysis.__init__..3s9$\$\!at|F[F[SVVF[F[F[F[$\$\c3:K|]\}}t|VdSr)r!)r"r#r$s r&r'z$Analysis.__init__..4s,$C$C!SVV$C$C$C$C$C$Cr(r)rn_files n_statements n_excluded n_missing n_branchesn_partial_branchesn_missing_branches)rrfilenamelines statementsexcluded_linesexcludedtranslate_linesexecutedr has_arcssortedarcs_arc_possibilities exit_countsno_branch_lines no_branch_total_branchesmissing_branch_arcssumitemssetNumbersr!numbers) r%rrrrr8r/mbar0r1s ` r&__init__zAnalysis.__init__s *# D$6$?@@ ,2244*99;; 9??4=117R%55h??  6 9     E&,T-?-D-D-F-F&G&GD ##1==??D !/??AADN--//J**,,C!$$\$\$\$\syy{{$\$\$\!\!\ !$$C$Csyy{{$C$C$C!C!C  &(D #!D  UUDNCD DJ D+.@T_--4=))$,''!11     r(Fbranchesboolstrc|r;|r'|}nd}t|j|j|S)zThe missing line numbers, formatted nicely. Returns a string like "1-2, 5-11, 13-14". If `branches` is true, includes the missing branch arcs also. N)r;)r9rArC format_linesr4r )r%rIr;s r&missing_formattedzAnalysis.missing_formattedFsX    ++--3355DDDDOT\EEEEr(c4|jS)z"Were arcs measured in this result?)rr9r%s r&r9zAnalysis.has_arcsUsy!!###r( List[TArc]c|jS)z.Returns a sorted list of the arcs in the code.)r<rPs r&arc_possibilitieszAnalysis.arc_possibilitiesYs &&r(c|j|jpg}|j|}t |S)z@Returns a sorted list of the arcs actually executed in the code.)rr;r2rtranslate_arcsr:)r%r8s r& arcs_executedzAnalysis.arcs_executed]sB9>>$-006B%44X>>hr(c}fd|D}t|S)z:Returns a sorted list of the un-executed arcs in the code.c3`K|](}|vr"|djvr|djv$|V)dSrr*N)r?r6)r"pr8r%s r&r'z(Analysis.arcs_missing..hs^  H$$!DN22!DM11 2111   r(rSrVr:)r%possibler r8s` @r& arcs_missingzAnalysis.arcs_missingdsa))++%%''         gr(c||}fd|D}t|S)zAReturns a sorted list of the executed arcs missing from the code.c3xK|]4}|vr.|d|dkr|ddks |ddk0|V5dSrY)r"er\s r&r'z,Analysis.arcs_unpredicted..ysc  H$$!! 1QqTAXX &.XXX   r(r[)r%r8 unpredictedr\s @r&arcs_unpredictedzAnalysis.arcs_unpredictedps]))++%%''        k"""r( List[TLineNo]cHd|jDS)zz*Analysis._branch_lines..s!IIIxr%uqyyyyyr()r=rCrPs r& _branch_lineszAnalysis._branch_liness%II4#3#9#9#;#;IIIIr(cbtd|jDS)z"How many total branches are there?c3&K|] }|dk|V dS)r*Nr`)r"rhs r&r'z+Analysis._total_branches..s&MMU519959999MMr()rBr=valuesrPs r&r@zAnalysis._total_branchess.MMd&6&=&=&?&?MMMMMMr(Dict[TLineNo, List[TLineNo]]c|}t|}tjt }|D]$\}}||vr|||%|S)zgReturn arcs that weren't executed from branch lines. Returns {l1:[l2a,l2b,...], ...} )r]rDrj collections defaultdictlistappend)r%r branch_linesrGrgl2s r&rAzAnalysis.missing_branch_arcssx ##%%4--//00 %d++ # #FB\!!Br""" r(c|}t|}tjt }|D]$\}}||vr|||%|S)zdReturn arcs that were executed from branch lines. Returns {l1:[l2a,l2b,...], ...} )rVrDrjrprqrrrs)r%r8rtebargrus r&executed_branch_arcszAnalysis.executed_branch_arcssx %%''4--//00 %d++ # #FB\!!Br""" r(Dict[TLineNo, Tuple[int, int]]c|}i}|D].}|j|}t||}|||z f||</|S)zGet stats about branches. Returns a dict mapping line numbers to a tuple: (total_exits, taken_exits). )rArjr=r!)r% missing_arcsstatslnumexitsr s r& branch_statszAnalysis.branch_statssm//11 &&(( 3 3D$T*E,t,--G %'/2E$KK r(N) rrrrrrrrrr)F)rIrJrrK)rrJ)rrQ)rrdrr)rrn)rry)__name__ __module__ __qualname____doc__rHrNr9rSrVr]rcrjr@rArxrr`r(r&rrs22+ + + + Z F F F F F$$$$''''        ####"JJJJNNNN              r(rceZdZdZ d d!dZd"dZed#dZed#dZed$dZ ed%dZ d&dZ d#dZ ed'dZ d(dZd)dZdS)*rEzThe numerical results of measuring coverage. This holds the basic statistics from `Analysis`, and is used to roll up statistics across files. rrrr+r,r-r.r/r0r1rrc d|cxkrdksnJ||_dd|zz |_d|jz |_||_||_||_||_||_||_||_ dS)Nr g?Y@) _precision_near0_near100r+r,r-r.r/r0r1) r%rr+r,r-r.r/r0r1s r&rHzNumbers.__init__sI""""""""""#B M)  +  ($"$"4"4r( List[int]cf|j|j|j|j|j|j|j|jgS)z:Return a list for __init__(*args) to recreate this object.)rr+r,r-r.r/r0r1rPs r& init_argszNumbers.init_argss4 O L$+T_dn OT4d6M  r(c |j|jz S)z*Returns the number of executed statements.)r,r.rPs r& n_executedzNumbers.n_executeds 4>11r(c |j|jz S)z(Returns the number of executed branches.)r/r1rPs r&n_executed_brancheszNumbers.n_executed_branchess!888r(floatcF|jdkr|j\}}d|z|z }nd}|S)z/Returns a single percentage value for coverage.rr)r, ratio_covered)r% numerator denominatorpc_covs r& pc_coveredzNumbers.pc_covereds:  q %)%7 "I{i';6FFF r(rKc6||jS)a Returns the percent covered, as a string, without a percent sign. Note that "0" is only returned when the value is truly zero, and "100" is only returned when the value is truly 100. Rounding can never result in either "0" or "100". )display_coveredrrPs r&pc_covered_strzNumbers.pc_covered_strs##DO444r(pccd|cxkr |jkr nn|j}n2|j|cxkrdkr nn|j}nt||j}d|j|fzS)zReturn a displayable total percentage, as a string. Note that "0" is only returned when the value is truly zero, and "100" is only returned when the value is truly 100. Rounding can never result in either "0" or "100". rdz%.*f)rrroundr)r%rs r&rzNumbers.display_covereds r    DK     BB ]R % % % %# % % % % %BBr4?++B"---r(c:d}|jdkr |d|jzz }|S)z/How many characters wide can pc_covered_str be?rr*)r)r%widths r& pc_str_widthzNumbers.pc_str_width s* ?Q   Q( (E r(Tuple[int, int]cF|j|jz}|j|jz}||fS)z:Return a numerator and denominator for the coverage ratio.)rrr,r/)r%rrs r&rzNumbers.ratio_covereds-Od&>> '$/9 +%%r(othercHt|j}|j|jz|_|j|jz|_|j|jz|_|j|jz|_|j|jz|_|j|jz|_|j|jz|_|S)N)r) rErr+r,r-r.r/r0r1)r%rnumss r&__add__zNumbers.__add__s111|em3  -0BB/E,<<%/9/E,<<  #e&> >   #e&> >  r(c|dksJ|S)Nrr`)r%rs r&__radd__zNumbers.__radd__(szzzz r(N)rrrrrrrr)rrr+rr,rr-rr.rr/rr0rr1rrr)rrr)rr)rrK)rrrrK)rr)rrErrE)rrrrE)rrrrrHrpropertyrrrrrrrrrr`r(r&rErEsU"#"#55555.    222X2999X9X555X5.... &&&X&    r(rEr4Iterable[TLineNo]r3rList[Tuple[TLineNo, TLineNo]]ct|}t|}g}d}d}|D]J}|t|krn4|||kr |dz }|s|}|}/|r|||fd}K|r|||f|S)z,Produce a list of ranges for `format_lines`.Nrr*)r:r!rs)r4r3pairsstartlidxstmtends r& _line_rangesr.s  ##J 5MME E E D   3u::   E 5;   AID CC   LL% & & &E # eS\""" Lr(r;1Optional[Iterable[Tuple[TLineNo, List[TLineNo]]]]rKcDdt||D}|Wt|}|D]E\}}t|D]0}||vr*||vr&|dkr|nd}|||d|f1Fddt|D} | S)aNicely format a list of line numbers. Format a list of line numbers for printing by coalescing groups of lines as long as the lines represent consecutive statements. This will coalesce even if there are gaps between statements. For example, if `statements` is [1,2,3,4,5,10,11,12,13,14] and `lines` is [1,2,5,10,11,13,14] then the result will be "1-2, 5-11, 13-14". Both `lines` and `statements` can be any iterable. All of the elements of `lines` must be in `statements`, and all of the values must be positive integers. If `arcs` is provided, they are (start,[end,end,end]) pairs that will be included in the output as long as start isn't in `lines`. c<g|]}|dt|fS)rr )r"pairs r&riz format_lines.._s'YYY47IdOO,YYYr(Nrexitz->z, c3&K|] }|dV dS)Nr`)r"ts r&r'zformat_lines..hs&66aAbE666666r()rr:rsjoin) r4r3r; line_items line_exitsliner~exdestrets r&rMrMIs,ZYjRW9X9XYYYJ D\\ % A AKD%Umm A Au$$5"$q&&BBfD%%t->->->->&?@@@ A ))666*#5#5666 6 6C Jr(totalr fail_underrrrJcd|cxkrdksnd|d}t||dkr|dkrdSt|||kS)a'Determine if a total should fail due to fail-under. `total` is a float, the coverage measurement total. `fail_under` is the fail_under setting to compare with. `precision` is the number of digits to consider after the decimal point. Returns True if the total should fail. rrz fail_under=z' is invalid. Must be between 0 and 100.T)r r)rrrmsgs r&should_fail_underrlsp  $ $ $ $u $ $ $ $OJOOO#Uu~~t  " "Z //r()r4rr3rrrr)r4rr3rr;rrrK)rrrrrrrrJ)r __future__rrptypingrrrrrr r coverage.debugr coverage.exceptionsr coverage.miscrcoverage.typesrr coverage.datarcoverage.pluginrrrErrMrr`r(r&rs'&""""""QQQQQQQQQQQQQQQQQQ((((((++++++######((((((((-******,,,,,,\\\\\\\\~vvvvvmvvvr<?C     F000000r(