
    HeU[                       d Z ddlm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
Z
ddlmZ ddlmZmZmZmZ ddlZddlmZ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 m!Z!m"Z" ddl#m$Z$ ddl%m&Z&m'Z' ddl(m)Z) ddl*m+Z+m,Z, ddl-m.Z. er(ddlm/Z/ ddl0m1Z1 ddlm2Z2  G d de2      Z3 G d de2      Z4 ee      Zd+dZ5d+dZ6d,dZ7e G d d             Z8e G d d             Z9 G d d      Z: G d  d!      Z;e
jx                  e
jz                  z   d"z   Z> ej~                  d#      d-d$       Z@ G d% d&      ZA G d' d(      ZBd.d)ZCd/d*ZDy)0zHTML reporting for coverage.py.    )annotationsN)	dataclass)AnyIterableTYPE_CHECKINGcast)CoverageDataadd_data_to_hash)NoDataError)flat_rootname)
ensure_dirfile_be_goneHasherisolate_moduleformat_local_datetime)human_sortedpluralstdout_link)get_analysis_to_report)AnalysisNumbers)Templite)TLineNoTMorf)__url__)Coverage)FileReporter)	TypedDictc                  0    e Zd ZU dZded<   ded<   ded<   y)IndexInfoDictz4Information for each file, to render the index file.r   numsstrhtml_filenamerelative_filenameN__name__
__module____qualname____doc____annotations__     //usr/lib/python3/dist-packages/coverage/html.pyr    r    )   s    Br,   r    c                  &    e Zd ZU dZded<   ded<   y)FileInfoDictzHSummary of the information from last rendering, to avoid duplicate work.r"   hashr    indexNr%   r+   r,   r-   r/   r/   /   s    V	r,   r/   c                    t         j                  j                  t         j                  j                  t              d      }t         j                  j                  ||       }|S )z9Return the path to an "htmlfiles" data file of ours.
    	htmlfiles)ospathjoindirname__file__)fname
static_dirstatic_filenames      r-   data_filenamer<   8   s?     bggooh7EJggll:u5Or,   c                v    t        t        |             5 }|j                         cddd       S # 1 sw Y   yxY w)z+Return the contents of a data file of ours.N)openr<   read)r9   	data_files     r-   	read_datarA   @   s0    	mE"	#  y~~     s   /8c                    t        j                  dd|t         j                        dz   }t        | d      5 }|j	                  |j                  dd             ddd       y# 1 sw Y   yxY w)	z*Write `html` to `fname`, properly encoded.z(\A\s+)|(\s+$) )flags
wbasciixmlcharrefreplaceN)resub	MULTILINEr>   writeencode)r9   htmlfouts      r-   
write_htmlrP   F   sY    66#RR\\BTID	eT	 >d

4;;w(;<=> > >s   "A""A+c                      e Zd ZU dZded<   ded<   ded<   ded	<   d
ed<   ded<   d
ed<   d
ed<   d
ed<   dZded<   dZded<   dZded<   dZded<   dZ	ded<   y)LineDataz-The data for each source line of HTML output.zlist[tuple[str, str]]tokensr   numberr"   categorybool	statementz	list[str]contextscontexts_labelcontext_listshort_annotationslong_annotationsrC   rN   Nz
str | Nonecontext_strannotateannotate_long	css_class)
r&   r'   r(   r)   r*   rN   r]   r^   r_   r`   r+   r,   r-   rR   rR   M   si    7!!OMO  D#N"K"Hj $M:$Isr,   rR   c                  0    e Zd ZU dZded<   ded<   ded<   y)	FileDataz-The data for each source file of HTML output.r"   r$   r   r!   zlist[LineData]linesNr%   r+   r,   r-   rb   rb   `   s    7
Mr,   rb   c                  $    e Zd ZdZdZddZddZy)HtmlDataGenerationz8Generate structured data to be turned into HTML reports.z(empty)c                z   || _         | j                   j                  | _        | j                   j                         }|j                         | _        | j                  j                  r/|j                         dhk(  r| j                   j                  d       |j                  | j                  j                         y )NrC   zNo contexts were measured)	coverageconfigget_datahas_arcsshow_contextsmeasured_contexts_warnset_query_contextsreport_contexts)selfcovdatas      r-   __init__zHtmlDataGeneration.__init__m   s    mm**}}%%';;$$%%'B4/##$?@ ; ;<r,   c                     j                   r |j                         }|j                         } j                  j                  r%|j
                  j                  |j                        }g }t        |j                         d      D ]L  \  }}d}	g }
