o
    gE                     @   s
  d Z ddlZddlZddlZddlZddlZddlZddlZddlm	Z	 ddl
mZ ddlmZ ddl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 dd
lmZ eeZdd Zdd Zdd ZG dd dZG dd dZG dd dZ dd Z!dd Z"dS )zHTML reporting for coverage.py.    N)add_data_to_hash)CoverageException)flat_rootname)
ensure_dirfile_be_goneHasherisolate_moduleformat_local_datetime)human_sorted)get_analysis_to_report)Numbers)Templitec                 C   s(   t jt jtd}t j|| }|S )z9Return the path to an "htmlfiles" data file of ours.
    	htmlfiles)ospathjoindirname__file__)fname
static_dirstatic_filename r   K/home/ubuntu/cloudmapper/venv/lib/python3.10/site-packages/coverage/html.pydata_filename   s   r   c                 C   s8   t t| }| W  d   S 1 sw   Y  dS )z+Return the contents of a data file of ours.N)openr   read)r   	data_filer   r   r   	read_data"   s   $r   c                 C   sZ   t jdd|t jdd }t| d}||dd W d   dS 1 s&w   Y  dS )	z*Write `html` to `fname`, properly encoded.z(\A\s+)|(\s+$) )flags
wbasciixmlcharrefreplaceN)resub	MULTILINEr   writeencode)r   htmlfoutr   r   r   
write_html(   s   "r+   c                   @   s$   e Zd ZdZdZdd Zdd ZdS )HtmlDataGenerationz8Generate structured data to be turned into HTML reports.z(empty)c                 C   sX   || _ | j j| _| j  }| | _| jjr#| dhkr#| j d || jj d S )Nr   zNo contexts were measured)	coverageconfigget_datahas_arcsshow_contextsmeasured_contexts_warnset_query_contextsreport_contexts)selfcovdatar   r   r   __init__4   s   


zHtmlDataGeneration.__init__c                    sv   j r| }| } jjr|j|j}g }t|	 ddD ]\}}d}	g }
g }||j
v r2d}	n9||jv r:d}	n1 j rd||v rdd}	|| D ]}|dk rS|
d n|
| ||||| qGn||jv rkd	}	d }}d}|	r jjrt fd
d||dD }| jgkr j}n	t| d}|}|tj|||	||jv ||||
|d	 q tj| |j|d}|S )z.Produce the data needed for one file's report.   startNexcmisparr   exitrunc                 3   s    | ]}|p j V  qd S N)EMPTY).0cr6   r   r   	<genexpr>a   s    z3HtmlDataGeneration.data_for_file.<locals>.<genexpr>r   z ctx)	tokensnumbercategory	statementcontextscontexts_labelcontext_listshort_annotationslong_annotations)relative_filenamenumslines)r0   missing_branch_arcsarcs_executedr.   r1   r8   contexts_by_linenofilename	enumeratesource_token_linesexcludedmissingappendmissing_arc_description
statementsr
   getrC   lentypesSimpleNamespacerQ   numbers)r6   franalysisrT   rU   rV   rS   linenorH   rJ   rO   rP   brL   rM   rN   	file_datar   rF   r   data_for_file>   sb   




z HtmlDataGeneration.data_for_fileN)__name__
__module____qualname____doc__rC   r9   ri   r   r   r   r   r,   /   s
    
r,   c                   @   s@   e Zd ZdZg dZdd Zdd Zdd Zd	d
 Zdd Z	dS )HtmlReporterzHTML reporting.)z	style.csszcoverage_html.jszkeybd_closed.pngzkeybd_open.pngzfavicon_32.pngc                 C   s4  || _ | j j| _| jj| _| jj| _| jd u r| jj| _| jj| _| jd u r+| jj| _d| _d| _	| jj
}| jjrCtj| jj| _nd | _| j  | _| j | _g | _g | _t| j| _t| j | _t| jjd| _tttt jt j|t t!j!" | j| j| jj#dddddd| _$t%d	| _&t'| j&| j$| _(d S )
Nr   )	precisionzexc show_exczmis show_miszpar run show_parrA   )r=   r>   r?   rA   )escapepairr`   __url____version__title
time_stamp	extra_cssr0   r1   rJ   zpyfile.html))r-   r.   html_dir	directoryhtml_skip_coveredskip_coveredhtml_skip_empty
skip_emptyskipped_covered_countskipped_empty_count
html_titlerv   r   r   basenamer/   r8   r0   file_summariesall_files_numsIncrementalCheckerincrr,   datagenr   ro   totalsrp   rq   r`   rr   rs   r	   datetimenowr1   template_globalsr   pyfile_html_sourcer   source_tmpl)r6   r7   rt   r   r   r   r9      sP   








