
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3

  \=p  ã               @   s(  d dg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	Z	ddl
Z
ddlZddlmZ yddlZW n" ek
rš   ejZdd„ ZY nX dd„ Zd	d„ Zd
ZG dd„ dƒZdd„ Zdd„ ZG dd„ dƒZdd„ Zdd„ Zddd„Zdd„ ZG dd „ d ƒZdd„ Zedk�r$eƒ  dS )ÚTraceÚCoverageResultsé    N)Ú	monotonicc               C   s   t jd ƒ d S )N)ÚsysÚsettrace© r   r   ú/usr/lib64/python3.6/trace.pyÚ_unsettraceE   s    r	   c             C   s   t j| ƒ tj| ƒ d S )N)Ú	threadingr   r   )Úfuncr   r   r   Ú	_settraceH   s    
r   c               C   s   t jd ƒ tjd ƒ d S )N)r   r   r
   r   r   r   r   r	   L   s    
z#pragma NO COVERc               @   s   e Zd Zddd„Zdd„ ZdS )Ú_IgnoreNc             C   s:   |s
t ƒ nt |ƒ| _|sg ndd„ |D ƒ| _ddi| _d S )Nc             S   s   g | ]}t jj|ƒ‘qS r   )ÚosÚpathÚnormpath)Ú.0Údr   r   r   ú
<listcomp>U   s   z$_Ignore.__init__.<locals>.<listcomp>z<string>é   )ÚsetÚ_modsÚ_dirsÚ_ignore)ÚselfÚmodulesÚdirsr   r   r   Ú__init__S   s    
z_Ignore.__init__c             C   sª   || j kr| j | S || jkr,d| j |< dS x*| jD ] }|j|d ƒr4d| j |< dS q4W |d krnd| j |< dS x,| jD ]"}|j|tj ƒrvd| j |< dS qvW d| j |< dS )Nr   Ú.r   )r   r   Ú
startswithr   r   Úsep)r   ÚfilenameÚ
modulenameÚmodr   r   r   r   ÚnamesY   s$    







z_Ignore.names)NN)Ú__name__Ú
__module__Ú__qualname__r   r#   r   r   r   r   r   R   s   
r   c             C   s    t jj| ƒ}t jj|ƒ\}}|S )N)r   r   ÚbasenameÚsplitext)r   Úbaser    Úextr   r   r   Ú_modname„   s    r+   c             C   sÆ   t jj| ƒ}d}xJtjD ]@}t jj|ƒ}|j|ƒr|t|ƒ t jkrt|ƒt|ƒkr|}qW |rv| t|ƒd d … }n| }t jj|ƒ\}}|jt jdƒ}t j	r¬|jt j	dƒ}t jj
|ƒ\}}|jdƒS )NÚ r   r   )r   r   Únormcaser   r   Úlenr   Ú
splitdriveÚreplaceÚaltsepr(   Úlstrip)r   ZcomparepathZlongestÚdirr)   Zdriver    r*   r   r   r   Ú_fullmodname‹   s     r4   c               @   s:   e Zd Zddd„Zdd„ Zdd„ Zdd
d„Zddd„ZdS )r   Nc             C   sþ   || _ | j d kri | _ | j jƒ | _|| _| jd kr8i | _| jjƒ | _|| _| jd krZi | _| jjƒ | _|| _|| _| jrúy@t| jdƒ�}tj	|ƒ\}}}W d Q R X | j
| j|||ƒƒ W n@ tttfk
rø } ztd| j|f tjd� W Y d d }~X nX d S )NÚrbzSkipping counts file %r: %s)Úfile)ÚcountsÚcopyZcounterÚcalledfuncsÚcallersÚinfileÚoutfileÚopenÚpickleÚloadÚupdateÚ	__class__ÚOSErrorÚEOFErrorÚ
ValueErrorÚprintr   Ústderr)r   r7   r9   r;   r:   r<   ÚfÚerrr   r   r   r   ¨   s,    


