B
    =cm&                 @   sR   d 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
 G dd dZdS )	zSummary reporting    N)ConfigErrorNoDataError)human_sorted_items)get_analysis_to_report)Numbersc               @   sX   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zde	dddZ
dd Zdd ZdS )SummaryReporterz*A reporter for writing the summary report.c             C   sr   || _ | j j| _|  | _d | _| jjp.d| _| jdkrLtd| jg | _	d| _
d| _t| jjd| _d S )Ntext>   totalmarkdownr   zUnknown report format choice: r   )	precision)coverageconfigget_dataZhas_arcsbranchesoutfileformatoutput_formatr   fr_analysisskipped_countempty_countr   r   r	   )selfr    r   A/var/www/cleansys/lib/python3.7/site-packages/coverage/summary.py__init__   s    

zSummaryReporter.__init__c             C   s    | j |  | j d dS )z-Write a line to the output, adding a newline.
N)r   writerstrip)r   liner   r   r   r      s    zSummaryReporter.writec             C   s   |  d| dS )z)Write a list of strings, joined together. N)r   join)r   itemsr   r   r   write_items#   s    zSummaryReporter.write_itemsc          	      sN  t dd |D dg d t t|d d tdd t gfdd|D  td	d
d
d
d
ddd  fddD }d|}dt| }| | | |  jtdddd x2|D ]*} fddt|D }	| |	 qW |r
| |  fddt|D }	| |	 x|D ]}
| |
 q6W dS )a:  Internal method that prints report data in text format.

        `header` is a list with captions.
        `lines_values` is list of lists of sortable values.
        `total_line` is a list with values of the total line.
        `end_lines` is a list of ending lines with information about skipped files.

        c             S   s   g | ]}t |d  qS )r   )len).0r   r   r   r   
<listcomp>1   s    z0SummaryReporter._report_text.<locals>.<listcomp>      Cover   z Coverc                s"   g | ]}t | d  d qS )r'   r(   )r"   index)r#   r   )headerr   r   r$   3   s    z{:{name_len}}z{:>7}z{:>{n}}z{:>10})NameStmtsMissBranchBrPartr'   Missingc                s    g | ]} | j |d qS ))name_lenn)r   )r#   item)formatsmax_nmax_namer   r   r$   >   s   r   -z{:>{n}}%)r'   z   {:9})r0   c                s,   g | ]$\}} | j t|d  dqS )r&   )r1   r2   )r   str)r#   r3   value)r4   r5   r6   r   r   r$   L   s   c                s,   g | ]$\}} | j t|d  dqS )r&   )r1   r2   )r   r8   )r#   r3   r9   )r4   r5   r6   r   r   r$   V   s   N)	maxr"   r)   dictr   r   updatezipr!   )r   r*   lines_values
total_line	end_linesheader_items
header_strrulevalues
line_itemsend_liner   )r4   r*   r5   r6   r   _report_text'   s:    
$






zSummaryReporter._report_textc          	      s  t dd |D ddt tdd tdddddd	d
d t t||d d td fdd|D }d|}dddt|d d dgdd |dd D   }| | | | xB|D ]:} tdd  fddt||D }	| 	|	 qW  tdd	d g }
xdt||D ]V\}}|dkrJ|}n$|dkrbd| d}nd| d}|
 | j
