B
    ó±ô`0  ã               @   sª   d Z ddlmZmZmZ eZddlZddlZddl	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 ejd	d
„ ƒZdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )zMUtility code for facilitating collection of code coverage when running tests.é    )Úabsolute_importÚdivisionÚprint_functionNé   )ÚIntegrationConfigÚSanityConfigÚ
TestConfig)Úwrite_text_file)ÚCOVERAGE_CONFIG_NAMEÚremove_tree)Údata_contextc             c   s"   t | ƒ z
dV  W dt| ƒ X dS )zEContent to set up and clean up code coverage configuration for tests.N)Úcoverage_setupÚcoverage_cleanup)Úargs© r   úS/home/dcms/DCMS/lib/python3.7/site-packages/ansible_test/_internal/coverage_util.pyÚcoverage_context   s    
r   c             C   sD   | j s
dS t| ƒ}| jr d| _n t ¡ | _ttj 	| jt
¡|ƒ dS )z8Set up code coverage configuration before running tests.Nz/tmp/coverage-temp-dir)ZcoverageÚgenerate_coverage_configÚexplainÚcoverage_config_base_pathÚtempfileÚmkdtempr	   ÚosÚpathÚjoinr
   )r   Úcoverage_configr   r   r   r   (   s    
r   c             C   s    | j r| jst| j ƒ d| _ dS )z?Clean up code coverage configuration after tests have finished.N)r   r   r   )r   r   r   r   r   7   s    
r   c             C   s   t ƒ jjrt| ƒ}ntƒ }|S )z/Generate code coverage configuration for tests.)r   ÚcontentÚ
collectionÚ#generate_collection_coverage_configÚ generate_ansible_coverage_config)r   r   r   r   r   r   >   s    

r   c              C   s   d} | S )z7Generate code coverage configuration for Ansible tests.zé
[run]
branch = True
concurrency = multiprocessing
parallel = True

omit =
    */python*/dist-packages/*
    */python*/site-packages/*
    */python*/distutils/*
    */pyshared/*
    */pytest
    */AnsiballZ_*.py
    */test/results/*
r   )r   r   r   r   r   H   s    r   c             C   s|   d}t | tƒr.|dtƒ jjtƒ jjjf 7 }nJt | tƒrf|dtƒ jjtj	 
tƒ jjtƒ jj¡f 7 }n|dtƒ jj 7 }|S )zBGenerate code coverage configuration for Ansible Collection tests.zl
[run]
branch = True
concurrency = multiprocessing
parallel = True
disable_warnings =
    no-data-collected
z
include =
    %s/*
    */%s/*
z%
include =
    %s/*

omit =
    %s/*
z
include =
     %s/*
)Ú
isinstancer   r   r   Úrootr   Ú	directoryr   r   r   r   Zresults_path)r   r   r   r   r   r   ]   s    	

,r   )Ú__doc__Ú
__future__r   r   r   ÚtypeÚ__metaclass__Ú
contextlibr   r   Úconfigr   r   r   Úior	   Úutilr
   r   Údatar   Úcontextmanagerr   r   r   r   r   r   r   r   r   r   Ú<module>   s   
