o
    ÍdZî'  ã                   @   sh   d Z ddlZddlmZ ddlmZmZmZ G dd„ deƒZ	G dd„ deƒZ
ed	d	eed
�dd„ ƒZdS )z Results of coverage measurement.é    N)Úiitems)ÚcontractÚformat_linesÚ
SimpleReprc                   @   sp   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚAnalysisz(The results of analyzing a FileReporter.c              	      s  |ˆ _ |ˆ _ˆ jjˆ _ˆ j ¡ ˆ _ˆ j ¡ ˆ _ˆ j  ˆ j¡pg }ˆ j |¡}ˆ j| ˆ _ˆ j  	¡ rft
ˆ j ¡ ƒˆ _ˆ j ¡ ˆ _ˆ j ¡ ˆ _ˆ  ¡ }ˆ  ¡ }t‡ fdd„t|ƒD ƒƒ}tdd„ t|ƒ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© úB/var/www/html/env/lib/python3.10/site-packages/coverage/results.pyÚ	<genexpr>!   s   €$ z$Analysis.__init__.<locals>.<genexpr>c                 s   s   � | ]	\}}t |ƒV  qd S r   )r	   r
   r   r   r   r   "   ó   € r   é   ©Ún_filesÚn_statementsÚ
n_excludedÚ	n_missingÚ
n_branchesÚn_partial_branchesÚn_missing_branches)ÚdataÚfile_reporterÚfilenameÚlinesÚ
statementsÚexcluded_linesÚexcludedÚtranslate_linesr   Úhas_arcsÚsortedÚarcsÚ_arc_possibilitiesÚexit_countsÚno_branch_linesÚ	no_branchÚtotal_branchesÚmissing_branch_arcsÚsumr   ÚsetÚNumbersr	   Únumbers)r   r   r   Úexecutedr   Úmbar   r   r   r   r   Ú__init__   s:   

ùzAnalysis.__init__c                 C   s   t | j| jƒS )zhThe missing line numbers, formatted nicely.

        Returns a string like "1-2, 5-11, 13-14".

        )r   r!   r   r   r   r   r   Úmissing_formatted3   s   zAnalysis.missing_formattedc                 C   s
   | j  ¡ S )z"Were arcs measured in this result?)r   r%   r   r   r   r   r%   ;   s   
zAnalysis.has_arcsc                 C   s   | j S )z.Returns a sorted list of the arcs in the code.)r(   r   r   r   r   Úarc_possibilities?   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   r'   r   r   Útranslate_arcsr&   )r   r2   r   r   r   Úarcs_executedC   s   zAnalysis.arcs_executedc                    s,   ˆ  ¡ }ˆ ¡ ‰ ‡ ‡fdd„|D ƒ}t|ƒS )z;Returns a sorted list of the arcs in the code not executed.c                 3   s*   � | ]}|ˆ vr|d  ˆj vr|V  qdS )r   N)r+   )r   Úp©r2   r   r   r   r   M   s   € þýz(Analysis.arcs_missing.<locals>.<genexpr>©r6   r8   r&   )r   Úpossibler   r   r:   r   Úarcs_missingI   s   ÿzAnalysis.arcs_missingc                 C   sj   |   ¡ }| j}tt|ƒƒ}g }|D ]\}}t|ƒD ]}||vr.| d||dkr)|ndf ¡ qqd |¡S )zäThe missing branch arcs, formatted nicely.

        Returns a string like "1->2, 1->3, 16->20". Omits any mention of
        branches from missing lines, so if line 17 is missing, then 17->18
        won't be included.

        z%d->%sr   Úexitz, )r-   r   r&   r   ÚappendÚjoin)r   r'   r   Ú
line_exitsÚpairsÚlineÚexitsÚexr   r   r   Úarcs_missing_formattedT   s   €þ
zAnalysis.arcs_missing_formattedc                    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 )r   r   Nr   )r   Úe©r<   r   r   r   o   s   € ýüz,Analysis.arcs_unpredicted.<locals>.<genexpr>r;   )r   r2   Úunpredictedr   rH   r   Úarcs_unpredictedf   s   
ÿzAnalysis.arcs_unpredictedc                 C   s   dd„ t | 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>y   s    z)Analysis.branch_lines.<locals>.<listcomp>)r   r)   r   r   r   r   Úbranch_linesw   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   rL   r   r   r   r   }   r   z*Analysis.total_branches.<locals>.<genexpr>)r.   r)   Úvaluesr   r   r   r   r,   {   s   zAnalysis.total_branchesc                 C   sF   |   ¡ }t|  ¡ ƒ}t t¡}|D ]\}}||v r ||  |¡ q|S )zgReturn arcs that weren't executed from branch lines.

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

        )r=   r/   rN   ÚcollectionsÚdefaultdictÚlistr?   )r   r   rN   r3   rK   Úl2r   r   r   r-      s   
