B
    ó±ô`  ã               @   sš   d Z ddlmZmZmZ eZddlZddlm	Z
 ddlmZ ddlmZmZmZmZmZ e
jrndd	lmZmZ G d
d„ deƒZdd„ Zdd„ Zdd„ ZdS )z>Identify aggregated coverage in one file missing from another.é    )Úabsolute_importÚdivisionÚprint_functionNé   )Útypes)Úto_bytesé   )ÚCoverageAnalyzeTargetsConfigÚget_target_indexÚmake_reportÚread_reportÚwrite_report)ÚTargetIndexesÚIndexedPointsc                   s    e Zd ZdZ‡ fdd„Z‡  ZS )Ú#CoverageAnalyzeTargetsMissingConfigzAConfiguration for the `coverage analyze targets missing` command.c                s<   t t| ƒ |¡ |j| _|j| _|j| _|j| _|j| _d S )N)Úsuperr   Ú__init__Ú	from_fileÚto_fileÚoutput_fileÚ	only_gapsÚonly_exists)ÚselfÚargs)Ú	__class__© úf/home/dcms/DCMS/lib/python3.7/site-packages/ansible_test/_internal/coverage/analyze/targets/missing.pyr      s    z,CoverageAnalyzeTargetsMissingConfig.__init__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__classcell__r   r   )r   r   r      s   r   c             C   s–   t | jƒ\}}}t | jƒ\}}}i }| jrPt||||| jƒ}t||||| jƒ}	n(t|||||| jƒ}t|||||| jƒ}	t|||	ƒ}
t| |
| j	ƒ dS )z>Identify aggregated coverage in one file missing from another.N)
r   r   r   r   Ú	find_gapsr   Úfind_missingr   r   r   )r   Zfrom_targetsZfrom_path_arcsZfrom_path_linesZ
to_targetsZto_path_arcsZto_path_linesÚtarget_indexesZarcsÚlinesÚreportr   r   r   Ú(command_coverage_analyze_targets_missing)   s    r'   c       
         s–   i }xŒ|   ¡ D ]€\}}|r,tj t|ƒ¡s,q| |i ¡}t| ¡ ƒt| ¡ ƒ ‰ˆrt‡fdd„|  ¡ D ƒƒ}	t‡ ‡fdd„|	  ¡ D ƒƒ||< qW |S )z8Find gaps in coverage between the from and to data sets.c             3   s"   | ]\}}|ˆ kr||fV  qd S )Nr   )Ú.0ÚkeyÚvalue)Úgapsr   r   ú	<genexpr>M   s    zfind_gaps.<locals>.<genexpr>c             3   s.   | ]&\}}|t ‡ ‡fd d„|D ƒƒfV  qdS )c             3   s   | ]}t ˆ | ˆƒV  qd S )N)r
   )r(   Úi)Ú
from_indexr$   r   r   r,   N   s    z&find_gaps.<locals>.<genexpr>.<genexpr>N)Úset)r(   ZgapZindexes)r.   r$   r   r   r,   N   s    )	ÚitemsÚosÚpathÚisfiler   Úgetr/   ÚkeysÚdict)
Ú	from_datar.   Úto_datar$   r   Útarget_dataÚ	from_pathÚfrom_pointsÚ	to_pointsZ
gap_pointsr   )r.   r+   r$   r   r"   :   s    $r"   c                sÂ   i }x¸|   ¡ D ]¬\}}|r,tj t|ƒ¡s,q| |i ¡}	x€|  ¡ D ]t\}
}|	 |
tƒ ¡}t‡ fdd„|D ƒƒt‡fdd„|D ƒƒ }|rB| |i ¡ |
tƒ ¡}| ‡fdd„|D ƒ¡ qBW qW |S )zBFind coverage in from_data not present in to_data (arcs or lines).c             3   s   | ]}ˆ | V  qd S )Nr   )r(   r-   )r.   r   r   r,   g   s    zfind_missing.<locals>.<genexpr>c             3   s   | ]}ˆ | V  qd S )Nr   )r(   r-   )Úto_indexr   r   r,   g   s    c             3   s   | ]}t |ˆ ƒV  qd S )N)r
   )r(   Úname)r$   r   r   r,   k   s    )	r0   r1   r2   r3   r   r4   r/   Ú
setdefaultÚupdate)r7   r.   r8   r=   r$   r   r9   r:   r;   r<   Z
from_pointZfrom_target_indexesZto_target_indexesZremaining_targetsZtarget_indexr   )r.   r$   r=   r   r#   S   s    	, r#   )r    Ú
__future__r   r   r   ÚtypeÚ__metaclass__r1   Ú r   ÚtÚencodingr   r	   r
   r   r   r   ÚTYPE_CHECKINGr   r   r   r'   r"   r#   r   r   r   r   Ú<module>   s   