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
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mZ e
rVdd
lmZ ddlmZ ddlmZ eeef ZdZG dd dZ dddZ!dS )zJson reporting for coverage.py    )annotationsN)Iterable)IOTYPE_CHECKINGAny)__version__)get_analysis_to_report)AnalysisAnalysisNarrowerNumbers)TLineNoTMorf)Coverage)CoverageData)FileReporter   c                   @  sP   e Zd ZdZdZd#ddZd$ddZd$ddZd%ddZd&ddZ	d'd d!Z
d"S )(JsonReporterz-A reporter for writing JSON coverage results.zJSON reportcoverager   returnNonec                 C  s(   || _ | j j| _t| jj| _i | _d S N)r   configr   	precisiontotalreport_data)selfr    r   Y/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/coverage/jsonreport.py__init__'   s   

zJsonReporter.__init__numsr   JsonObjc              	   C  s&   |j |j|j|j|j|j|j|jdS )z!Create a dict summarizing `nums`.)covered_linesnum_statementspercent_coveredpercent_covered_displaymissing_linesexcluded_linespercent_statements_covered"percent_statements_covered_display)
n_executedn_statements
pc_coveredpc_covered_str	n_missing
n_excludedpc_statementspc_statements_strr   r   r   r   r   make_summary-   s   zJsonReporter.make_summaryc                 C  s   |j |j|j|j|j|jdS )z4Create a dict summarizing the branch info in `nums`.)num_branchesnum_partial_branchescovered_branchesmissing_branchespercent_branches_covered percent_branches_covered_display)
n_branchesn_partial_branchesn_executed_branchesn_missing_branchespc_branchespc_branches_strr1   r   r   r   make_branch_summary:   s   z JsonReporter.make_branch_summarymorfsIterable[TMorf] | NoneoutfileIO[str]floatc                 C  s   |pt j}| j }|| jj ttt	j	
  | | jjd| jd< i }t| j|D ]\}}| ||||| < q-|| jd< | | j| jd< | r[| jd | | j tj| j|| jjrfdndd | jjoq| jjS )zGenerate a json report for `morfs`.

        `morfs` is a list of modules or file names.

        `outfile` is a file object to write the json to.

        )formatversion	timestampbranch_coverageshow_contextsmetafilestotals   N)indent)sysstdoutr   get_dataset_query_contextsr   report_contextsFORMAT_VERSIONr   datetimenow	isoformathas_arcsjson_show_contextsr   r   report_one_filerelative_filenamer2   r   updater?   jsondumpjson_pretty_printr*   r+   )r   r@   rB   coverage_datameasured_filesfile_reporteranalysisr   r   r   reportE   s4   


zJsonReporter.reportr`   r   rc   r	   rb   r   c                   st  |j }|  j|7  _| |}t|j|t|jt|jd}| jjr+|	|j
|d< | rK|| | tt| |d< tt| |d< t|  }| }| D ]\\ }	ttd|d }
|D ]}|j krrqj|
|j8 }
qjt|}| fdd|D  ||
g i  ||	< }|D ]}|j krq| |||j||j< q| |||
|d< q[|S )	z3Extract the relevant report data for a single file.executed_linessummaryr%   r&   contextsexecuted_branchesr6      c                 3  s     | ]}|j  kr|jV  qd S r   )kindlines).0rnounr   r   	<genexpr>   s    z/JsonReporter.report_one_file.<locals>.<genexpr> ) numbersr   r2   sortedexecutedmissingexcludedr   rY   contexts_by_linenofilenamerX   r\   r?   list_convert_branch_arcsexecuted_branch_arcsmissing_branch_arcslensource
splitlinescode_regionscode_region_kindssetrangerk   rl   r
   add_regionsmake_region_datanarrowname)r   r`   rc   rb   r   rg   reported_file	num_linesregionspluraloutside_linesregionnarrowerregion_datar   ro   r   rZ   n   sT   






zJsonReporter.report_one_filenarrowed_analysisc                 C  s   |j }| |}t|j|t|jt|jd}| jjr&||j	}||d< |
 rF|| | tt| |d< tt| |d< |S )z0Create the data object for one region of a file.re   rh   ri   r6   )rs   r2   rt   ru   rv   rw   r   rY   rx   ry   rX   r\   r?   rz   r{   r|   r}   )r   r`   r   narrowed_numsnarrowed_summarythis_regionrh   r   r   r   r      s&   


zJsonReporter.make_region_dataN)r   r   r   r   )r   r   r   r    )r@   rA   rB   rC   r   rD   )r`   r   rc   r	   rb   r   r   r    )r`   r   r   r	   r   r    )__name__
__module____qualname____doc__report_typer   r2   r?   rd   rZ   r   r   r   r   r   r   "   s    




)4r   branch_arcsdict[TLineNo, list[TLineNo]]r   !Iterable[tuple[TLineNo, TLineNo]]c                 c  s,    |   D ]\}}|D ]}||fV  qqdS )z4Convert branch arcs to a list of two-element tuples.N)items)r   r   targetstargetr   r   r   r{      s   r{   )r   r   r   r   )"r   
__future__r   rU   r]   rO   collections.abcr   typingr   r   r   r   r   coverage.report_corer   coverage.resultsr	   r
   r   coverage.typesr   r   r   coverage.datar   coverage.pluginr   dictstrr    rT   r   r{   r   r   r   r   <module>   s(    