U
    f"                     @   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 ddl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)develop)Distribution)paths_on_pythonpath   )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   Ztempdirsetattr)Zmonkeypatch	user_base	user_site r   <lib/python3.8/site-packages/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   ZsetupfZ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 )
TestDevelopZ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.0Zconsole_scriptszfoocmd = foo:foo)namepackagesversionZ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PathZegg_linksuffixAssertionErrorZstem)r)   r*   r+   r,   linkr   r   r   test_egg_link_filenameU   s    z"TestDevelop.test_egg_link_filenameN)__name__
__module____qualname__hasattrsysZin_virtualenvr   prefixZin_venvr-   r#   markZxfailr5   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_pathr3   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pkgsr>   ../r?   r@   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/r>   rB   rC   r?   r@   r   r   r   .test_resolve_setup_path_one_dir_trailing_slasho   s    z;TestResolver.test_resolve_setup_path_one_dir_trailing_slashN)r6   r7   r8   __doc__rA   rD   rE   r   r   r   r   r=   b   s   r=   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)r:   
executablestrr   r   
subprocess
check_call)Zsrc_dirr   Zdevelop_cmdr   r   r   install_developt   s    
zTestNamespaces.install_developZAPPVEYORz-https://github.com/pypa/setuptools/issues/851r.   Z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-mZpipZinstallz-tz-cz"import myns.pkgA; import myns.pkgBzimport pkg_resourcesN)
r   Zbuild_namespace_packager:   rH   rI   rJ   rK   rL   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)r6   r7   r8   staticmethodrL   r#   r<   ZskipifboolosenvirongetplatformZpython_implementationrM   r   r   r   r   rG   s   s   

rG   )rF   rP   r:   rJ   r0   rS   r#   Zsetuptools.command.developr   Zsetuptools.distr   Zsetuptools._pathr    r   r   r   r   Zfixturer   r   r   r=   rG   r   r   r   r   <module>   s(   

,