zHtmlReporter.__init__c                 C   sx   | j   | j | j| j t| j|D ]
\}}| || q| js&t	dt
| j| _|   |   | jjo;| jjS )zcGenerate an HTML report for `morfs`.

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

        zNo data to report.)r   r   check_global_datar.   r   r   r-   	html_filer   r   sumr   
index_filemake_local_static_report_filesn_statements
pc_covered)r6   morfsrd   re   r   r   r   report   s   
zHtmlReporter.reportc                 C   s   | j D ]}tt|tj| j| qttj| jdd}|	d W d   n1 s/w   Y  | j
rHt| jj
tj| j| j
 dS dS )z5Make local instances of static files for HTML report.z
.gitignorewz# Created by coverage.py
*
N)STATIC_FILESshutilcopyfiler   r   r   r   rx   r   r'   rv   r.   )r6   staticfgir   r   r   r      s   
"z+HtmlReporter.make_local_static_report_filesc                    s<  t | }|d }t| j tj| j|}|j}| j	| | j
r>|jdk}|jdk}|r>|r>t| |  jd7  _dS | jrS|jdkrSt| |  jd7  _dS | j| j||rh| j	| j| dS | j||}	|	jD ] g }
 jD ]"\}}|dkr|
	t| qyt|pd}|
	d| d| d	 qyd
|
 _ jrd fdd jD  _nd _ jr߈ j}t |dkr|d  _!nd"t |ddd t#|ddD  _!nd _!g } j$r|	| j%d  j$  d|pd _&qr| j'(|	j)}
t*||
 ||| d}| j	| | j+|| dS )z*Generate an HTML file for one source file.z.htmlr   r:   Nwsz&nbsp;z<span class="z">z</span>r   z,&nbsp;&nbsp; c                 3   s     | ]} j  d | V  qdS )z&#x202F;&#x219B;&#x202F;N)rI   )rD   dldatar   r   rG     s
    
z)HtmlReporter.html_file.<locals>.<genexpr>z{:d} missed branches: {}z, c                 s   s$    | ]\}}|d d| V  qdS )r   z) Nr   )rD   numann_longr   r   r   rG   -  s
    
