B
    `f                 @   sT   d 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	 G dd de
ZdS )zJson reporting for coverage.py    N)__version__)get_analysis_to_report)Numbersc               @   s*   e Zd ZdZdd Zd	ddZdd ZdS )
JsonReporterz-A reporter for writing JSON coverage results.c             C   s"   || _ | j j| _t | _i | _d S )N)coverageconfigr   totalreport_data)selfr    r   [/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/coverage/jsonreport.py__init__   s    
zJsonReporter.__init__Nc             C   s  |pt j}| j }|| jj ttj	 
 | | jjd| jd< i }x,t| j|D ]\}}| |||| < qZW || jd< | jj| jj| jj| jj| jjd| jd< | r| jd | jj| jj| jj| jjd tj| j|| jjrdndd	 | jjo| 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

        )version	timestampZbranch_coverageZshow_contextsmetafiles)covered_linesnum_statementspercent_coveredmissing_linesexcluded_linesZtotals)num_branchesnum_partial_branchescovered_branchesmissing_branches   N)indent)sysstdoutr   get_dataZset_query_contextsr   Zreport_contextsr   datetimenow	isoformathas_arcsjson_show_contextsr	   r   report_one_fileZrelative_filenamer   
n_executedn_statements
pc_covered	n_missing
n_excludedupdate
n_branchesn_partial_branchesn_executed_branchesn_missing_branchesjsondumpZjson_pretty_print)r
   Zmorfsoutfilecoverage_dataZmeasured_filesZfile_reporteranalysisr   r   r   report   s:    



zJsonReporter.reportc             C   s   |j }|  j|7  _|j|j|j|j|jd}t|j|t|j	t|j
d}| jjrh|j|j|d< | r|d |j|j|j|jd |S )z2Extract the relevant report data for a single file)r   r   r   r   r   )Zexecuted_linessummaryr   r   Zcontextsr6   )r   r   r   r   )Znumbersr   r&   r'   r(   r)   r*   sortedZexecutedmissingZexcludedr   r$   dataZcontexts_by_linenofilenamer#   r+   r,   r-   r.   r/   )r
   r3   r4   numsr6   Zreported_filer   r   r   r%   K   s*    
zJsonReporter.report_one_file)N)__name__
__module____qualname____doc__r   r5   r%   r   r   r   r   r      s   
3r   )r?   r    r0   r   r   r   Zcoverage.reportr   Zcoverage.resultsr   objectr   r   r   r   r   <module>   s   