o
    gO4                     @  s   d Z ddlmZ ddlZddlmZmZmZmZm	Z	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rFdd	lmZ dd
lmZ G dd dZG dd dZd#ddZ	d$d%ddZd&d!d"ZdS )'z Results of coverage measurement.    )annotationsN)CallableDictIterableListOptionalTupleTYPE_CHECKING)	auto_repr)ConfigError	nice_pair)TArcTLineNo)CoverageData)FileReporterc                   @  s   e Zd ZdZd-ddZd.d/ddZd0ddZd1ddZd1ddZd1ddZ	d1ddZ
d2d d!Zd3d"d#Zd4d%d&Zd4d'd(Zd5d*d+Zd,S )6Analysisz(The results of analyzing a FileReporter.datar   	precisionintfile_reporterr   file_mapperCallable[[str], str]returnNonec           
   
     s(  | _ | _| jj _ j  _ j  _ j  jp!g } j|}| _ j j  _	 j 
 rlt j  _ j  _ j  _  }  }t fdd| D }tdd | D }	ng  _i  _t  _d } }}	t|dt jt jt j	|||	d _d S )Nc                 3  s&    | ]\}}| j vrt|V  qd S N)missinglen.0kvself P/var/www/html/bloggers_ems/venv/lib/python3.10/site-packages/coverage/results.py	<genexpr>3   s   $ z$Analysis.__init__.<locals>.<genexpr>c                 s  s    | ]	\}}t |V  qd S r   )r   r   r$   r$   r%   r&   4       r      )r   n_filesn_statements
n_excluded	n_missing
n_branchesn_partial_branchesn_missing_branches)r   r   filenamelines
statementsexcluded_linesexcludedtranslate_linesexecutedr   has_arcssortedarcs_arc_possibilitiesexit_countsno_branch_lines	no_branch_total_branchesmissing_branch_arcssumitemssetNumbersr   numbers)
r#   r   r   r   r   r6   r-   mbar.   r/   r$   r"   r%   __init__   s>   
zAnalysis.__init__Fbranchesboolstrc                 C  s0   |r|   r|   }nd}t| j| j|d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)r9   )r7   r?   rA   format_linesr2   r   )r#   rG   r9   r$   r$   r%   missing_formattedF   s   zAnalysis.missing_formattedc                 C  s
   | j  S )z"Were arcs measured in this result?)r   r7   r"   r$   r$   r%   r7   U   s   
zAnalysis.has_arcs
List[TArc]c                 C  s   | j S )z.Returns a sorted list of the arcs in the code.)r:   r"   r$   r$   r%   arc_possibilitiesY   s   zAnalysis.arc_possibilitiesc                 C  s&   | j | jpg }| j|}t|S )z@Returns a sorted list of the arcs actually executed in the code.)r   r9   r0   r   translate_arcsr8   )r#   r6   r$   r$   r%   arcs_executed]   s   zAnalysis.arcs_executedc                   s,     }   fdd|D }t|S )z:Returns a sorted list of the un-executed arcs in the code.c                 3  s8    | ]}| vr|d  j vr|d jvr|V  qdS r   r(   N)r=   r4   )r   pr6   r#   r$   r%   r&   h   s    z(Analysis.arcs_missing.<locals>.<genexpr>rM   rO   r8   )r#   possibler   r$   rR   r%   arcs_missingd   s   zAnalysis.arcs_missingc                   s*   |    |  } fdd|D }t|S )zAReturns a sorted list of the executed arcs missing from the code.c                 3  sD    | ]}| vr|d  |d kr|d  d ks|d d kr|V  qdS rP   r$   )r   erT   r$   r%   r&   y   s    z,Analysis.arcs_unpredicted.<locals>.<genexpr>rS   )r#   r6   unpredictedr$   rW   r%   arcs_unpredictedp   s   
zAnalysis.arcs_unpredictedList[TLineNo]c                 C  s   dd | j  D S )z<Returns a list of line numbers that have more than one exit.c                 S  s   g | ]
\}}|d kr|qS )r(   r$   )r   l1countr$   r$   r%   
<listcomp>       z*Analysis._branch_lines.<locals>.<listcomp>)r;   rA   r"   r$   r$   r%   _branch_lines   s   zAnalysis._branch_linesc                 C  s   t dd | j D S )z"How many total branches are there?c                 s  s    | ]	}|d kr|V  qdS )r(   Nr$   )r   r\   r$   r$   r%   r&      r'   z+Analysis._total_branches.<locals>.<genexpr>)r@   r;   valuesr"   r$   r$   r%   r>      s   zAnalysis._total_branchesDict[TLineNo, List[TLineNo]]c                 C  F   |   }t|  }tt}|D ]\}}||v r || | q|S )zgReturn arcs that weren't executed from branch lines.

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

        )rU   rB   r_   collectionsdefaultdictlistappend)r#   r   branch_linesrE   r[   l2r$   r$   r%   r?         
zAnalysis.missing_branch_arcsc                 C  rb   )zdReturn arcs that were executed from branch lines.

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

        )rO   rB   r_   rc   rd   re   rf   )r#   r6   rg   ebar[   rh   r$   r$   r%   executed_branch_arcs   ri   zAnalysis.executed_branch_arcsDict[TLineNo, Tuple[int, int]]c                 C  sD   |   }i }|  D ]}| j| }t|| }||| f||< q
|S )zGet stats about branches.

        Returns a dict mapping line numbers to a tuple:
        (total_exits, taken_exits).
        )r?   r_   r;   r   )r#   missing_arcsstatslnumexitsr   r$   r$   r%   branch_stats   s   