zCoverageResults.__init__c             C   s   |j dƒo|jdƒS )Nú<ú>)r   Úendswith)r   r    r   r   r   Úis_ignored_filenameÂ   s    z#CoverageResults.is_ignored_filenamec       	      C   sz   | j }| j}| j}|j }|j}|j}x$|D ]}|j|dƒ||  ||< q*W x|D ]}d||< qPW x|D ]}d||< qfW d S )Nr   r   )r7   r9   r:   Úget)	r   Úotherr7   r9   r:   Zother_countsZother_calledfuncsZother_callersÚkeyr   r   r   r@   È   s    


zCoverageResults.updateTFc       !      C   sô  | j rDtƒ  tdƒ | j }x(t|ƒD ]\}}}td|||f ƒ q$W | jrØtƒ  tdƒ d }}	xvt| jƒD ]h\\}
}}\}}}|
|kr¢tƒ  td|
dƒ |
}d}	||
krÀ|	|krÀtd|ƒ |}	td||||f ƒ qlW i }x8| jD ].\}}|j|i ƒ }||< | j||f ||< qäW i }�x$|jƒ D �]\}}| j|ƒ�r@�q&|jdƒ�rX|d d… }|d k�r€t	j
jt	j
j|ƒƒ}t|ƒ}n$|}t	j
j|ƒ�sœt	j|ƒ t|ƒ}|�r´t|ƒ}ni }tj|ƒ}t	j
j||d
 ƒ}t|dƒ�}tj|jƒ\}}W d Q R X | j|||||ƒ\}}|�r&|�r&td| | ƒ}||||f||< �q&W |�rŠ|�rŠtdƒ x2t|ƒD ]&}|| \}}}}td||  ƒ �q`W | j�rðy&tj| j| j | jft| jdƒd	ƒ W n6 tk
�rî }  ztd|  tj d� W Y d d } ~ X nX d S )Nzfunctions called:z*filename: %s, modulename: %s, funcname: %szcalling relationships:r,   z***z  -->z    %s.%s -> %s.%sz.pycr   z.coverr5   éd   zlines   cov%   module   (path)z%5d   %3d%%   %s   (%s)Úwbz"Can't save counts files because %s)r6   éÿÿÿÿ)!r9   rE   Úsortedr:   r7   rM   ÚitemsrL   rK   r   r   ÚdirnameÚabspathr+   ÚexistsÚmakedirsr4   Ú_find_executable_linenosÚ	linecacheÚgetlinesÚjoinr=   ÚtokenizeÚdetect_encodingÚreadlineÚwrite_results_fileÚintr<   r>   ÚdumprB   r   rF   )!r   Zshow_missingÚsummaryÚcoverdirZcallsr    r!   ÚfuncnameZlastfileZ	lastcfileZpfileZpmodZpfuncÚcfileZcmodZcfuncZper_fileÚlinenoÚ	lines_hitZsumsÚcountr3   ÚlnotabÚsourceZ	coverpathÚfpÚencodingÚ_Ún_hitsÚn_linesZpercentÚmrH   r   r   r   Úwrite_resultsÚ   s|    






zCoverageResults.write_resultsc             C   sì   yt |d|d�}W n6 tk
rH } ztd||f tjd� dS d }~X nX d}d}	|�ˆ x€t|dƒD ]r\}
}|
|kr˜|jd||
  ƒ |	d7 }	|d7 }n.|
|kr¼t|kr¼|jdƒ |d7 }n
|jd	ƒ |j|jd
ƒƒ qdW W d Q R X |	|fS )NÚw)rm   z3trace: Could not open %r for writing: %s - skipping)r6   r   r   z%5d: z>>>>>> z       é   )r   r   )	r=   rB   rE   r   rF   Ú	enumerateÚwriteÚPRAGMA_NOCOVERÚ
expandtabs)r   r   Úlinesrj   rh   rm   r<   rH   rp   ro   rg   Úliner   r   r   r`   5  s(    



z"CoverageResults.write_results_file)NNNNN)TFN)N)r$   r%   r&   r   rL   r@   rr   r`   r   r   r   r   r   §   s    

[c             C   s0   i }x&t j| ƒD ]\}}||krd||< qW |S )Nr   )ÚdisZfindlinestarts)ÚcodeÚstrsÚlinenosrn   rg   r   r   r   Ú_find_lines_from_codeU  s
    r   c             C   s8   t | |ƒ}x(| jD ]}tj|ƒr|jt||ƒƒ qW |S )N)r   Ú	co_constsÚinspectZiscoder@   Ú_find_lines)r|   r}   r~   Úcr   r   r   r‚   _  s
    

