U
    ui                     @   s   d 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 ddl	m
Z
 ddlmZ ddlmZmZ dZd	Zejd
d Zejdd ZG dd dZG dd dZG dd dZdS )zdevelop tests    N)paths_on_pythonpath)develop)Distribution   )contexts
namespaceszHfrom setuptools import setup

setup(name='foo',
    packages=['foo'],
)
zprint "foo"
c              
   c   sJ   t  8}t  $}| d| | d| d V  W 5 Q R X W 5 Q R X d S )Nzsite.USER_BASEzsite.USER_SITE)r   tempdirsetattr)Zmonkeypatch	user_base	user_site r   A/tmp/pip-unpacked-wheel-9osl9suo/setuptools/tests/test_develop.py	temp_user   s
    

r   c              	   c   s   | }| d}|d }| r*tt||d}|t W 5 Q R X |d }|d}|t W 5 Q R X |  |V  W 5 Q R X d S )Nfoosetup.pywz__init__.py)	mkdirisfile
ValueErrordiropenwriteSETUP_PYINIT_PYas_cwd)tmpdirr   targetr   setupfinitr   r   r   test_env&   s    

r    c                   @   sJ   e Zd ZeedZeedo&ejejkZdd Z	e
jjdddd Zd	S )
TestDevelopreal_prefixbase_prefixc                 C   sR   t d tddgdddgid}t|}d|_t|}|  ||_|  dS )	z
        Test that console scripts are installed and that they reference
        only the project by name and not the current version.
        zTTODO: needs a fixture to cause 'develop' to be invoked without mutating environment.r   z0.0console_scriptszfoocmd = foo:foo)namepackagesversionentry_pointsr   N)	pytestskipdictr   script_namer   ensure_finalizedZinstall_dirrun)selfr   settingsdistcmdr   r   r   test_console_scripts:   s$    
z TestDevelop.test_console_scriptsz0legacy behavior retained for compatibility #4167reasonc                 C   sN   t dd}t|}t|}|  t|j}|jdks<t|j	dksJtd S )NzFoo $$$ Bar_baz-bing)r%   z	.egg-linkZFoo_Bar_baz_bing)
r+   r   r   r-   pathlibPathegg_linksuffixAssertionErrorstem)r/   r0   r1   r2   linkr   r   r   test_egg_link_filenameU   s    z"TestDevelop.test_egg_link_filenameN)__name__
__module____qualname__hasattrsysZin_virtualenvr#   prefixin_venvr3   r)   markZxfailr=   r   r   r   r   r!   6   s
   
r!   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	TestResolverz
    TODO: These tests were written with a minimal understanding
    of what _resolve_setup_path is intending to do. Come up with
    more meaningful cases that look like real-world scenarios.
    c                 C   s   t ddddkstd S )N.r   Z_resolve_setup_pathr:   r/   r   r   r   test_resolve_setup_path_cwdi   s    z(TestResolver.test_resolve_setup_path_cwdc                 C   s   t ddddkstd S )NpkgsrG   ../rH   rI   r   r   r   test_resolve_setup_path_one_dirl   s    z,TestResolver.test_resolve_setup_path_one_dirc                 C   s   t ddddkstd S )Nzpkgs/rG   rK   rL   rH   rI   r   r   r   .test_resolve_setup_path_one_dir_trailing_slasho   s    z;TestResolver.test_resolve_setup_path_one_dir_trailing_slashN)r>   r?   r@   __doc__rJ   rM   rN   r   r   r   r   rF   b   s   rF   c                   @   sT   e Zd Zedd Zejjee	j
dddejje dkdddd	 Zd
S )TestNamespacesc              
   C   sP   t jdddt|g}|  * tt|g t| W 5 Q R X W 5 Q R X d S )Nr   r   z--install-dir)rB   
executablestrr   r   
subprocess
check_call)src_dirr   Zdevelop_cmdr   r   r   install_developt   s    
zTestNamespaces.install_developZAPPVEYORz-https://github.com/pypa/setuptools/issues/851r4   PyPyz.https://github.com/pypa/setuptools/issues/1202c              	   C   s   t |d}t |d}|d }tjdddt|dt|g}t| | || t | tjdd	g}t	t|g t| W 5 Q R X tjdd
g}t	t|g t| W 5 Q R X dS )a  
        Installing two packages sharing the same namespace, one installed
        naturally using pip or `--single-version-externally-managed`
        and the other installed using `develop` should leave the namespace
        in tact and both packages reachable by import.
        z	myns.pkgAz	myns.pkgBr&   z-mpipinstallz-tz-cz"import myns.pkgA; import myns.pkgBzimport pkg_resourcesN)
r   Zbuild_namespace_packagerB   rQ   rR   rS   rT   rV   Zmake_site_dirr   )r/   r   Zpkg_AZpkg_Br   Zinstall_cmdZ
try_importZpkg_resources_impr   r   r   !test_namespace_package_importable   s4    	

z0TestNamespaces.test_namespace_package_importableN)r>   r?   r@   staticmethodrV   r)   rE   Zskipifboolosenvirongetplatformpython_implementationrZ   r   r   r   r   rP   s   s   

rP   )rO   r]   r6   r`   rS   rB   r)   Zsetuptools._pathr   Zsetuptools.command.developr   Zsetuptools.distr    r   r   r   r   Zfixturer   r    r!   rF   rP   r   r   r   r   <module>   s&   

,