L iZC\dZddlmZddlZddlZddlmZddlmZddl m Z ddl m Z ddl mZmZer dd lmZdd lmZ dd Zej*Gd d ZeeZGddZej*GddZddZ ddZ d ddZddZy)z Results of coverage measurement.) annotationsN)Iterable) TYPE_CHECKING) ConfigError) nice_pair)TArcTLineNo) CoverageData) FileReporterAnalysisc p|j}|j}|j}|j|j|xsg}|r%|j }|j |xsg} |j | } t jt} |D]\} } | | j| | jD cic]#\} } t| dk(s| t| d%}} } t}| D]9\} } | | k7r|j| | f| |vs$|j| || f;|j |}|j}|j}n t}t}i}t}t|||||||||| Scc} } w)z'Create an Analysis from a FileReporter.r precisionfilenamehas_arcs statementsexcludedexecutedarc_possibilities_setarcs_executed_set exit_counts no_branch)rlinesexcluded_linestranslate_linesarcstranslate_arcs collections defaultdictsetadditemslenlistrno_branch_linesr )datar file_reporterrrrrrrrdestsfromnotonotonos single_destsnew_arcsrrrs V/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/coverage/results.pyanalysis_from_file_reporterr0s}}H$$&J++-H,,TZZ-A-GRHH - 2 2 4#yy28b++D1'',1 $LFD &M  d # $9>  '4vuUWXFDKN "  5  ALFD~ fd^,\)LL&,v*>!?@  A*88B#//1 !113 #E E 3+  ) s F2/F2ceZdZUdZded<ded<ded<ded <ded <ded <d ed <d ed<ded<ded<ddZdddZddZddZd dZ d!dZ d!dZ d"dZ y)#r z(The results of analyzing a FileReporter.intrstrrboolr set[TLineNo]rrr set[TArc]rrzdict[TLineNo, int]rrc Jtj_tj_j j z _jrcj}j}tfd|jD}td|jD}ndx}x}}tjdtj tj tj|||_y)Nc3XK|]!\}}|jvst|#ywN)missingr$).0kvselfs r/ z)Analysis.__post_init__..ds'$]1qPTP\P\G\SV$]s**c38K|]\}}t|ywr9)r$)r;r<r=s r/r?z)Analysis.__post_init__..es$D1SV$Dsrr)rn_files n_statements n_excluded n_missing n_branchesn_partial_branchesn_missing_branches)sortedrarc_possibilitiesr arcs_executedrrr:r_total_branchesmissing_branch_arcssumr#Numbersrr$rnumbers)r>rEmbarFrGs` r/ __post_init__zAnalysis.__post_init__\s!'(B(B!C#D$:$:;6 ==--/J**,C!$$] $]!] !$$D $D!D CD DJ D+.@nnT__-4==)$,,'!11   c|r+|jr|jj}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)rrLr# format_linesrr:)r>branchesrs r/missing_formattedzAnalysis.missing_formattedts@  ++-335DDDOOT\\EErRcDfdjD}t|S)z:Returns a sorted list of the un-executed arcs in the code.c3K|]6}|jvr&|djvr|djvr|8yw)rrN)rrr)r;pr>s r/r?z(Analysis.arcs_missing..sG ...!DNN*!DMM)  sr:s` r/ arcs_missingzAnalysis.arcs_missings$ ++ grRct|jjDcgc] \}}|dkDs |c}}Scc}}w)zl1counts r/ _branch_lineszAnalysis._branch_liness/$($4$4$:$:$<Jyr5 JJJs 44cVtd|jjDS)z"How many total branches are there?c3,K|] }|dkDs |yw)rN)r;r]s r/r?z+Analysis._total_branches..sMU5195Ms )rMrvaluesr>s r/rKzAnalysis._total_branchess"Md&6&6&=&=&?MMMrRc|j}t|j}tjt }|D]=\}}||k7sJd|j d|d|||vs*||j|?|S)zgReturn arcs that weren't executed from branch lines. Returns {l1:[l2a,l2b,...], ...} zIn z, didn't expect z == )rZr!r^rr r%rappend)r>r: branch_linesrPr\l2s r/rLzAnalysis.missing_branch_arcss ##%4--/0 %%d+ #FB8 Ns4==/1A"T"N N8\!Br" # rRc t|j}tjt}|j D]A\}}||k7s Jd|d|||f|j vr)||vs.||j|C|S)zReturn arcs that were executed from branch lines. Only include ones that we considered possible. Returns {l1:[l2a,l2b,...], ...} z+Oops: Didn't think this could happen: l1 = z, l2 = )r!r^rr r%rJrre)r>rfebar\rgs r/executed_branch_arcszAnalysis.executed_branch_arcss4--/0 %%d+(( #FB8 VKbWHrgV V8Bxt999\!Br"  #  rRc|j}i}|jD])}|j|}t||}|||z f||<+|S)zGet stats about branches. Returns a dict mapping line numbers to a tuple: (total_exits, taken_exits). )rLr^rr$)r> missing_arcsstatslnumexitsr:s r/ branch_statszAnalysis.branch_statssg//1 &&( 3D$$T*E,t,-G %'/2E$K 3 rRN)returnNone)F)rUr4rqr3)rqz list[TArc])rqz list[TLineNo]rqr2)rqzdict[TLineNo, list[TLineNo]])rqzdict[TLineNo, tuple[int, int]]) __name__ __module__ __qualname____doc____annotations__rQrVrZr^rKrLrjrprarRr/r r Msi2NMN$$  ## 0 F KN $rRc(eZdZdZddZddZddZy) AnalysisNarrowera For reducing an `Analysis` to a subset of its lines. Originally this was a simpler method on Analysis, but that led to quadratic behavior. This class does the bulk of the work up-front to provide the same results in linear time. Create an AnalysisNarrower from an Analysis, bulk-add region lines to it with `add_regions`, then individually request new narrowed Analysis objects for each region with `narrow`. Doing most of the work in limited calls to `add_regions` lets us avoid poor performance. c||_tjt|_tjt|_tjt |_yr9)analysisrr r!region2arc_possibilitiesregion2arc_executeddictregion2exit_counts)r>r|s r/__init__zAnalysisNarrower.__init__sH  GRG^G^_bGc%BMBYBYZ]B^ JUJaJa K rRc |jjri |D]}t|}|D]}| |<  d fd }||jj|j||jj |j |jjjD]+\}} j|x}s||j||<-yy)z Pre-process a number of sets of line numbers. Later calls to `narrow` with one of these sets will provide a narrowed Analysis. c|D]X\}}j|x}r||j||fj|x}sC||j||fZyr9)getr")arc_set region2arcsabr line2regions r/ collect_arcsz2AnalysisNarrower.add_regions..collect_arcssl$3DAq'OOA..q.#A**Aq62'OOA..q.#A**Aq62 3rRN)rr6rzdict[TRegionLines, set[TArc]]rqrr) r|r frozensetrr}rr~rr#rr) r>linessrfzlineslinerlnonumrrs @r/ add_regionszAnalysisNarrower.add_regionss == ! !79K 0#E*!0D(/K%0 0  3" 3: 3 3 <[>[ \ 88$:R:R S MM55;;= :S#,,1,69D++A.s3 :+ "rRc J|jj|z}|jj|z}|jj|z}|jjrRt |}|j |}|j|}|j|}|jj|z} n t}t}i}t} t|jj|jj|jj|||||||  S)zCreate a narrowed Analysis. The current analysis is copied to make a new one that only considers the lines in `lines`. r)r|rrrrrr}r~rrr!r rr) r>rrrrrrrrrs r/narrowzAnalysisNarrower.narrows]]--5 ==))E1==))E1 == ! !&G$($A$A'$J ! $ 8 8 A 11':K //%7I$'E ! # KImm--]]++]]++!"7/#  rRN)r|r rqrr)rzIterable[set[TLineNo]]rqrr)rr5rqr )rtrurvrwrrrrarRr/rzrzs  :<& rRrzc`eZdZUdZdZded<dZded<dZded<dZded<dZ ded<dZ ded <dZ ded <dZ ded <e dd Ze dd Ze ddZe ddZddZe ddZe ddZe ddZe ddZe ddZe ddZe ddZd dZd!dZy)"rNzThe numerical results of measuring coverage. This holds the basic statistics from `Analysis`, and is used to roll up statistics across files. rr2rrArBrCrDrErFrGc4|j|jz S)z*Returns the number of executed statements.)rBrDrcs r/ n_executedzNumbers.n_executed<s  4>>11rRc4|j|jz S)z(Returns the number of executed branches.)rErGrcs r/n_executed_brancheszNumbers.n_executed_branchesAs!8!888rRc2|j|jfS)z4Return numerator/denominator for statement coverage.)rrBrcs r/ratio_statementszNumbers.ratio_statementsFs 1 111rRc2|j|jfS)z1Return numerator/denominator for branch coverage.)rrErcs r/ratio_brancheszNumbers.ratio_branchesKs''88rRc|dkDrd|z|z Sy)zHelper for pc_* properties.rY@rar> numerator denominators r/_percentzNumbers._percentPs ?I%4 4rRc4|j|jS)z/Returns a single percentage value for coverage.)r ratio_coveredrcs r/ pc_coveredzNumbers.pc_coveredVst}}d0011rRc4|j|jS)z.Returns the percentage covered for statements.)rrrcs r/ pc_statementszNumbers.pc_statements[st}}d3344rRc4|j|jS)z,Returns the percentage covered for branches.)rrrcs r/ pc_brancheszNumbers.pc_branches`st}}d1122rRcBt|j|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_coveredrrrcs r/pc_covered_strzNumbers.pc_covered_strest??rRcBt|j|jS)z=Returns the statement percent covered without a percent sign.)rrrrcs r/pc_statements_strzNumbers.pc_statements_strpst114>>BBrRcBt|j|jS)z:Returns the branch percent covered without a percent sign.)rrrrcs r/pc_branches_strzNumbers.pc_branches_strust//@@rRcn|j|jz}|j|jz}||fS)z:Return a numerator and denominator for the coverage ratio.)rrrBrErs r/rzNumbers.ratio_coveredzs7OOd&>&>> ''$//9 +%%rRc |t|j|j|jz|j|jz|j|jz|j |j z|j |j z|j|jz|j|jzSr9) rNrrArBrCrDrErFrGr>others r/__add__zNumbers.__add__s NN LL5== (    2 2 2 OOe.. . NNU__ , OOe.. .  # #e&>&> >  # #e&>&> >  rRc|dk(sJ|S)Nrrars r/__radd__zNumbers.__radd__szz rRNrs)rqztuple[int, int])rr2rr2rqfloat)rqr)rqr3)rrNrqrN)rr2rqrN)rtrurvrwrrxrArBrCrDrErFrGpropertyrrrrrrrrrrrrrrrarRr/rNrN*sJIsGSL#JIsJ 22992299 225533@@CCAA&&  rRrNcdd|zz }d|cxkr|krnn|}n#d|z |cxkrdkr nnd|z }n t||}|d|dS)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". g? rrd.f)round)pcrnear0s r/rrs[ "i- E2~~  %-2 # # U] 2y !9+Q  rRct|}t|}g}d}d}|D]>}|t|k\rn.|||k(r |dz }|s|}|}'|s*|j|fd}@|r|j|f|S)z,Produce a list of ranges for `format_lines`.Nrr)rHr$re)rrpairsstartlidxstmtends r/ _line_rangesrs  #J 5ME E E D  3u:   5;  AIDC  LL% &E   eS\" LrRcDt||Dcgc]}|dt|f}}|Pt|}|D]@\}}t|D]-}||vs||vs |dkDr|nd} |j||d| f/Bdj dt|D} | Scc}w)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`. rexitz->z, c3&K|] }|d yw)Nra)r;ts r/r?zformat_lines..s6aAbE6s)rrrHrejoin) rrrpair line_items line_exitsrroexdestrets r/rTrTs,:FjRW9XY47IdO,YJY D\ % AKD%Um Au$5!#a2VD%%tvRv->&?@ A A ))66*#56 6C JZsBcrd|cxkrdksnd|d}t||dk(r|dk7ryt|||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)rr)total fail_underrmsgs r/should_fail_underrsP  $u $J<'NO#Uu~  "Z //rR) r'r rr2r(r rr3rqr )rrrr2rqr3)rIterable[TLineNo]rrrqzlist[tuple[TLineNo, TLineNo]]r9)rrrrrz.Iterable[tuple[TLineNo, list[TLineNo]]] | Nonerqr3)rrrrrr2rqr4)rw __future__rr dataclassescollections.abcrtypingrcoverage.exceptionsr coverage.miscrcoverage.typesrr coverage.datar coverage.pluginr r0 dataclassr r TRegionLinesrzrNrrrTrrarRr/rs'"$ +#(*,4 44 4 4  4n wwwt! \ \ ~ eeeP!$! #<<@ !    9  F0rR