r‚   c             C   s’   i }t j}t| |d��r}tj|jƒ}x^|D ]V\}}}}	}
|t jkr||t jkr||\}}|	\}}xt||d ƒD ]}d||< qlW |}q*W W d Q R X |S )N)rm   r   )ÚtokenÚINDENTr=   r]   Úgenerate_tokensr_   ÚSTRINGÚrange)r    rm   r   Z
prev_ttyperG   ÚtokZttypeZtstrÚstartÚendrz   ZslineZscolZelineZecolÚir   r   r   Ú_find_stringsk  s    

r�   c             C   s€   y(t j| ƒ�}|jƒ }|j}W d Q R X W n6 tk
r^ } ztd| |f tjd� i S d }~X nX t|| dƒ}t	| |ƒ}t
||ƒS )Nz%Not printing coverage data for %r: %s)r6   Úexec)r]   r=   Úreadrm   rB   rE   r   rF   Úcompiler�   r‚   )r    rG   Úprogrm   rH   r|   r}   r   r   r   rY   ‚  s    
rY   c            	   @   s‚   e Zd Zddddf f dddf	dd„Zdd„ Zd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   r   r   NFc
       
      C   sÀ   || _ || _t||ƒ| _i | _i | _d| _|| _i | _i | _	i | _
d | _|	rTtƒ | _|rb| j| _nZ|rp| j| _nL|rŠ|rŠ| j| _| j| _n2|r | j| _| j| _n|r¶| j| _| j| _nd| _d S )Nr   r   )r;   r<   r   Úignorer7   ZpathtobasenameÚ	donothingÚtraceÚ_calledfuncsÚ_callersÚ_caller_cacheÚ
start_timeÚ_timeÚglobaltrace_trackcallersÚglobaltraceÚglobaltrace_countfuncsÚglobaltrace_ltÚlocaltrace_trace_and_countÚ
localtraceÚlocaltrace_traceÚlocaltrace_count)
r   ri   r”   Ú
countfuncsÚcountcallersÚ
ignoremodsÚ
ignoredirsr;   r<   Útimingr   r   r   r   ‘  s6    




zTrace.__init__c             C   s    dd l }|j}| j|||ƒ d S )Nr   )Ú__main__Ú__dict__Úrunctx)r   Úcmdr§   Údictr   r   r   ÚrunÃ  s    z	Trace.runc          
   C   sL   |d kri }|d kri }| j s(t| jƒ zt|||ƒ W d | j sFtƒ  X d S )N)r“   r   r›   rŽ   r	   )r   rª   ÚglobalsÚlocalsr   r   r   r©   È  s      
zTrace.runctxc             O   s<   d }| j stj| jƒ z|||Ž}W d | j s6tjd ƒ X |S )N)r“   r   r   r›   )r   r   ÚargsÚkwÚresultr   r   r   ÚrunfuncÓ  s    zTrace.runfuncc       
      C   sð   |j }|j}|rt|ƒ}nd }|j}d }|| jkrL| j| d k	rÒ| j| }n†d | j|< dd„ tj|ƒD ƒ}t|ƒdkrÒdd„ tj|d ƒD ƒ}t|ƒdkrÒdd„ tj|d ƒD ƒ}	t|	ƒdkrÒ|	d j}|| j|< |d k	ræd||f }|||fS )Nc             S   s   g | ]}t j|ƒr|‘qS r   )r�   Z
isfunction)r   rG   r   r   r   r   ï  s    z1Trace.file_module_function_of.<locals>.<listcomp>r   c             S   s   g | ]}t |tƒr|‘qS r   )Ú
isinstancer«   )r   r   r   r   r   r   õ  s    r   c             S   s   g | ]}t |d ƒr|‘qS )Ú	__bases__)Úhasattr)r   rƒ   r   r   r   r   ø  s    z%s.%s)	Úf_codeÚco_filenamer+   Úco_namer—   ÚgcZget_referrersr.   r$   )
r   Úframer|   r    r!   re   ZclsnameZfuncsZdictsÚclassesr   r   r   Úfile_module_function_ofÞ  s,    