g }||j                  v rd}	n||j                  v rd}	n j                   rd|v r`d}	||   D ]U  }|dk  r|
j                  d       n|
j                  t        |             |j                  |j                  ||             W n||j                  v rd	}	g }d}g }|	rg j                  j                  rQt!         fd
j#                  |d      D              }| j$                  gk(  r j$                  }nt'        |       d}|}|j                  t)        |||	||j                  v ||||
|	             O t+        |j-                         |j.                  |      }|S )z.Produce the data needed for one file's report.   startrC   excmisparr   exitrunc              3  >   K   | ]  }|xs j                     y wN)EMPTY).0crp   s     r-   	<genexpr>z3HtmlDataGeneration.data_for_file.<locals>.<genexpr>   s     'dATZZ'ds   r+   z ctx)	rS   rT   rU   rW   rX   rY   rZ   r[   r\   )r$   r!   rc   )rj   missing_branch_arcsarcs_executedrh   rk   rr   contexts_by_linenofilename	enumeratesource_token_linesexcludedmissingappendr"   missing_arc_description
statementsr   getr   lenrR   rb   r$   numbers)rp   franalysisr   r   r   rc   linenorS   rU   r[   r\   brX   rY   rZ   	file_datas   `                r-   data_for_filez HtmlDataGeneration.data_for_filew   s   =="*">">"@$224M;;$$!)!A!A(BSBS!T'(=(=(?qI *	NFFH "!*** 8+++ 6-@#@ ,V4 bA1u)008)00Q8$++B,F,FvqR_,`ab 8... HNLDKK55''dASAWAWX^`bAc'dd

|+%)ZZN(+Hd%;N#+LLL!!X%8%88!-)"3!1
 
A*	X  224!!
	 r,   Nrq   r   returnNone)r   r   r   r   r   rb   )r&   r'   r(   r)   r   rs   r   r+   r,   r-   re   re   h   s    BE==r,   re   c                      e Zd ZdZddZy)FileToReportz#A file we're considering reporting.c                    || _         || _        t        |j                               | _        | j                  dz   | _        y )Nz.html)r   r   r   r$   rootnamer#   )rp   r   r   s      r-   rs   zFileToReport.__init__   s6     %b&:&:&<=!]]W4r,   N)r   r   r   r   r   r   )r&   r'   r(   r)   rs   r+   r,   r-   r   r      s
    -5r,   r   z!#$%'()*+,-./:;=?@[]^_`{|}~)maxsizec                    | dk(  r	t         d   S g }| r7t        | t        t                     \  } }|j                  t         |          | r7dj	                  |      S )zACreate a short HTML-safe string from an integer, using HTML_SAFE.r   rC   )	HTML_SAFEdivmodr   r   r6   )nrts      r-   
encode_intr      sV     	Av|
A
aY(1	1  771:r,   c                  P    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dZ
dd	Zy
)HtmlReporterzHTML reporting.)z	style.csszcoverage_html.jszkeybd_closed.pngzkeybd_open.pngzfavicon_32.pngc                b   || _         | j                   j                  | _        | j                  j                  | _        | j                  j                  | _        | j
                  | j                  j
                  | _        | j                  j                  | _        | j                  | j                  j                  | _        d| _        d| _	        | j                  j                  }|  | j                  j                  r9t        j                  j                  | j                  j                        | _        nd | _        | j                   j                         | _        | j                   j#                         | _        g | _        g | _        t)        | j                        | _        t-        | j                         | _        t1        | j                  j2                        | _        d| _        d | _        d | _        t<        t>        t@        tB        t         jD                  |tG        tH        jH                  jK                               | j                  | j"                  | j                  jL                  dddddd	| _'        tQ        d
      | _)        tU        | jR                  | jN                        | _+        y )Nr   )	precisionFzexc show_exczmis show_miszpar run show_parr|   )rx   ry   rz   r|   )escapepairr   r   __version__title