zAnalysis.branch_statsN)
r   r   r   r   r   r   r   r   r   r   )F)rG   rH   r   rI   )r   rH   )r   rL   )r   rZ   r   r   )r   ra   )r   rl   )__name__
__module____qualname____doc__rF   rK   r7   rM   rO   rU   rY   r_   r>   r?   rk   rq   r$   r$   r$   r%   r      s    
-








r   c                   @  s   e Zd ZdZ								d+d,ddZeZd-ddZed.ddZ	ed.ddZ
ed/ddZed0ddZd1ddZd.d d!Zed2d#d$Zd3d&d'Zd4d(d)Zd*S )5rC   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   r)   r*   r+   r,   r-   r.   r/   r   r   c	           	      C  sj   d|  krdk sJ  J || _ dd|  | _d| j | _|| _|| _|| _|| _|| _|| _|| _	d S )Nr   
   g      ?      Y@)

_precision_near0_near100r)   r*   r+   r,   r-   r.   r/   )	r#   r   r)   r*   r+   r,   r-   r.   r/   r$   r$   r%   rF      s   
zNumbers.__init__	List[int]c                 C  s$   | j | j| j| j| j| j| j| jgS )z:Return a list for __init__(*args) to recreate this object.)ry   r)   r*   r+   r,   r-   r.   r/   r"   r$   r$   r%   	init_args   s   zNumbers.init_argsc                 C     | j | j S )z*Returns the number of executed statements.)r*   r,   r"   r$   r$   r%   
n_executed      zNumbers.n_executedc                 C  r~   )z(Returns the number of executed branches.)r-   r/   r"   r$   r$   r%   n_executed_branches   r   zNumbers.n_executed_branchesfloatc                 C  s,   | j dkr| j\}}d| | }|S d}|S )z/Returns a single percentage value for coverage.r   rx   )r*   ratio_covered)r#   	numeratordenominatorpc_covr$   r$   r%   
pc_covered   s   

zNumbers.pc_coveredrI   c                 C  s   |  | 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"   r$   r$   r%   pc_covered_str   s   	zNumbers.pc_covered_strpcc                 C  s^   d|  k r| j k rn n| j }n| j|  k rdk r"n n| j}nt|| j}d| j|f 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".

        r   d   z%.*f)rz   r{   roundry   )r#   r   r$   r$   r%   r      s   zNumbers.display_coveredc                 C  s    d}| j dkr|d| j  7 }|S )z/How many characters wide can pc_covered_str be?   r   r(   )ry   )r#   widthr$   r$   r%   pc_str_width  s   
zNumbers.pc_str_widthTuple[int, int]c                 C  s    | j | j }| j| j }||fS )z:Return a numerator and denominator for the coverage ratio.)r   r   r*   r-   )r#   r   r   r$   r$   r%   r     s   zNumbers.ratio_coveredotherc                 C  sr   t | jd}| j|j |_| j|j |_| j|j |_| j|j |_| j|j |_| j|j |_| j|j |_|S )N)r   )	rC   ry   r)   r*   r+   r,   r-   r.   r/   )r#   r   numsr$   r$   r%   __add__  s   

zNumbers.__add__c                 C  s   |dksJ | S )Nr   r$   )r#   r   r$   r$   r%   __radd__*  s   zNumbers.__radd__N)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|   rr   )r   r   )r   rI   )r   r   r   rI   )r   r   )r   rC   r   rC   )r   r   r   rC   )rs   rt   ru   rv   rF   r
   __repr__r}   propertyr   r   r   r   r   r   r   r   r   r$   r$   r$   r%   rC      s6    	
	



rC   r2   Iterable[TLineNo]r1   r   List[Tuple[TLineNo, TLineNo]]c                 C  s   t | } t |}g }d}d}| D ]&}|t|kr n||| kr+|d7 }|s(|}|}q|r6|||f d}q|r@|||f |S )z,Produce a list of ranges for `format_lines`.Nr   r(   )r8   r   rf   )r2   r1   pairsstartlidxstmtendr$   r$   r%   _line_ranges0  s(   r   r9   1Optional[Iterable[Tuple[TLineNo, List[TLineNo]]]]rI   c           
      C  s   dd t | |D }|dur<t|}|D ]'\}}t|D ]}||vr:||vr:|dkr,|nd}||| d| f qqdd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                 S  s   g | ]
}|d  t |fqS )r   r   )r   pairr$   r$   r%   r]   a  r^   z format_lines.<locals>.<listcomp>Nr   exitz->z, c                 s  s    | ]}|d  V  qdS )Nr$   )r   tr$   r$   r%   r&   j  s    zformat_lines.<locals>.<genexpr>)r   r8   rf   join)
r2   r1   r9   
line_items
line_exitslinerp   exdestretr$   r$   r%   rJ   K  s   rJ   totalr   
fail_underr   r   rH   c                 C  sL   d|  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   rx   zfail_under=z' is invalid. Must be between 0 and 100.T)r   r   )r   r   r   msgr$   r$   r%   should_fail_undern  s   r   )r2   r   r1   r   r   r   r   )r2   r   r1   r   r9   r   r   rI   )r   r   r   r   r   r   r   rH   )rv   
__future__r   rc   typingr   r   r   r   r   r   r	   coverage.debugr
   coverage.exceptionsr   coverage.miscr   coverage.typesr   r   coverage.datar   coverage.pluginr   r   rC   r   rJ   r   r$   r$   r$   r%   <module>   s$   $  
{#