€zAnalysis.missing_branch_arcsc              	   C   s`   |   ¡ }i }|  ¡ D ]#}| j| }zt|| ƒ}W n ty$   d}Y nw ||| f||< q
|S )zGet stats about branches.

        Returns a dict mapping line numbers to a tuple:
        (total_exits, taken_exits).
        r   )r-   rN   r)   r	   ÚKeyError)r   Úmissing_arcsÚstatsÚlnumrD   r   r   r   r   Úbranch_stats�   s   
ÿzAnalysis.branch_statsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r4   r5   r%   r6   r8   r=   rF   rJ   rN   r,   r-   rX   r   r   r   r   r      s    $r   c                   @   s–   e Zd ZdZdZdZdZ		ddd„Zdd„ Ze	d	d
„ ƒZ
edd„ ƒZ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 )r0   zœThe numerical results of measuring coverage.

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

    r   ç      ð?g     ÀX@c                 C   s.   || _ || _|| _|| _|| _|| _|| _d S r   r   )r   r   r   r   r   r   r   r   r   r   r   r4   ­   s   
zNumbers.__init__c                 C   s    | j | j| j| j| j| j| jgS )z:Return a list for __init__(*args) to recreate this object.r   r   r   r   r   Ú	init_args¸   s   þzNumbers.init_argsc                 C   s@   d|  krdk sJ ‚ J ‚|| _ dd|  | _d| j | _dS )z<Set the number of decimal places used to report percentages.r   é
   r]   ç      Y@N)Ú
_precisionÚ_near0Ú_near100)ÚclsÚ	precisionr   r   r   Úset_precision¿   s   zNumbers.set_precisionc                 C   ó   | j | j S )z*Returns the number of executed statements.)r   r   r   r   r   r   Ú
n_executedÇ   ó   zNumbers.n_executedc                 C   rg   )z(Returns the number of executed branches.)r   r   r   r   r   r   Ún_executed_branchesÌ   ri   zNumbers.n_executed_branchesc                 C   s,   | j dkr| j\}}d| | }|S d}|S )z/Returns a single percentage value for coverage.r   r`   )r   Úratio_covered)r   Ú	numeratorÚdenominatorÚpc_covr   r   r   Ú
pc_coveredÑ   s   

ÿzNumbers.pc_coveredc                 C   sd   | j }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 )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".

        r   éd   z%.*f)ro   rb   rc   Úroundra   )r   Úpcr   r   r   Úpc_covered_strÛ   s   	zNumbers.pc_covered_strc                 C   s    d}| j dkr|d| j  7 }|S )z/How many characters wide can pc_covered_str be?é   r   r   )ra   )rd   Úwidthr   r   r   Úpc_str_widthí   s   
zNumbers.pc_str_widthc                 C   s    | j | j }| j| j }||fS )z:Return a numerator and denominator for the coverage ratio.)rh   rj   r   r   )r   rl   rm   r   r   r   rk   õ   s   zNumbers.ratio_coveredc                 C   sl   t ƒ }| j|j |_| j|j |_| j|j |_| j|j |_| j|j |_| j|j |_| j|j |_|S r   )r0   r   r   r   r   r   r   r   )r   ÚotherÚnumsr   r   r   Ú__add__ü   s   
ÿ
ÿzNumbers.__add__c                 C   s   |dkr| S t S )Nr   )ÚNotImplemented)r   rw   r   r   r   Ú__radd__  s   zNumbers.__radd__N)r   r   r   r   r   r   r   )rY   rZ   r[   r\   ra   rb   rc   r4   r^   Úclassmethodrf   Úpropertyrh   rj   ro   rs   rv   rk   ry   r{   r   r   r   r   r0       s2    
ÿ



	


r0   Únumber)ÚtotalÚ
fail_underre   Úreturnsc                 C   s"   |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`   T)rq   )r   r€   re   r   r   r   Úshould_fail_under  s   r‚   )r\   rP   Úcoverage.backwardr   Úcoverage.miscr   r   r   Úobjectr   r0   ÚintÚboolr‚   r   r   r   r   Ú<module>   s    r