|d 7 }
q2W | 	|
 x|D ]}| | qW dS )!aT  Internal method that prints report data in markdown format.

        `header` is a list with captions.
        `lines_values` is a sorted list of lists containing coverage information.
        `total_line` is a list with values of the total line.
        `end_lines` is a list of ending lines with information about skipped files.

        c             s   s"   | ]}t |d  ddV  qdS )r   _z\_N)r"   replace)r#   r   r   r   r   	<genexpr>h   s    z3SummaryReporter._report_markdown.<locals>.<genexpr>r   )defaultz	**TOTAL**r&   z| {:{name_len}}|z{:>9} |z	{:>{n}} |z{:>10} |)r+   r,   r-   r.   r/   r'   r0   r'      z Cover c                s    g | ]} | j |d qS ))r1   r2   )r   )r#   r3   )r4   r5   r6   r   r   r$   t   s    z4SummaryReporter._report_markdown.<locals>.<listcomp>r   | z- |r7   c             S   s    g | ]}d  t|d dqS )z-: |r&   r7   )rjustr"   )r#   r3   r   r   r   r$   w   s    Nz
{:>{n}}% |)r'   c                s4   g | ],\}} | j t|d dd dqS )rH   z\_r&   )r1   r2   )r   r8   rI   )r#   r3   r9   )r4   r5   r6   r   r   r$      s   z|{:>{name_len}} |)r+   r'   z **z%**z**)r1   r2   )r:   r"   r;   r)   r   rO   r   r<   r=   r!   r   )r   r*   r>   r?   r@   rA   rB   Zrule_strrD   rE   Ztotal_line_itemsr3   r9   insertrF   r   )r4   r5   r6   r   _report_markdown^   sD    
 







z SummaryReporter._report_markdownN)returnc             C   s   |pt j| _| j | jj x$t| j|D ]\}}| 	|| q.W | j
js\| js\td| jdkrv| | j
j n|   | j
jS )zWrites a report summarizing coverage statistics per module.

        `outfile` is a text-mode file object to write the summary to.

        zNo data to report.r	   )sysstdoutr   r   r   Zset_query_contextsr   Zreport_contextsr   report_one_filer	   Zn_filesr   r   r   r   pc_covered_strtabular_report
pc_covered)r   Zmorfsr   franalysisr   r   r   report   s    
zSummaryReporter.reportc                s  dddg}| j r|ddg7 }|dg7 }| jjr8|dg7 }tdd	d
dd}| j r`|tddd g }x|| jD ]r\}}|j}| |j|j	g}| j r||j
|jg7 }||jg7 }| jjr||jddg7 }||jg7 }|| qlW | jjpd }d}	|d dkrd}	|d	d }n|d dkr0|d	d }||  dkrVtd| jj|dkrnt||	d}n|j fdd|	d d| jj| jj	g}
| j r|
| jj
| jjg7 }
|
| jjg7 }
| jjr|
dg7 }
g }| jjr| jr| jd	krdnd}|d| j d | d! | jjrX| jrX| jd	kr:dnd}|d| j d"| d# | jd$krl| j}n| j}||||
| dS )%zWrites tabular report formats.r+   r,   r-   r.   r/   r'   r0   r   r&   r(   )nameZstmtsZmissZcover      )branchZbrpartT)r   r]   Fr7   N+zInvalid sorting option: )reversec                s   |   | d fS )Nr   r   )r   )sort_idxr   r   <lambda>       z0SummaryReporter.tabular_report.<locals>.<lambda>)keyrb   ZTOTALr   sr   z filez" skipped due to complete coverage.z empty filez	 skipped.r
   )r   r   Zshow_missingr;   r<   r   numbersZrelative_filenamen_statements	n_missingZ
n_branchesn_partial_branchesrV   Zmissing_formattedrX   appendsortlowergetr   r   r	   skip_coveredr   
skip_emptyr   r   rQ   rG   )r   r*   Zcolumn_orderr>   rY   rZ   numsargsZsort_optionrb   r?   r@   Zfile_suffix	formatterr   )rc   r   rW      sf    







zSummaryReporter.tabular_reportc             C   s~   |j }|  j|7  _|jdk}|jdk}| jjrH|rH|rH|  jd7  _n2| jjrj|jdkrj|  j	d7  _	n| j
||f dS )z4Report on just one file, the callback from report().r   r&   N)rh   r	   rj   rk   r   rp   r   rq   ri   r   r   rl   )r   rY   rZ   rr   Zno_missing_linesZno_missing_branchesr   r   r   rU      s    

zSummaryReporter.report_one_file)N)__name__
__module____qualname____doc__r   r   r!   rG   rQ   floatr[   rW   rU   r   r   r   r   r      s   78Fr   )rx   rS   Zcoverage.exceptionsr   r   Zcoverage.miscr   Zcoverage.reportr   Zcoverage.resultsr   r   r   r   r   r   <module>   s   