time_stamp	extra_cssrj   rk   rU   zpyfile.html),rg   rh   html_dir	directoryhtml_skip_coveredskip_coveredhtml_skip_empty
skip_emptyskipped_covered_countskipped_empty_count
html_titler   r4   r5   basenameri   rr   rj   file_summariesall_files_numsIncrementalCheckerincrre   datagenr   r   totalsdirectory_was_emptyfirst_frfinal_frr   r   r   r   r   r   datetimenowrk   template_globalsrA   pyfile_html_sourcer   source_tmpl)rp   rq   r   s      r-   rs   zHtmlReporter.__init__   s   mm**-- KK99$ $ 8 8D++55??""kk44DO%&"#$ &&;;  WW--dkk.C.CDDN!DNMM**,			**,35-/&t~~6	)$--8(=(=>#(   #///0A0A0E0E0GH![[66
 &%)	#!
0 #,M":#D$;$;T=R=RSr,   c                   | j                   j                          | j                   j                  | j                  | j                         g }t        | j                  |      D ]s  \  }}t        ||      }| j                  |      }|r|j                  |       7t        t        j                  j                  | j                  |j                               u t!        |      D ]X  \  }}|dk(  rd}n||dz
     j                  }|t#        |      dz
  k(  rd}	n||dz      j                  }	| j%                  |||	       Z | j&                  st)        d      t+        t,        t/        | j&                              | _        |r|d   j                  }
|d   j                  }ndx}
}| j3                  |
|       | j5                          | j0                  j6                  xr | j0                  j8                  S )zcGenerate an HTML report for `morfs`.

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

        r   
index.htmlru   zNo data to report.)r   r?   check_global_datarh   r   r   rg   r   should_report_filer   r   r4   r5   r6   r   r#   r   r   write_html_filer   r   r   r   sumr   
index_filemake_local_static_report_filesn_statements
pc_covered)rp   morfsfiles_to_reportr   r   ftrshouldi	prev_html	next_html
first_html
final_htmls               r-   reportzHtmlReporter.report  s    					##DKK1H1HI 24==%H 	NLBr8,C,,S1F&&s+RWW\\$..#:K:KLM	N  0 		<FAsAv(	+AE2@@	C(1,,(	+AE2@@	  i;		< ""2337C(;(;$<= (+99J(,::J&22J
J/++-{{''BDKK,B,BBr,   c                |    t        | j                         t        j                  | j                        sd| _        yy)z'Make sure our htmlcov directory exists.TN)r   r   r4   listdirr   rp   s    r-   make_directoryzHtmlReporter.make_directoryK  s+    4>>"zz$..)'+D$ *r,   c                   | j                   D ]I  }t        j                  t        |      t        j
                  j                  | j                  |             K | j                  rNt        t        j
                  j                  | j                  d      d      5 }|j                  d       ddd       | j                  ru| j                  j                  J t        j                  | j                  j                  t        j
                  j                  | j                  | j                               yy# 1 sw Y   xY w)z5Make local instances of static files for HTML report.z
