o
    g                     @  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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mZ ddlmZmZ erRdd	lmZ dd
lmZ dZG dd dZdddZdS )zJson reporting for coverage.py    )annotationsN)AnyDictIOIterableListOptionalTupleTYPE_CHECKING)__version__)get_analysis_to_report)AnalysisNumbers)TMorfTLineNo)Coverage)CoverageData   c                   @  s2   e Zd ZdZ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   S/var/www/html/bloggers_ems/venv/lib/python3.10/site-packages/coverage/jsonreport.py__init__!   s   

zJsonReporter.__init__morfsOptional[Iterable[TMorf]]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| jj| jj| jj| jj| jjd| jd< | rr| jd | jj| jj| jj| jjd tj| j|| jj r}dndd	 | jjo| 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covered_linesnum_statementspercent_coveredpercent_covered_displaymissing_linesexcluded_linestotalsnum_branchesnum_partial_branchescovered_branchesmissing_branches   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_filenamer   
n_executedn_statements
pc_coveredpc_covered_str	n_missing
n_excludedupdate
n_branchesn_partial_branchesn_executed_branchesn_missing_branchesjsondumpjson_pretty_print)r   r    r"   coverage_datameasured_filesfile_reporteranalysisr   r   r   report'   sH   


	
zJsonReporter.reportrV   r   rY   r   Dict[str, Any]c                 C  s   |j }|  j|7  _|j|j|j|j|j|jd}t|j	|t|j
t|jd}| jjr6|j|j|d< | r\||j|j|j|jd tt| |d< tt| |d< |S )z3Extract the relevant report data for a single file.r,   )executed_linessummaryr1   r2   contextsr4   executed_branchesr8   )numbersr   rH   rI   rJ   rK   rL   rM   sortedexecutedmissingexcludedr   rE   datacontexts_by_linenofilenamerD   rN   rO   rP   rQ   rR   list_convert_branch_arcsexecuted_branch_arcsmissing_branch_arcs)r   rV   rY   numsr]   reported_filer   r   r   rF   \   s<   	

zJsonReporter.report_one_fileN)r   r   r   r   )r    r!   r"   r#   r   r$   )rV   r   rY   r   r   r[   )__name__
__module____qualname____doc__report_typer   rZ   rF   r   r   r   r   r      s    

5r   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)rs   sourcetargetstargetr   r   r   ri      s   ri   )rs   rt   r   ru   )rq   
__future__r   rA   rS   r;   typingr   r   r   r   r   r   r	   r
   r   r   coverage.report_corer   coverage.resultsr   r   coverage.typesr   r   r   coverage.datar   r@   r   ri   r   r   r   r   <module>   s    (d