r;   rJ    pln)rR   html_filenamerQ   ),r   rQ   r   rx   r   r   r   rc   r   r\   rz   	n_missingn_partial_branchesr   r}   r|   r   r~   r   can_skip_filer8   r   
index_infor   ri   rS   rH   rp   r)   rO   annotaterP   r`   annotate_longformatrX   rJ   r   	css_classr   render__dict__r+   set_index_info)r6   rd   re   rootnamer   	html_pathrR   no_missing_linesno_missing_branchesrh   r)   tok_typetok_texttok_htmllongscss_classesr   r   r   r   r      sx   







zHtmlReporter.html_filec                 C   s   t td| j}d }}| jrd}|| j| jdkrdnd}| jr2d}|| j| jdkr/dnd}|| j| j||d}t	j
| jd}t|| | jd	|  | j  d
S )z*Write the index.html file for this report.z
index.htmlr   z'{} {} skipped due to complete coverage.r:   filefilesz{} empty {} skipped.)r   r   skipped_covered_msgskipped_empty_msgzWrote HTML report to N)r   r   r   r}   r   r~   r   r   r   r   r   r   rx   r+   r-   _messager   r'   )r6   
index_tmplr   r   msgr)   r   r   r   r   r   F  s0   
zHtmlReporter.index_fileN)
rj   rk   rl   rm   r   r9   r   r   r   r   r   r   r   r   rn   }   s    9Zrn   c                   @   sh   e Zd 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dd Zdd Zdd Zdd ZdS )r   z0Logic and data to support incremental reporting.zstatus.json   c                 C   s   || _ |   d S rB   )rx   reset)r6   rx   r   r   r   r9     s   zIncrementalChecker.__init__c                 C   s   d| _ i | _dS )z5Initialize to empty. Causes all files to be reported.r   N)globalsr   rF   r   r   r   r     s   
zIncrementalChecker.resetc              	   C   s   d}z$t j| j| j}t|}t|}W d   n1 s w   Y  W n tt	fy3   d}Y nw d}|d | j
kr@d}n	|d tjkrId}|rqi | _|d  D ]\}}t|d d  |d d< || j|< qT|d	 | _dS |   dS )
z)Read the information we stored last time.FNTr   versionr   indexrR   r   )r   r   r   rx   STATUS_FILEr   jsonloadOSError
ValueErrorSTATUS_FORMATr-   rs   r   itemsr   r   r   )r6   usablestatus_filefstatusstatusrW   fileinfor   r   r   r     s,   
zIncrementalChecker.readc                 C   s   t j| j| j}i }| j D ]\}}|d d  |d d< |||< q| jt	j
| j|d}t|d}tj||dd W d   dS 1 sHw   Y  dS )zWrite the current status.r   rR   )r   r   r   r   r   ),:)
separatorsN)r   r   r   rx   r   r   r   	init_argsr   r-   rs   r   r   r   dump)r6   r   r   rW   r   r   r*   r   r   r   r'     s   
"zIncrementalChecker.writec                 G   sB   t  }|D ]}|| q| }| j|kr|   || _dS dS )z<Check the global data that can affect incremental reporting.N)r   update	hexdigestr   r   )r6   r8   mr   these_globalsr   r   r   r     s   

z$IncrementalChecker.check_global_datac                 C   sV   t  }|| d t||j| | }| |}||kr#dS | || dS )zCan we skip reporting this file?

        `data` is a CoverageData object, `fr` is a `FileReporter`, and
        `rootname` is the name being used for the file.
        zutf-8TF)	r   r   sourcer(   r   rW   r   	file_hashset_file_hash)r6   r8   rd   r   r   	this_hash	that_hashr   r   r   r     s   
z IncrementalChecker.can_skip_filec                 C   s   | j |i ddS )z#Get the hash of `fname`'s contents.hashr   r   r_   r6   r   r   r   r   r        zIncrementalChecker.file_hashc                 C      || j |i d< dS )z#Set the hash of `fname`'s contents.r   Nr   
setdefault)r6   r   valr   r   r   r     r   z IncrementalChecker.set_file_hashc                 C   s   | j |i di S )z/Get the information for index.html for `fname`.r   r   r   r   r   r   r     r   zIncrementalChecker.index_infoc                 C   r   )z/Set the information for index.html for `fname`.r   Nr   )r6   r   infor   r   r   r     r   z!IncrementalChecker.set_index_infoN)rj   rk   rl   rm   r   r   r9   r   r   r'   r   r   r   r   r   r   r   r   r   r   r   g  s    
r   c                 C   s   |  dd ddS )z\HTML-escape the text in `t`.

    This is only suitable for HTML text, not attributes.

    &z&amp;<z&lt;)replace)tr   r   r   rp     s   rp   c                 C   s   d|  S )zEFormat a pair of numbers so JavaScript can read them in an attribute.z%s %sr   )ratior   r   r   rq     s   rq   )#rm   r   r   r   r$   r   ra   r-   coverage.datar   coverage.exceptionsr   coverage.filesr   coverage.miscr   r   r   r   r	   r
   coverage.reportr   coverage.resultsr   coverage.templiter   r   r   r+   r,   rn   r   rp   rq   r   r   r   r   <module>   s6   N k 