.gitignorewz# Created by coverage.py
*
N)STATIC_FILESshutilcopyfiler<   r4   r5   r6   r   r   r>   rL   r   rh   )rp   staticfgis      r-   r   z+HtmlReporter.make_local_static_report_filesQ  s     '' 	YFOOM&1277<<PV3WX	Y ##bggll4>><@#F ;#		9:; >>;;((444OODKK11277<<PTP^P^3_` 	; ;s   D55D>c                P   |j                   j                  }| j                  j                  |       | j                  r8|j
                  dk(  }|j                  dk(  }|r|r| xj                  dz  c_        y| j                  r%|j                  dk(  r| xj                  dz  c_
        yy)z$Determine if we'll report this file.r   ru   FT)r   r   r   r   r   	n_missingn_partial_branchesr   r   r   r   )rp   r   r!   no_missing_linesno_missing_branchess        r-   r   zHtmlReporter.should_report_filec  s     ||##""4( $! 3#'#:#:a#?$7**a/*??  A%((A-(r,   c                   | j                          | j                  j                  | j                  |j                  |j
                        r?| j                  j                  | j                  j                  |j
                               y| j                  j                  |j                  |j                        }t        j                  d |j                  D              }t        d |j!                         D              D ci c]  \  }}||
 }}}|rCt#        j$                  |j'                         D 	
ci c]  \  }	}
t)        |
      |	 c}
}	d      }nd}|j                  D ]  g }j*                  D ]L  \  }}|dk(  r|j                  t-        |             &t-        |      xs d}|j                  d| d	| d
       N dj/                  |      _        j2                  rcj2                  D cg c]  }t)        ||          }}t5        d |D              t7              dj/                  fd|D              z   _        nd_        j:                  r*dj/                  fdj:                  D              _        nd_        j>                  rgj>                  }tA        |      dk(  r|d   _!        nIdjE                  tA        |      dj/                  d t        |d      D                    _!        nd_!        g }jF                  r+|j                  | jH                  d   jF                            dj/                  |      xs d_%         tL        jN                  j/                  | jP                  |jR                        }| jT                  jW                  i |jX                  |||d      }t[        ||       |j                  j\                  |jR                  |j                  j_                         d}| j                  j                  |       | j                  ja                  |j
                  |       yc c}}w c c}
}	w c c}w )z*Generate an HTML file for one source file.Nc              3  B   K   | ]  }|j                   D ]  }|   y wr~   )rX   )r   cliner   s      r-   r   z/HtmlReporter.write_html_file.<locals>.<genexpr>  s      &^Uu~~&^!q&^q&^s   c              3  &   K   | ]	  }|d      yw)r   Nr+   )r   xs     r-   r   z/HtmlReporter.write_html_file.<locals>.<genexpr>  s     5[qad5[s      )indentwsz&nbsp;z<span class="z">z</span>rC   c              3  2   K   | ]  }t        |        y wr~   )r   )r   ecs     r-   r   z/HtmlReporter.write_html_file.<locals>.<genexpr>  s      DRR D   c              3  @   K   | ]  }|j                          y wr~   )ljust)r   r   
code_widths     r-   r   z/HtmlReporter.write_html_file.<locals>.<genexpr>  s     Nrbhhz2N   z,&nbsp;&nbsp; c              3  @   K   | ]  }j                    d |   yw)z&#x202F;&#x219B;&#x202F;N)rT   )r   dldatas     r-   r   z/HtmlReporter.write_html_file.<locals>.<genexpr>  s)      7 ||n$<QC@7r   ru   r   z{:d} missed branches: {}z, c              3  2   K   | ]  \  }}|d d|   yw)r   z) Nr+   )r   numann_longs      r-   r   z/HtmlReporter.write_html_file.<locals>.<genexpr>  s)      " -X  #1gRz2"r   rv   rU    pln)contexts_jsonr   r   )r!   r#   r$   )1r   r   can_skip_filerr   r   r   r   r   
index_infor   r   r   collectionsCounterrc   r   most_commonjsondumpsitemsr   rS   r   r6   rN   rZ   maxr"   r]   r[   r^   r\   r   r_   formatrU   r   r`   r4   r5   r   r#   r   render__dict__rP   r   r$   set_index_info)rp   r   r   r   r   rX   r   ycontext_codeskvr  
html_partstok_typetok_texttok_html	c_contextencoded_contextslongscss_classes	html_pathrN   r  r   r   s                          @@r-   r   zHtmlReporter.write_html_filez  s    99""499cffcllC&&tyy';';CLL'IJ LL..svvs||D	&&&^ioo&^^,55[HDXDXDZ5[,[\&1aA\\ JJ0=0C0C0EFfq!A!FM
 !M__ 4	=EJ&+ll U"(t#%%fX&67%h/;8H%%hZr(7&STU ,EJ!!JOJ\J\$=FJ}Y78$  $ ! D3C DD

