
    L-Ph6                       d Z ddlmZ ddlZddlZddlmZmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZmZ e	rdd	lmZ dd
lmZ d(dZej         G d d                      Zej         G d d                      Zd)dZd*d Z	 d+d,d#Zd-d'ZdS ).z Results of coverage measurement.    )annotationsN)	ContainerIterable)TYPE_CHECKING)ConfigError	nice_pair)TArcTLineNo)CoverageData)FileReporterdatar   	precisionintfile_reporterr   filenamestrreturnAnalysisc                   |                                  }|                                }|                                }|                    |                     |          pg           }|r-|                                }|                     |          pg }	|                    |	          }	t          j        t                    }
|D ] \  }}|
|         	                    |           !d |

                                D             }t                      }|	D ]D\  }}||k    r|	                    ||f           #||v r|	                    |||         f           E|                    |          }|                                }|                                }n,t                      }t                      }i }t                      }t          ||||||||||
  
        S )z'Create an Analysis from a FileReporter.c                f    i | ].\  }}t          |          d k    |t          |          d         /S )   r   )lenlist).0fromnotonoss      P/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/coverage/results.py
<dictcomp>z/analysis_from_file_reporter.<locals>.<dictcomp>,   s?     
 
 
5zzQ DKKN    
r   r   has_arcs
statementsexcludedexecutedarc_possibilities_setarcs_executed_setexit_counts	no_branch)r"   linesexcluded_linestranslate_linesarcstranslate_arcscollectionsdefaultdictsetadditemsr(   no_branch_linesr   )r   r   r   r   r"   r#   r$   r%   r&   r-   destsr   tonosingle_destsnew_arcsr'   r(   r)   s                     r   analysis_from_file_reporterr9      s    }}H$$&&J++--H,,TZZ-A-A-GRHHH  - 2 2 4 4#yy228b++D11 ',,1 	$ 	$LFD&Md####
 
!&
 
 

 55  	A 	ALFD~~fd^,,,,\))LL&,v*>!?@@@)88BB#//11!1133		 #EEEE	3+   r    c                      e Zd ZU dZded<   ded<   ded<   ded	<   ded
<   ded<   ded<   ded<   ded<   ded<   d&dZd'dZd(d)dZd*dZd+dZ	d,dZ
d-d!Zd-d"Zd.d$Zd%S )/r   z(The results of analyzing a FileReporter.r   r   r   r   boolr"   zset[TLineNo]r#   r$   r%   z	set[TArc]r&   r'   zdict[TLineNo, int]r(   r)   r   Nonec           
     ^    t           j                   _        t           j                   _         j         j        z
   _         j        r 	                                } 
                                }t           fd|                                D                       }t          d |                                D                       }ndx}x}}t           j        dt           j                  t           j                  t           j                  |||           _        d S )Nc              3  N   K   | ]\  }}|j         vt          |          V   d S N)missingr   )r   kvselfs      r   	<genexpr>z)Analysis.__post_init__.<locals>.<genexpr>g   s9      $\$\!at|F[F[SVVF[F[F[F[$\$\r    c              3  :   K   | ]\  }}t          |          V  d S r?   )r   )r   rA   rB   s      r   rD   z)Analysis.__post_init__.<locals>.<genexpr>h   s,      $C$C!SVV$C$C$C$C$C$Cr    r   r   )r   n_filesn_statements
n_excluded	n_missing
n_branchesn_partial_branchesn_missing_branches)sortedr&   arc_possibilitiesr'   arcs_executedr#   r%   r@   r"   _total_branchesmissing_branch_arcssumr3   Numbersr   r   r$   numbers)rC   rJ   mbarK   rL   s   `    r   __post_init__zAnalysis.__post_init___   s   !'(B!C!C#D$:;;6= 	E--//J**,,C!$$\$\$\$\syy{{$\$\$\!\!\!$$C$Csyy{{$C$C$C!C!CCDDJD+.@nT_--4=))$,''!11	
 	
 	
r    r*   Container[TLineNo]c                   fd| j         D             }fd| j        D             }fd| j        D             }| j        r_fd| j        D             }fd| j        D             }fd| j                                        D             }fd| j        D             }n,t                      }t                      }i }t                      }t          | j        | j        | j        |||||||
  
        S )	zCreate a narrowed Analysis.

        The current analysis is copied to make a new one that only considers
        the lines in `lines`.
        c                    h | ]}|v |	S  rZ   r   lnor*   s     r   	<setcomp>z"Analysis.narrow.<locals>.<setcomp>~   s    EEEcucr    c                    h | ]}|v |	S rZ   rZ   r[   s     r   r]   z"Analysis.narrow.<locals>.<setcomp>       AAACC5LLCLLLr    c                    h | ]}|v |	S rZ   rZ   r[   s     r   r]   z"Analysis.narrow.<locals>.<setcomp>   r_   r    c                .    h | ]\  }}|v s|v ||fS rZ   rZ   r   abr*   s      r   r]   z"Analysis.narrow.<locals>.<setcomp>   s:     % % %1a::e A!+r    c                .    h | ]\  }}|v s|v ||fS rZ   rZ   rb   s      r   r]   z"Analysis.narrow.<locals>.<setcomp>   s:     ! ! !1a::e A!+r    c                $    i | ]\  }}|v 	||S rZ   rZ   )r   r\   numr*   s      r   r   z#Analysis.narrow.<locals>.<dictcomp>   s0       %S#%<< S<<r    c                    h | ]}|v |	S rZ   rZ   r[   s     r   r]   z"Analysis.narrow.<locals>.<setcomp>   s    GGG#,,,,,r    r!   )r#   r$   r%   r"   r&   r'   r(   r3   r)   r1   r   r   r   )	rC   r*   r#   r$   r%   r&   r'   r(   r)   s	    `       r   narrowzAnalysis.narroww   sm    FEEET_EEE
