o
    v&i                     @  s   d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	m
Z
 ddlmZ ddlmZ ddlmZmZmZ dd	lmZ e
rFdd
lmZ d$ddZd%ddZd&ddZd'd d!ZG d"d# d#ZdS )(zLCOV reporting for coverage.py.    )annotationsN)Iterable)IOTYPE_CHECKING)FileReporter)get_analysis_to_report)AnalysisAnalysisNarrowerNumbers)TMorf)Coveragelinestrreturnc                 C  s.   t j| ddd }t|ddS )z9Produce a hash of a source line for use in the LCOV file.zutf-8F)usedforsecurityascii=)hashlibmd5encodedigestbase64	b64encodedecoderstrip)r   hashed r   Y/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/coverage/lcovreport.py	line_hash   s   r   analysisr   lines	list[int]source_lines	list[str]outfileIO[str]Nonec              	   C  s   d}|D ]#}|rdt ||d   }t|| jv}|d| d| | d q| jjdkrF|d| jj d |d| jj d d	S d	S )
z0Emit line coverage records for an analyzed file. ,   zDA:
r   zLF:zLH:N)r   intmissingwritenumbersn_statements
n_executed)r   r    r"   r$   hash_suffixr   hitr   r   r   
lcov_lines#   s   r3   frr   file_analysisc              
   C  s   dd |   D }|sdS t|}|dd |D  |  d}|D ]4\}}}||j}	t|	jjdk}
||
7 }|	d| d| d|j
 d	 |	d
|
 d|j
 d	 q#|	dt| d	 |	d| d	 dS )z4Emit function coverage records for an analyzed file.c                 S  sB   g | ]}|j d kr|jrt|jt|jt|jt|j|fqS )function)kindr    minstartmax).0regionr   r   r   
<listcomp>H   s    z"lcov_functions.<locals>.<listcomp>Nc                 s  s    | ]	\}}}|j V  qd S N)r    )r;   _rr   r   r   	<genexpr>U       z!lcov_functions.<locals>.<genexpr>r   zFN:r(   r*   zFNDA:zFNF:zFNH:)code_regionsr	   add_regionssortnarrowr    r+   r.   r0   r-   namelen)r4   r5   r$   	functionsnarrowerfunctions_hit
first_line	last_liner<   r   r2   r   r   r   lcov_functions8   s"   	 rN   c                 C  s>  |  }| }| }|D ]^}||vrq|| \}}	|	dkr3t|| dks)J dd || D }
ndd || D }
|
dd || D  |
jdd d	 |
D ]\}}| ||}|d
| d| d| d qRqtdd |	 D }|tdd |	 D  }|dkr|d| d |d| d dS dS )z2Emit branch coverage records for an analyzed file.r   c                 S     g | ]}|d fqS )-r   r;   dstr   r   r   r=          zlcov_arcs.<locals>.<listcomp>c                 S  rO   )1r   rQ   r   r   r   r=      rS   c                 s  s    | ]}|d fV  qdS )0Nr   rQ   r   r   r   rA          zlcov_arcs.<locals>.<genexpr>c                 S  s   | d dk | fS )Nr   r   )dr   r   r   <lambda>   s    zlcov_arcs.<locals>.<lambda>)keyzBRDA:z,0,r(   r*   c                 s  s    | ]\}}|V  qd S r>   r   r;   tkr   r   r   rA      rV   c                 s  s    | ]	\}}|| V  qd S r>   r   rZ   r   r   r   rA      rB   zBRF:zBRH:N)
branch_statsexecuted_branch_arcsmissing_branch_arcsrH   extendrE   arc_descriptionr-   sumvalues)r4   r   r    r$   r]   executed_arcsmissing_arcsr   r?   takendestinationsrR   r2   branchbrfbrhr   r   r   	lcov_arcsg   s.    rk   c                   @  s2   e Zd ZdZdZdddZdddZdddZdS )LcovReporterz-A reporter for writing LCOV coverage reports.zLCOV reportcoverager   r   r&   c                 C  s"   || _ |j| _t| j jj| _d S r>   )rm   configr
   	precisiontotal)selfrm   r   r   r   __init__   s   zLcovReporter.__init__morfsIterable[TMorf] | Noner$   r%   floatc                 C  sr   | j   |p	tj}dd t| j |D }|  |D ]\}}}|  j|j7  _| |||| q| jj	o8| jj
S )zRenders the full lcov report.

        `morfs` is a list of modules or filenames

        outfile is the file object to write the file into.
        c                 S  s   g | ]\}}|  ||fqS r   )relative_filename)r;   r4   r   r   r   r   r=      s    z'LcovReporter.report.<locals>.<listcomp>)rm   get_datasysstdoutr   rE   rp   r.   	lcov_filer/   
pc_covered)rq   rs   r$   	to_reportfnamer4   r   r   r   r   report   s   


zLcovReporter.report	rel_fnamer   r4   r   r   r   c                 C  s   |j jdkr| jjrdS |d| d t|j}| jjr%| 	 }ng }t
|||| t||| |jr>t|||| |d dS )zProduces the lcov data for a single file.

        This currently supports both line and branch coverage,
        however function coverage is not supported.
        r   NzSF:r*   zend_of_record
)r.   r/   rn   
skip_emptyr-   sorted
statementslcov_line_checksumssource
splitlinesr3   rN   has_arcsrk   )rq   r   r4   r   r$   r    r"   r   r   r   rz      s   
zLcovReporter.lcov_fileN)rm   r   r   r&   )rs   rt   r$   r%   r   ru   )
r   r   r4   r   r   r   r$   r%   r   r&   )__name__
__module____qualname____doc__report_typerr   r~   rz   r   r   r   r   rl      s    

rl   )r   r   r   r   )
r   r   r    r!   r"   r#   r$   r%   r   r&   )r4   r   r5   r   r$   r%   r   r&   )
r4   r   r   r   r    r!   r$   r%   r   r&   )r   
__future__r   r   r   rx   collections.abcr   typingr   r   coverage.pluginr   coverage.report_corer   coverage.resultsr   r	   r
   coverage.typesr   rm   r   r   r3   rN   rk   rl   r   r   r   r   <module>   s$   



/4