OggN=MNNO !
 %'!&& "2!6!6 7"447 "
 "&%%..u:?*/(E'*D*K*KE
		 "1:51J" +E' '+#K~~""))*5ennE "hh{3<uEOi4	=l GGLL1B1BC	&& (
  (
*""	(
  	9d# LL(( ..!$!9!9!;%


 	"":.		  z:_ ] G"$s   Q:Q
:Qc           	        | j                          t        t        d      | j                        }dx}}| j                  r| j                  }| dt        |       d}| j                  r| j                  }| dt        |       d}|j                  | j                  | j                  ||||d      }t        j                  j                  | j                  d      }t        ||       t        |dt        j                  j!                  |             }	| j"                  j%                  d	|	        | j&                  j)                          y
)z*Write the index.html file for this report.r   rC   z filez" skipped due to complete coverage.z empty filez	 skipped.)filesr   skipped_covered_msgskipped_empty_msgr   r   zfile://zWrote HTML report to N)r   r   rA   r   r   r   r   r  r   r   r4   r5   r6   r   rP   r   abspathrg   _messager   rL   )
rp   r   r   
index_tmplr!  r"  r   rN   r   
print_hrefs
             r-   r   zHtmlReporter.index_file  s(   i5t7L7LM
244/%%**A%&CuVAYK7Y"Z##((A#$#[9 E  ((kk#6!2$$"
  WW\\$..,?
:t$ wrwwz7R6S-TU
!6zlCD 			r,   Nr   )r   zIterable[TMorf] | Noner   floatr   r   )r   r   r   rV   )r   r   r   r"   r   r"   r   r   )r   r"   r   r"   r   r   )r&   r'   r(   r)   r   rs   r   r   r   r   r   r   r+   r,   r-   r   r      s6    L;Tz0Cd,a$.\;|r,   r   c                  l    e Zd 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y)r   z0Logic and data to support incremental reporting.zstatus.jsonr   zThis file is an internal implementation detail to speed up HTML report generation. Its format can change at any time. You might be looking for the JSON report: https://coverage.rtfd.io/cmd.html#cmd-jsonc                2    || _         | j                          y r~   )r   reset)rp   r   s     r-   rs   zIncrementalChecker.__init__  s    "

r,   c                     d| _         i | _        y)z5Initialize to empty. Causes all files to be reported.rC   N)globalsr   r   s    r-   r+  zIncrementalChecker.reset"  s    .0
r,   c                .   d}	 t         j                  j                  | j                  | j                        }t        |      5 }t        j                  |      }ddd       d}d   | j                  k7  rd}n|d   t        j                  k7  rd}	 |rPi | _        d   j                         D ](  \  }}t        |d   d    |d   d<   || j                  |<   * |d	   | _        y| j#                          y# 1 sw Y   xY w# t        t        f$ r d}Y w xY w)
z)Read the information we stored last time.FNTr  versionr   r1   r!   r-  )r4   r5   r6   r   STATUS_FILEr>   r
  loadSTATUS_FORMATrg   r   OSError
ValueErrorr   r  r   r-  r+  )rp   usablestatus_filefstatusstatusr   fileinfos          r-   r?   zIncrementalChecker.read'  s   	'',,t~~t7G7GHKk" ,g7+,
 Fh4#5#55	"h&:&::DJ&,Wo&;&;&= 0"(,3Xg5Fv5N,O!&)'/

8$0 "),DLJJL%, ,$ 	F	s)   ?D  C4D  4C=9D   DDc                   t         j                  j                  | j                  | j                        }i }| j
                  j                         D ]%  \  }}|d   }|d   j                         |d<   |||<   ' | j                  | j                  t        j                  | j                  |d}t        |d      5 }t        j                  ||d       ddd       y# 1 sw Y   yxY w)zWrite the current status.r1   r!   )noter  r/  r-  r   r   ),:)