AAAA4=AAAAAAA4=AAA= 	% % % %#'#=% % %!! ! ! !#'#9! ! !   )-)9)?)?)A)A  K HGGGGGGII$'EE! #KIn]]!"7/#
 
 
 	
r    Fbranchesc                    |r.| j         r'|                                                                 }nd}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-   )r"   rQ   r3   format_linesr#   r@   )rC   rj   r-   s      r   missing_formattedzAnalysis.missing_formatted   sR      	 	++--3355DDDDOT\EEEEr    
list[TArc]c                H      fd j         D             }t          |          S )z:Returns a sorted list of the un-executed arcs in the code.c              3  j   K   | ]-}|j         vr"|d          j        vr|d         j        v)|V  .dS )r   r   N)r'   r)   r$   )r   prC   s     r   rD   z(Analysis.arcs_missing.<locals>.<genexpr>   sa       
 
D222!DN22!DM11  2111	
 
r    )rN   rM   )rC   r@   s   ` r   arcs_missingzAnalysis.arcs_missing   s<    
 
 
 
-
 
 
 gr    list[TLineNo]c                H    d | j                                         D             S )z<Returns a list of line numbers that have more than one exit.c                $    g | ]\  }}|d k    |S )r   rZ   )r   l1counts      r   
<listcomp>z*Analysis._branch_lines.<locals>.<listcomp>   s!    IIIxr%uqyyyyyr    )r(   r3   rC   s    r   _branch_lineszAnalysis._branch_lines   s%    II4#3#9#9#;#;IIIIr    c                b    t          d | j                                        D                       S )z"How many total branches are there?c              3  &   K   | ]}|d k    |V  dS )r   NrZ   )r   rw   s     r   rD   z+Analysis._total_branches.<locals>.<genexpr>   s&      MMU519959999MMr    )rR   r(   valuesry   s    r   rP   zAnalysis._total_branches   s.    MMd&6&=&=&?&?MMMMMMr    dict[TLineNo, list[TLineNo]]c                ,   |                                  }t          |                                           }t          j        t
                    }|D ]B\  }}||k    sJ d| j         d| d|             ||v r||                             |           C|S )zgReturn arcs that weren't executed from branch lines.

        Returns {l1:[l2a,l2b,...], ...}

        zIn z, didn't expect z == )rr   r1   rz   r/   r0   r   r   append)rC   r@   branch_linesrU   rv   l2s         r   rQ   zAnalysis.missing_branch_arcs   s     ##%%4--//00%d++ 	# 	#FB888N4=NN"NN"NN888\!!Br"""
r    c                   t          |                                           }t          j        t                    }| j        D ]F\  }}||k    sJ d|d|            ||f| j        vr'||v r||                             |           G|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 = )r1   rz   r/   r0   r   rO   r&   r   )rC   r   ebarv   r   s        r   executed_branch_arcszAnalysis.executed_branch_arcs   s     4--//00%d++( 	# 	#FB888VbVVrVV888Bxt999\!!Br"""
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).

        )rQ   rz   r(   r   )rC   missing_arcsstatslnumexitsr@   s         r   branch_statszAnalysis.branch_stats   sm     //11&&(( 	3 	3D$T*E,t,--G %'/2E$KKr    N)r   r<   )r*   rW   r   r   )F)rj   r;   r   r   )r   rn   )r   rs   r   r   )r   r~   )r   r   )__name__
__module____qualname____doc____annotations__rV   ri   rm   rr   rz   rP   rQ   r   r   rZ   r    r   r   r   P   sR        22NNNMMMNNN$$$$    ####
 
 
 
0*
 *
 *
 *
XF F F F F   J J J JN N N N      $     r    c                     e Zd ZU dZdZded<   dZded<   dZded<   dZded<   dZ	ded<   dZ
ded	<   dZded
<   dZded<   edd            Zedd            Zedd            Zedd            Zedd            ZddZddZdS )rS   zThe numerical results of measuring coverage.

    This holds the basic statistics from `Analysis`, and is used to roll
    up statistics across files.

    r   r   r   rF   rG   rH   rI   rJ   rK   rL   r   c                     | j         | j        z
  S )z*Returns the number of executed statements.)rG   rI   ry   s    r   
n_executedzNumbers.n_executed  s      4>11r    c                     | j         | j        z
  S )z(Returns the number of executed branches.)rJ   rL   ry   s    r   n_executed_brancheszNumbers.n_executed_branches  s     !888r    floatc                F    | j         dk    r| j        \  }}d|z  |z  }nd}|S )z/Returns a single percentage value for coverage.r         Y@)rG   ratio_covered)rC   	numeratordenominatorpc_covs       r   
pc_coveredzNumbers.pc_covered  s:     q  %)%7"I{i';6FFFr    r   c                6    t          | j        | j                  S )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_coveredr   r   ry   s    r   pc_covered_strzNumbers.pc_covered_str  s     t???r    tuple[int, int]c                F    | j         | j        z   }| j        | j        z   }||fS )z:Return a numerator and denominator for the coverage ratio.)r   r   rG   rJ   )rC   r   r   s      r   r   zNumbers.ratio_covered'  s-     Od&>>	'$/9+%%r    otherc                    t          | j        | j        |j        z   | j        |j        z   | j        |j        z   | j        |j        z   | j        |j        z   | j        |j        z   | j        |j        z             S r?   )	rS   r   rF   rG   rH   rI   rJ   rK   rL   rC   r   s     r   __add__zNumbers.__add__.  su    NL5=( 22Oe..NU_,Oe..#e&>>#e&>>	
 	
 		
r    c                    |dk    sJ | S )Nr   rZ   r   s     r   __radd__zNumbers.__radd__:  s    zzzzr    Nr   )r   r   )r   r   )r   r   )r   rS   r   rS   )r   r   r   rS   )r   r   r   r   r   r   rF   rG   rH   rI   rJ   rK   rL   propertyr   r   r   r   r   r   r   rZ   r    r   rS   rS      sv          IGLJIJ2 2 2 X2 9 9 9 X9    X @ @ @ X@ & & & X&

 

 

 

     r    rS   pcr   c                    dd|z  z  }d| cxk     r|k     rn n|} n)d|z
  | cxk     rdk     r	n nd|z
  } nt          | |          } d|| fz  S )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      ?
   r   r   d   z%.*f)round)r   r   near0s      r   r   r   @  s     "	/!E2~~~~~~~~~
%-2	#	#	#	#	#	#	#	#	#U]2y!!YO##r    r#   Iterable[TLineNo]r*   list[tuple[TLineNo, TLineNo]]c                   t          |           } t          |          }g }d}d}| D ]J}|t          |          k    r n4|||         k    r|dz  }|s|}|}/|r|                    ||f           d}K|r|                    ||f           |S )z,Produce a list of ranges for `format_lines`.Nr   r   )rM   r   r   )r#   r*   pairsstartlidxstmtends          r   _line_rangesr   R  s    
 
##J5MMEE ED 
 
3u::E5;AID CC 	LL%&&&E #eS\"""Lr    r-   .Iterable[tuple[TLineNo, list[TLineNo]]] | Nonec                D   d t          | |          D             }|Wt          |          }|D ]E\  }}t          |          D ]0}||vr*||vr&|dk    r|nd}|                    || d| f           1Fd                    d t          |          D                       }	|	S )a  Nicely 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 | ]}|d          t          |          fS )r   r   )r   pairs     r   rx   z format_lines.<locals>.<listcomp>  s'    YYY47IdOO,YYYr    Nr   exitz->z, c              3  &   K   | ]}|d          V  dS )NrZ   )r   ts     r   rD   zformat_lines.<locals>.<genexpr>  s&      66aAbE666666r    )r   rM   r   join)
r#   r*   r-   
line_items
line_exitsliner   exdestrets
             r   rl   rl   m  s    , ZYjRW9X9XYYYJD\\
% 	A 	AKD%Umm A Au$$5"$q&&BBfD%%t->->->->&?@@@A
 ))666*#5#5666
6
6CJr    total
fail_underr;   c                    d|cxk    rdk    sn d| d}t          |          |dk    r| dk    rdS t          | |          |k     S )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.

    r   r   zfail_under=z' is invalid. Must be between 0 and 100.T)r   r   )r   r   r   msgs       r   should_fail_underr     sp     $$$$u$$$$OJOOO# Uu~~t	""Z//r    )
r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   )r#   r   r*   r   r   r   r?   )r#   r   r*   r   r-   r   r   r   )r   r   r   r   r   r   r   r;   )r   
__future__r   r/   dataclassescollections.abcr   r   typingr   coverage.exceptionsr   coverage.miscr	   coverage.typesr
   r   coverage.datar   coverage.pluginr   r9   	dataclassr   rS   r   r   rl   r   rZ   r    r   <module>r      s   ' & " " " " " "         / / / / / / / /             + + + + + + # # # # # # ( ( ( ( ( ( ( ( -******,,,,,,6 6 6 6r b b b b b b b bJ F F F F F F F FR$ $ $ $$   < <@         F0 0 0 0 0 0r    