zTrace.file_module_function_ofc             C   s0   |dkr,| j |ƒ}| j |jƒ}d| j||f< d S )NÚcallr   )r¼   Úf_backr–   )r   rº   ÚwhyÚargÚ	this_funcZparent_funcr   r   r   rš     s    
zTrace.globaltrace_trackcallersc             C   s    |dkr| j |ƒ}d| j|< d S )Nr½   r   )r¼   r•   )r   rº   r¿   rÀ   rÁ   r   r   r   rœ     s    
zTrace.globaltrace_countfuncsc             C   sj   |dkrf|j }|jjdd ƒ}|rbt|ƒ}|d k	rf| jj||ƒ}|sf| jrZtd||jf ƒ | j	S nd S d S )Nr½   Ú__file__z! --- modulename: %s, funcname: %s)
r¶   Ú	f_globalsrM   r+   r’   r#   r”   rE   r¸   rŸ   )r   rº   r¿   rÀ   r|   r    r!   Z	ignore_itr   r   r   r�     s    zTrace.globaltrace_ltc             C   s„   |dkr~|j j}|j}||f}| jj|dƒd | j|< | jrTtdtƒ | j  dd� tj	j
|ƒ}td||tj||ƒf dd� | jS )	Nrz   r   r   z%.2fú )r‹   z
%s(%d): %sr,   )r¶   r·   Úf_linenor7   rM   r˜   rE   r™   r   r   r'   rZ   ÚgetlinerŸ   )r   rº   r¿   rÀ   r    rg   rO   Úbnamer   r   r   rž   2  s    z Trace.localtrace_trace_and_countc             C   sd   |dkr^|j j}|j}| jr4tdtƒ | j  dd� tjj|ƒ}td||t	j
||ƒf dd� | jS )Nrz   z%.2frÄ   )r‹   z
%s(%d): %sr,   )r¶   r·   rÅ   r˜   rE   r™   r   r   r'   rZ   rÆ   rŸ   )r   rº   r¿   rÀ   r    rg   rÇ   r   r   r   r    A  s    zTrace.localtrace_tracec             C   s<   |dkr6|j j}|j}||f}| jj|dƒd | j|< | jS )Nrz   r   r   )r¶   r·   rÅ   r7   rM   rŸ   )r   rº   r¿   rÀ   r    rg   rO   r   r   r   r¡   N  s    zTrace.localtrace_countc             C   s   t | j| j| j| j| jd�S )N)r;   r<   r9   r:   )r   r7   r;   r<   r•   r–   )r   r   r   r   ÚresultsV  s    
zTrace.results)NN)r$   r%   r&   r   r¬   r©   r²   r¼   rš   rœ   r�   rž   r    r¡   rÈ   r   r   r   r   r   �  s   0
)	c                 s’  t jƒ } | jdddd� | jddƒ}|jddd	d
d� |jddd	dd� |jddd	dd� |jddd	dd� | jdƒ}|jƒ }|jddd	dd� |jddd	dd� |jdddd� |jd d!d"d� |jd#d$d	d%d� |jd&d'd	d(d� |jd)d*d	d+d� | jd,d-ƒ}|jd.d/g d0d1� |jd2d/g d3d1� | jd4d5d6d7� | jd8t jd9d7� | jƒ }|j�r’d:d;jt	j
ƒf}tjjt	jf|žŽ ‰tjjt	jf|žŽ ‰ ‡ ‡fd<d=„‰d>d?„ |jD ƒ|_‡fd@d?„|jD ƒ|_|j�r|j�sâ| jdAƒ t|j|jdB�}|j|j|j|jƒS t|j|j|j|jgƒ�s*| jdCƒ |j�rL|j�sB|j�rL| jdDƒ |j�rh|j �rh| jdEƒ |jd k�r~| jdFƒ |jf|j•t	_ tjj!|jƒt	jdG< t"|j|j|j|j|j|j|j|j|j#dH�	}yJt$|jƒ�}t%|j&ƒ |jdIƒ}W d Q R X |jdJd d dKœ}	|j'||	|	ƒ W nP t(k
�rT }
 zt	j)dLt	j dG |
