
    He                        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
 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
rdd	lmZ dd
lmZ dZ G d d      Z	 	 	 	 ddZy)zJson reporting for coverage.py    )annotationsN)AnyIOIterableTYPE_CHECKING)__version__)get_analysis_to_report)AnalysisNumbers)TMorfTLineNo)Coverage)CoverageData   c                  ,    e Zd ZdZdZddZddZd	dZy)
JsonReporterz-A reporter for writing JSON coverage results.zJSON reportc                    || _         | j                   j                  | _        t        | j                  j                        | _        i | _        y )N)coverageconfigr   	precisiontotalreport_data)selfr   s     5/usr/lib/python3/dist-packages/coverage/jsonreport.py__init__zJsonReporter.__init__!   s8     mm**T[[223
+-    c                   |xs t         j                  }| j                  j                         }|j	                  | j
                  j                         t        t        t        j                  j                         j                         |j                         | j
                  j                  d| j                  d<   i }t        | j                  |      D ](  \  }}| j!                  ||      ||j#                         <   * || j                  d<   | j$                  j&                  | j$                  j(                  | j$                  j*                  | j$                  j,                  | j$                  j.                  | j$                  j0                  d| j                  d<   |j                         rs| j                  d   j3                  | j$                  j4                  | j$                  j6                  | j$                  j8                  | j$                  j:                  d       t=        j>                  | j                  || j
                  j@                  rdnd	       | j$                  j(                  xr | 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   morfsoutfilecoverage_datameasured_filesfile_reporteranalysiss          r   reportzJsonReporter.report'   s    'SZZ..0(()D)DE$"!**..0::<,557![[;;$
  '=dmmU'S 	#M8@D@T@TAN=::<=	 %3! "ZZ22"jj55#zz44'+zz'@'@!ZZ11"jj33&
" !!#X&-- $

 5 5(,

(E(E$(JJ$B$B$(JJ$A$A	/  			66AD	
 zz&&@4::+@+@@r   c                   |j                   }| xj                  |z  c_        |j                  |j                  |j                  |j
                  |j                  |j                  d}t        |j                        |t        |j                        t        |j                        d}| j                  j                  r(|j                  j                  |j                         |d<   |j#                         r|j%                  |j&                  |j(                  |j*                  |j,                  d       t/        t1        |j3                                     |d<   t/        t1        |j5                                     |d<   |S )z3Extract the relevant report data for a single file.r%   )executed_linessummaryr*   r+   contextsr-   executed_branchesr1   )numbersr   rA   rB   rC   rD   rE   rF   sortedexecutedmissingexcludedr   r>   datacontexts_by_linenofilenamer=   rG   rH   rI   rJ   rK   list_convert_branch_arcsexecuted_branch_arcsmissing_branch_arcs)r   rQ   rT   numsrX   reported_files         r   r?   zJsonReporter.report_one_file\   sA   

d
!__"//#'+':':!^^"oo
 %X%6%67#H$4$45$X%6%67	
 ;;))(0(H(HIZIZ([M*%!!#NN $(,(?(?$($<$<$($;$;	  26$X%B%B%DE2M-. 15$X%A%A%CD1M,- r   N)r   r   returnNone)rO   zIterable[TMorf] | NonerP   zIO[str]ri   float)rQ   r   rT   r
   ri   zdict[str, Any])__name__
__module____qualname____doc__report_typer   rU   r?    r   r   r   r      s    7K.3Aj!r   r   c              #  V   K   | j                         D ]  \  }}|D ]  }||f 
  yw)z4Convert branch arcs to a list of two-element tuples.N)items)branch_arcssourcetargetstargets       r   rd   rd      s=      ',,. ! 	!F&. 	!!s   '))rt   zdict[TLineNo, list[TLineNo]]ri   z!Iterable[tuple[TLineNo, TLineNo]])ro   
__future__r   r:   rL   r4   typingr   r   r   r   r   r   coverage.report_corer	   coverage.resultsr
   r   coverage.typesr   r   r   coverage.datar   r9   r   rd   rq   r   r   <module>r~      sZ    % "   
 3 3   7 . )!*
 a aH!-!&!r   