
    /~hT                        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 dd	lmZmZ erdd
lmZ ddlmZ ddlmZ eee	f   ZdZ G d d      Z	 	 	 	 ddZ y)zJson reporting for coverage.py    )annotationsN)Iterable)AnyIOTYPE_CHECKING)__version__)get_analysis_to_report)AnalysisNumbers)TMorfTLineNo)Coverage)CoverageData)FileReporter   c                  T    e Zd ZdZdZd
dZddZd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     \/var/www/peopleoo.sandbox-dev.co.uk/venv/lib/python3.12/site-packages/coverage/jsonreport.py__init__zJsonReporter.__init__'   s8     mm**T[[223
$&    c                    |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)
n_executedn_statements
pc_coveredpc_covered_str	n_missing
n_excludedr   numss     r   make_summaryzJsonReporter.make_summary-   s<     "__"//#'+':':!^^"oo
 	
r   c                `    |j                   |j                  |j                  |j                  dS )z4Create a dict summarizing the branch info in `nums`.)num_branchesnum_partial_branchescovered_branchesmissing_branches)
n_branchesn_partial_branchesn_executed_branchesn_missing_branchesr+   s     r   make_branch_summaryz JsonReporter.make_branch_summary8   s0     !OO$($;$; $ 8 8 $ 7 7	
 	
r   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                  d<   |j                         r7| j                  d   j)                  | j+                  | j&                               t-        j.                  | j                  || j
                  j0                  rdnd       | j&                  j2                  xr | j&                  j4                  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_filenamer-   r   updater7   jsondumpjson_pretty_printr&   r'   )r   morfsoutfilecoverage_datameasured_filesfile_reporteranalysiss          r   reportzJsonReporter.reportA   s    'SZZ..0(()D)DE$"!**..0::<,557![[;;$
  '=dmmU'S 	#M8@D@T@TAN=::<=	 %3!%)%6%6tzz%B"!!#X&--d.F.Ftzz.RS		66AD	
 zz&&@4::+@+@@r   c                "   |j                   }| xj                  |z  c_        | j                  |      }t        |j                        |t        |j
                        t        |j                        d}| j                  j                  r|j                  |j                        |d<   |j                         rj|j                  | j                  |             t        t        |j!                                     |d<   t        t        |j#                                     |d<   t%        |j'                         j)                               }|j+                         D ]  \  }}	i x||	<   }
t-        t/        d|dz               }|j1                         D ]Y  }|j2                  |k7  r||j4                  z  }| j7                  ||j9                  |j4                              |
|j:                  <   [ | j7                  ||j9                  |            |
d<    |S )z3Extract the relevant report data for a single file.executed_linessummaryr#   r$   contextsexecuted_branchesr2       )numbersr   r-   sortedexecutedmissingexcludedr   rM   contexts_by_linenofilenamerL   rP   r7   list_convert_branch_arcsexecuted_branch_arcsmissing_branch_arcslensource
splitlinescode_region_kindssetrangecode_regionskindlinesmake_region_datanarrowname)r   rV   rY   rX   r,   r^   reported_file	num_linesnounpluralregion_dataoutside_linesregions                r   rN   zJsonReporter.report_one_filej   s    

d
##D)$X%6%67#H$4$45$X%6%67	"
 ;;))(5(H(HIZIZ([M*%!!#NN433D9:15$X%B%B%DE2M-. 15$X%A%A%CD1M,- ,,.99;<	);;= 	LD&244M&!KaQ 78M'446 ;;$&-+/+@+@!OOFLL1,FKK(	 #33.KO	  r   c                    |j                   }| j                  |      }t        |j                        |t        |j                        t        |j
                        d}| j                  j                  r |j                  |j                        }||d<   |j                         rj|j                  | j                  |             t        t        |j                                     |d<   t        t        |j!                                     |d<   |S )z0Create the data object for one region of a file.r\   r_   r`   r2   )rc   r-   rd   re   rf   rg   r   rM   rh   ri   rL   rP   r7   rj   rk   rl   rm   )r   rV   narrowed_analysisnarrowed_numsnarrowed_summarythis_regionr_   s          r   rw   zJsonReporter.make_region_data   s    )11,,];$%6%?%?@'#$5$=$=>$%6%?%?@	
 ;;))$778I8R8RSH&.K
#!!###D$<$<]$KL/3$%6%K%K%MN0K+, /3$%6%J%J%LM/K*+ r   N)r   r   returnNone)r,   r   r   JsonObj)rT   zIterable[TMorf] | NonerU   zIO[str]r   float)rV   r   rY   r
   rX   r   r   r   )rV   r   r   r
   r   r   )__name__
__module____qualname____doc__report_typer   r-   r7   rZ   rN   rw    r   r   r   r   "   sK    7K'	

'AR)))5=)NZ)	)Vr   r   c              #  V   K   | j                         D ]  \  }}|D ]  }||f 
  yw)z4Convert branch arcs to a list of two-element tuples.N)items)branch_arcsro   targetstargets       r   rk   rk      s=      ',,. ! 	!F&. 	!!s   '))r   zdict[TLineNo, list[TLineNo]]r   z!Iterable[tuple[TLineNo, TLineNo]])!r   
__future__r   rI   rQ   rC   collections.abcr   typingr   r   r   r   r   coverage.report_corer	   coverage.resultsr
   r   coverage.typesr   r   r   coverage.datar   coverage.pluginr   dictstrr   rH   r   rk   r   r   r   <module>r      so    % "   
 $ ) )   7 . )!*, sCx.
 H HV!-!&!r   