separatorsN)r4   r5   r6   r   r0  r   r  	init_argsNOTEr2  rg   r   r-  r>   r
  dump)rp   r6  r   r   r9  r1   r8  rO   s           r-   rL   zIncrementalChecker.write@  s    ggll4>>43C3CD"&**"2"2"4 	'HhW%E!&M335E&M&E(O	' II((++||
 +s# 	;tIIfdz:	; 	; 	;s   9CC$c                    t               }|D ]  }|j                  |        |j                         }| j                  |k7  r| j	                          || _        yy)z<Check the global data that can affect incremental reporting.N)r   update	hexdigestr-  r+  )rp   rr   mr   these_globalss        r-   r   z$IncrementalChecker.check_global_dataS  sO    H 	AHHQK	<<=(JJL(DL )r,   c                   t               }|j                  |j                         j                  d             t	        ||j
                  |       |j                         }| j                  |      }||k(  ry| j                  ||       y)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   rC  sourcerM   r
   r   rD  	file_hashset_file_hash)rp   rr   r   r   rE  	this_hash	that_hashs          r-   r  z IncrementalChecker.can_skip_file]  so     H	##G,-r{{A.KKM	NN8,		!x3r,   c                Z    | j                   j                  |i       j                  dd      S )z#Get the hash of `fname`'s contents.r0   rC   r   r   rp   r9   s     r-   rI  zIncrementalChecker.file_hashq  s$    zz~~eR(,,VR88r,   c                B    || j                   j                  |i       d<   y)z#Set the hash of `fname`'s contents.r0   Nr   
setdefault)rp   r9   vals      r-   rJ  z IncrementalChecker.set_file_hashu  s    36

eR(0r,   c                Z    | j                   j                  |i       j                  di       S )z/Get the information for index.html for `fname`.r1   rN  rO  s     r-   r  zIncrementalChecker.index_infoy  s$    zz~~eR(,,Wb99r,   c                B    || j                   j                  |i       d<   y)z/Set the information for index.html for `fname`.r1   NrQ  )rp   r9   infos      r-   r  z!IncrementalChecker.set_index_info}  s    48

eR(1r,   N)r   r"   r   r   r(  )rr   r   r   r   )rr   r	   r   r   r   r"   r   rV   r9   r"   r   r"   )r9   r"   rS  r"   r   r   )r9   r"   r   r    )r9   r"   rV  r    r   r   )r&   r'   r(   r)   r0  r2  r@  rs   r+  r?   rL   r   r  rI  rJ  r  r  r+   r,   r-   r   r     sM    :KM	M 	B1
2;&)(97:9r,   r   c                F    | j                  dd      j                  dd      S )z\HTML-escape the text in `t`.

    This is only suitable for HTML text, not attributes.

    &z&amp;<z&lt;)replace)r   s    r-   r   r     s"     99S'"**377r,   c                      dj                   |  S )zEFormat a pair of numbers so JavaScript can read them in an attribute.z{} {})r  )ratios    r-   r   r     s    7>>5!!r,   rW  )r9   r"   rN   r"   r   r   )r   intr   r"   )r   r"   r   r"   )r]  ztuple[int, int]r   r"   )Er)   
__future__r   r  r   	functoolsr
  r4   rI   r   stringdataclassesr   typingr   r   r   r   rg   coverage.datar	   r
   coverage.exceptionsr   coverage.filesr   coverage.miscr   r   r   r   r   r   r   r   coverage.report_corer   coverage.resultsr   r   coverage.templiter   coverage.typesr   r   coverage.versionr   r   coverage.pluginsr   r   r    r/   r<   rA   rP   rR   rb   re   r   ascii_lettersdigitsr   	lru_cacher   r   r   r   r   r+   r,   r-   <module>rq     s@   & "     	 	   ! 5 5  8 + ( a a ; ; 7 . & ) $ !- !	 y  B >   $   L L^5 5   6==03PP	T"	 #	f fR	G9 G9X8"r,   