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mZmZmZ G dd	 d	eZdS )
z(Layout provider for Ansible collections.    )absolute_importdivisionprint_functionN   )types   )ContentLayoutLayoutProviderCollectionDetailLayoutMessagesc               @   sP   e Zd ZdZdZdZedd Zdd Zedd	 Z	ed
d Z
edd ZdS )CollectionLayoutz(Layout provider for Ansible collections.zplugins/modulesz	test/unitc             C   s(   t jt jt j| dkr$dS dS )zBReturn True if the given path is a content root for this provider.Zansible_collectionsTF)ospathbasenamedirname)r    r   `/home/dcms/DCMS/lib/python3.7/site-packages/ansible_test/_internal/provider/layout/collection.pyis_content_root   s     z CollectionLayout.is_content_rootc             C   s   t dd | jD }tjtj|}tj||}|tjj\}}tj|}t }t }	t }
| 	|| | 	||	 | 	||
 | 
||	}| ||
 t|||t|||dddd|d|tjjd|	d	d
d|
dS )z/Create a Layout using the given root and paths.c             s   s    | ]}|t jd |fV  qdS )ZpluginsN)r   r   join).0pr   r   r   	<genexpr>    s    z*CollectionLayout.create.<locals>.<genexpr>)name	namespaceroottestsztests/outputztests/sanityztests/integrationz(tests/integration/integration_config.ymlz
tests/unitztests/unit/plugins/modulesztests/unit/plugins/module_utils)plugin_pathsZ
collectionZ	test_pathZresults_pathZsanity_pathsanity_messagesZintegration_pathintegration_targets_pathZintegration_vars_pathintegration_messagesZ	unit_pathZunit_module_pathZunit_module_utils_pathunit_messages)dictZPLUGIN_TYPESr   r   r   relpathsplitsepr   "_CollectionLayout__check_test_path)_CollectionLayout__check_integration_path"_CollectionLayout__check_unit_pathr   r
   rstrip)selfr   pathsr   Zcollection_rootZcollection_dirZcollection_namespaceZcollection_namer   r   r    r   r   r   r   create   s@    zCollectionLayout.createc                sn   dt fdd| D }d t  fdd| D }|rR|rR|jd f  n|rj|jd f  d S )Nztests/c             3   s   | ]}|  V  qd S )N)
startswith)r   r   )modern_test_pathr   r   r   N   s    z5CollectionLayout.__check_test_path.<locals>.<genexpr>ztest/c             3   s   | ]}|  V  qd S )N)r,   )r   r   )legacy_test_pathr   r   r   P   s    z(Ignoring tests in "%s" in favor of "%s".z.Ignoring tests in "%s" that should be in "%s".)anywarningappend)r*   messagesZmodern_test_path_foundZlegacy_test_path_foundr   )r.   r-   r   Z__check_test_pathK   s    z"CollectionLayout.__check_test_pathc                s   dt fdd| D }d t  fdd| D }|rV|rV|jd f  }nP|rt|jd f   }n2|r|jd  }n|jd	 f  }|S )
Nzroles/test/c             3   s   | ]}|  V  qd S )N)r,   )r   r   )modern_integration_pathr   r   r   Z   s    z<CollectionLayout.__check_integration_path.<locals>.<genexpr>ztests/integration/targets/c             3   s   | ]}|  V  qd S )N)r,   )r   r   )legacy_integration_pathr   r   r   \   s    z(Ignoring tests in "%s" in favor of "%s".z9Falling back to tests in "%s" because "%s" was not found.zLoading tests from "%s".z2Cannot run integration tests without "%s" or "%s".)r/   r0   r1   infoerror)r*   r2   Zmodern_integration_path_foundZlegacy_integration_path_foundr   r   )r4   r3   r   Z__check_integration_pathW   s     z)CollectionLayout.__check_integration_pathc                s   dt fdd| D }d t  fdd| D }|rR|rR|jd f  n0|rl|jd f  n|rrn|jd  d S )	Nztests/unit/c             3   s   | ]}|  V  qd S )N)r,   )r   r   )modern_unit_pathr   r   r   p   s    z5CollectionLayout.__check_unit_path.<locals>.<genexpr>ztests/units/c             3   s   | ]}|  V  qd S )N)r,   )r   r   )legacy_unit_pathr   r   r   r   s    z(Ignoring tests in "%s" in favor of "%s".z&Rename "%s" to "%s" to run unit tests.z#Cannot run unit tests without "%s".)r/   r0   r1   r6   )r*   r2   Zmodern_unit_path_foundZlegacy_unit_path_foundr   )r8   r7   r   Z__check_unit_pathm   s    z"CollectionLayout.__check_unit_pathN)__name__
__module____qualname____doc__Z_CollectionLayout__module_pathZ_CollectionLayout__unit_pathstaticmethodr   r+   r%   r&   r'   r   r   r   r   r      s   -r   )r<   
__future__r   r   r   type__metaclass__r    r   tr   r	   r
   r   r   r   r   r   r   <module>   s   