f ƒ W Y d d }
~
X n t*k
�rh   Y nX |j+ƒ }|j,�sŽ|j|j|j|jƒ d S )MNz	--versionÚversionz	trace 2.0)ÚactionrÉ   zMain optionsz(One of these (or --report) must be givenz-cz--countÚ
store_truez»Count the number of times each line is executed and write the counts to <module>.cover for each module executed, in the module's directory. See also --coverdir, --file, --no-report below.)rÊ   Úhelpz-tz--tracez3Print each line to sys.stdout before it is executedz-lz--listfuncsz§Keep track of which functions are executed at least once and write the results to sys.stdout after the program exits. Cannot be specified alongside --trace or --count.z-Tz--trackcallsz^Keep track of caller/called pairs and write the results to sys.stdout after the program exits.Z	Modifiersz-rz--reportz¶Generate a report from a counts file; does not execute any code. --file must specify the results file to read, which must have been created in a previous run with --count --file=FILEz-Rz--no-reportz^Do not generate the coverage report files. Useful if you want to accumulate over several runs.z-fz--filez+File to accumulate counts over several runs)rÌ   z-Cz
--coverdirz†Directory where the report files go. The coverage report for <package>.<module> will be written to file <dir>/<package>/<module>.coverz-mz	--missingz?Annotate executable lines that were not executed with ">>>>>> "z-sz	--summaryz\Write a brief summary for each file to sys.stdout. Can only be used with --count or --reportz-gz--timingzQPrefix each line with the time since the program started. Only used while tracingZFilterszCan be specified multiple timesz--ignore-moduleÚappendzqIgnore the given module(s) and its submodules (if it is a package). Accepts comma separated list of module names.)rÊ   ÚdefaultrÌ   z--ignore-dirzWIgnore files in the given directory (multiple directories can be joined by os.pathsep).r    ú?zfile to run as main program)ÚnargsrÌ   Ú	argumentszarguments to the programÚlibzpython{0.major}.{0.minor}c                s4   t jjt jj| ƒƒ} | jdˆƒjdˆ ƒ} t jj| ƒS )Nz$prefixz$exec_prefix)r   r   Ú
expanduserÚ
expandvarsr0   r   )Ús)Ú_exec_prefixÚ_prefixr   r   Úparse_ignore_dir¥  s    zmain.<locals>.parse_ignore_dirc             S   s$   g | ]}|j d ƒD ]}|jƒ ‘qqS )ú,)ÚsplitÚstrip)r   rŒ   r"   r   r   r   r   ª  s   zmain.<locals>.<listcomp>c                s&   g | ]}|j tjƒD ]}ˆ |ƒ‘qqS r   )rÚ   r   Úpathsep)r   rŒ   rÕ   )rØ   r   r   r   ¬  s   z-r/--report requires -f/--file)r;   r<   zLmust specify one of --trace, --count, --report, --listfuncs, or --trackcallsz8cannot specify both --listfuncs and (--trace or --count)z3--summary can only be used with --count or --reportz3filename is missing: required with the main optionsr   )r¢   r£   r¤   r¥   r;   r<   r¦   rŽ   r§   )rÂ   r$   Ú__package__Ú
__cached__zCannot run file %r because: %s)-ÚargparseÚArgumentParserÚadd_argumentZadd_argument_groupZadd_mutually_exclusive_groupZ	REMAINDERÚ
parse_argsZ
ignore_dirÚformatr   Úversion_infor   r   r\   Úbase_prefixÚbase_exec_prefixZignore_moduleZreportr6   Úerrorr   rr   Zmissingrc   rd   Úanyr”   ri   Z	listfuncsZ
trackcallsr    rÑ   ÚargvrU   r   r¦   r=   r�   r�   r©   rB   ÚexitÚ
SystemExitrÈ   Z	no_report)ÚparserZgrpZ_grpZoptsZrel_pathrÈ   Útrl   r|   ZglobsrH   r   )rÖ   r×   rØ   r   Úmain\  s¤    


















(rî   r§   )N) Ú__all__rß   rZ   r   Úrer   r„   r]   r�   r¹   r{   r>   Ztimer   r™   r
   ÚImportErrorr   r   r	   rw   r   r+   r4   r   r   r‚   r�   rY   r   rî   r$   r   r   r   r   Ú<module>2   sF   2 /

 M 
