î
½1kd”<  ã               @   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 Z d d l Z d d l	 Z	 d d l
 Z
 d d l Z d d l m Z m Z m Z m Z d d l m Z m Z d d l m Z m Z m Z m Z d d l m Z d d l m Z d d l m Z d d	 l m  Z  m! Z! d d l m Z" d d l# Z$ d d l Z Gd
 d „  d e% ƒ Z& d e e e j' d ƒ ƒ Z( d Z) Gd d „  d e j* ƒ Z+ Gd d „  d e j* ƒ Z, Gd d „  d e j* ƒ Z- Gd d „  d e j* ƒ Z. d d „  Z/ d d „  Z0 e j1 d d „  d d „ ƒ Z2 e j1 d d  „  ƒ Z3 e j1 d! d" „  ƒ Z4 e j1 d# d$ „  ƒ Z5 e j1 d% d& „  ƒ Z6 d S)'zEasy install Tests
é    N)ÚStringIOÚBytesIOÚnextÚurlparse)Ú	run_setupÚSandboxViolation)Úeasy_installÚfix_jython_executableÚget_script_argsÚnt_quote_arg)ÚPthDistributions)r   )ÚDistribution)Úworking_setÚVersionConflictc               @   s(   e  Z d  Z d d „  Z d d „  Z d S)ÚFakeDistc             C   s   | d k r i  Si d d 6S)NÚconsole_scriptsÚepÚname© )ÚselfÚgroupr   r   úX/var/www/pythonscrapper/code/venv/build/setuptools/setuptools/tests/test_easy_install.pyÚget_entry_map   s    zFakeDist.get_entry_mapc             C   s   d S)NÚspecr   )r   r   r   r   Úas_requirement!   s    zFakeDist.as_requirementN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r      s   r   zü#!%s
# EASY-INSTALL-ENTRY-SCRIPT: 'spec','console_scripts','name'
__requires__ = 'spec'
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.exit(
        load_entry_point('spec', 'console_scripts', 'name')()
    )
Ú z0from setuptools import setup

setup(name='foo')
c               @   s4   e  Z d  Z d d „  Z d d „  Z d d „  Z d S)ÚTestEasyInstallTestc             C   s„   t  ƒ  } t | ƒ } d | _ t j ƒ  | _ z? | j ƒ  t j j	 | j d ƒ } |  j
 t j j | ƒ ƒ Wd  t j | j ƒ Xd  S)NFzsite.py)r   r   Zsitepy_installedÚtempfileÚmkdtempÚinstall_dirZinstall_site_pyÚosÚpathÚjoinÚ
assertTrueÚexistsÚshutilÚrmtree)r   ÚdistÚcmdZsitepyr   r   r   Útest_install_site_py9   s    		
z(TestEasyInstallTest.test_install_site_pyc             C   sf   t  ƒ  } t j } z3 d d „  t t | ƒ ƒ Dƒ d d … \ } } Wd  | t _ X|  j | t ƒ d  S)Nc             S   s   g  |  ] } | ‘ q Sr   r   )Ú.0Úir   r   r   ú
<listcomp>J   s   	 z<TestEasyInstallTest.test_get_script_args.<locals>.<listcomp>r   é   )r   ÚsysÚplatformr   r
   ÚassertEqualÚWANTED)r   r*   Zold_platformr   Úscriptr   r   r   Útest_get_script_argsE   s    		3
z(TestEasyInstallTest.test_get_script_argsc             C   s  t  ƒ  } t | ƒ } d d „  | _ d | _ d d g | _ t j j t j	 ƒ  d ƒ | _
 d g | _ | j ƒ  |  j | j j i  ƒ t | ƒ } d d „  | _ d d g | _ t j j t j	 ƒ  d ƒ | _
 d g | _ | j ƒ  t | j j j ƒ  ƒ } |  j | d d g ƒ d  S)Nc               S   s   d S)NTr   r   r   r   r   Ú<lambda>U   s    z8TestEasyInstallTest.test_no_find_links.<locals>.<lambda>TZlink1Zlink2Úokc               S   s   d S)NTr   r   r   r   r   r7   _   s    )r   r   Zcheck_pth_processingZno_find_linksÚ
find_linksr#   r$   r%   r    r!   r"   ÚargsÚensure_finalizedr3   Zpackage_indexZscanned_urlsÚsortedÚkeys)r   r*   r+   r=   r   r   r   Útest_no_find_linksP   s"    		

z&TestEasyInstallTest.test_no_find_linksN)r   r   r   r,   r6   r>   r   r   r   r   r   7   s   r   c               @   s(   e  Z d  Z d d „  Z d d „  Z d S)ÚTestPTHFileWriterc             C   sV   t  d t j ƒ  g ƒ } |  j | j ƒ | j t t j ƒ  ƒ ƒ |  j | j ƒ d S)zba pth file manager should set dirty
        if a distribution is in site but also the cwd
        zdoes-not_existN)r   r#   Úgetcwdr&   ÚdirtyÚaddÚPRDistribution)r   Úpthr   r   r   Ú!test_add_from_cwd_site_sets_dirtyi   s    z3TestPTHFileWriter.test_add_from_cwd_site_sets_dirtyc             C   si   t  j d k r d } n d } t d | g ƒ } |  j | j ƒ | j t | ƒ ƒ |  j | j ƒ d  S)NÚntz%/test/location/does-not-have-to-existzc:\does_not_existzdoes-not_exist)r#   r   r   r&   rA   rB   rC   )r   ÚlocationrD   r   r   r   Útest_add_from_site_is_ignoredr   s    	z/TestPTHFileWriter.test_add_from_site_is_ignoredN)r   r   r   rE   rH   r   r   r   r   r?   h   s   	r?   c               @   sd   e  Z d  Z d d „  Z d d „  Z d d „  Z d d „  Z d	 d
 „  Z d d „  Z d d „  Z	 d S)ÚTestUserInstallTestc             C   sÊ   t  j ƒ  |  _ t j j |  j d ƒ } t | d ƒ } | j t ƒ | j	 ƒ  t j
 ƒ  |  _ t j |  j ƒ t j |  _ t j |  _ t j |  _ t  j ƒ  t _ t j |  _ t  j ƒ  t _ t j t _ d  S)Nzsetup.pyÚw)r    r!   Údirr#   r$   r%   ÚopenÚwriteÚSETUP_PYÚcloser@   Úold_cwdÚchdirÚsiteÚENABLE_USER_SITEÚold_enable_siteÚeasy_install_pkgÚ__file__Úold_fileÚ	USER_BASEÚold_baseÚ	USER_SITEÚold_site)r   ÚsetupÚfr   r   r   ÚsetUp   s    
zTestUserInstallTest.setUpc             C   st   t  j |  j ƒ t j |  j ƒ t j t j ƒ t j t j ƒ |  j	 t _ |  j
 t _ |  j t _ |  j t _ d  S)N)r#   rQ   rP   r(   r)   rK   rR   rX   rZ   rY   r[   rT   rS   rW   rU   rV   )r   r   r   r   ÚtearDown�   s    zTestUserInstallTest.tearDownc             C   sT   d t  _ t ƒ  } d | _ t | ƒ } d g | _ | j ƒ  |  j | j d ƒ d  S)NTzsetup.pyÚpyzuser should be implied)	rR   rS   r   Úscript_namer   r:   r;   r&   Úuser)r   r*   r+   r   r   r   Útest_user_install_implied›   s    			
z-TestUserInstallTest.test_user_install_impliedc             C   sc   y t  d ƒ Wn t k
 r& d  SYn Xt j d ƒ } t j d t j d t j ƒ | j d ƒ d  S)NÚmultiprocessingZtest_easy_installÚlevelÚstreamzthis should not break)	Ú
__import__ÚImportErrorÚloggingÚ	getLoggerÚbasicConfigÚINFOr1   ÚstderrÚinfo)r   Úlogr   r   r   Útest_multiproc_atexit¥   s    	z)TestUserInstallTest.test_multiproc_atexitc             C   sT   d t  _ t ƒ  } d | _ t | ƒ } d g | _ | j ƒ  |  j | j d ƒ d  S)NFzsetup.pyr`   zNOT user should be implied)	rR   rS   r   ra   r   r:   Úinitialize_optionsZassertFalserb   )r   r*   r+   r   r   r   Ú6test_user_install_not_implied_without_usersite_enabled°   s    			
zJTestUserInstallTest.test_user_install_not_implied_without_usersite_enabledc             C   së  t  j ƒ  } t  j ƒ  } t j j | d ƒ } t | d ƒ } z | j d ƒ Wd  | j ƒ  Xt j j	 | ƒ t j
 j d ƒ } t j j j t j ƒ t j
 d <z² t ƒ  } d | _ t | ƒ } | | _ d g | _ | j ƒ  | j j | g ƒ | j d ƒ } t j j t j j | j ƒ ƒ }	 t j j t j j | ƒ ƒ }
 |  j |	 |
 ƒ Wd  t j j | ƒ x\ | | g D]N } t j j | ƒ snt j j | ƒ r qnn  y t j | ƒ WqnYqnXqnW| d  k	 rÜ| t j
 d <n
 t j
 d =Xd  S)Nzfoo-1.0.egg-inforJ   z
Name: foo
Ú
PYTHONPATHzsetup.pyZfoo)r    r!   r#   r$   r%   rL   rM   rO   r1   ÚappendÚenvironÚgetÚpathsepr   ra   r   r"   r:   r;   Zlocal_indexÚscanÚnormcaseÚrealpathrG   r3   Úremover'   Úisdirr(   r)   )r   Únew_locationÚtargetZegg_filer]   Z	old_ppathr*   r+   ÚresÚactualÚexpectedÚbasedirr   r   r   Útest_local_indexº   sB    			
!&	z$TestUserInstallTest.test_local_indexc             C   s~   t  |  j ƒ } t j j | d ƒ } y4 t ƒ  �% t ƒ  � t | d g ƒ Wd QXWd QXWn t k
 ry |  j	 d ƒ Yn Xd S)záRegression test for Distribute issue #318

        Ensure that a package with setup_requires can be installed when
        setuptools is installed in the user site-packages without causing a
        SandboxViolation.
        zsetup.pyÚinstallNz$Installation caused SandboxViolation)
Úcreate_setup_requires_packagerK   r#   r$   r%   Úquiet_contextÚreset_setup_stop_contextr   r   Úfail)r   Útest_pkgÚtest_setup_pyr   r   r   Útest_setup_requiresä   s    

 z'TestUserInstallTest.test_setup_requiresN)
r   r   r   r^   r_   rc   rp   rr   rƒ   r‹   r   r   r   r   rI   }   s   

*rI   c               @   sC   e  Z d  Z d d „  Z e e j d d „  ƒ ƒ Z d d „  Z d S)ÚTestSetupRequiresc          .   C   s<  t  j j j ƒ  } | j ƒ  d } t | j ƒ | } | j d ƒ rH d St ƒ  �Ÿ t	 j
 ƒ  �Œ } t ƒ  �z } t d | ƒ �b d | j d | d d | | g } t ƒ  �1 t d	 g ƒ � |  j t t j | ƒ Wd QXWd QXWd QXWd QXWd QXWd QX|  j d
 t | j ƒ k od k n ƒ |  j | j d j d ƒ d S)zÉ
        When easy_install installs a source distribution which specifies
        setup_requires, it should honor the fetch parameters (such as
        allow-hosts, index-url, and find-links).
        é   z:0Nrs   z--index-urlz--allow-hostsz--exclude-scriptsz--install-dirr   r0   é   r   z/does-not-exist/)Ú
setuptoolsÚtestsÚserverZ
MockServerÚstartr   ÚurlÚendswithr†   rŒ   Úcreate_sdistÚtempdir_contextÚenvironment_contextr‡   Úargv_contextZassertRaisesÚ
SystemExitrU   Úmainr&   ÚlenÚrequestsr3   r$   )r   Zp_indexÚnetlocZp_index_locZ	dist_fileZtemp_install_dirZ	ei_paramsr   r   r   Ú'test_setup_requires_honors_fetch_paramsù   s(    

			
	1,z9TestSetupRequires.test_setup_requires_honors_fetch_paramsc              c   sL   t  ƒ  �= }  t j j |  d ƒ } t | t j d ƒ j ƒ  ƒ | VWd QXd S)zl
        Return an sdist with a setup_requires dependency (of something that
        doesn't exist)
        z"setuptools-test-fetcher-1.0.tar.gza  
                    import setuptools
                    setuptools.setup(
                        name="setuptools-test-fetcher",
                        version="1.0",
                        setup_requires = ['does-not-exist'],
                    )
                N)r–   r#   r$   r%   Úmake_trivial_sdistÚtextwrapÚdedentÚlstrip)rK   Ú	dist_pathr   r   r   r•     s    zTestSetupRequires.create_sdistc       	   &   C   s  t  j ƒ  } t d d d d d ƒ} t j | ƒ zÔ t ƒ  �Å } t | ƒ } t j j	 | d ƒ } t
 ƒ  �S \ } } t ƒ  �; y t | d g ƒ Wn t k
 r² |  j d ƒ Yn XWd	 QXWd	 QX| j ƒ  } |  j t | ƒ d
 k ƒ |  j | d j ƒ  d ƒ Wd	 QXWd	 t  j | ƒ Xd	 S)zö
        Regression test for issue #323.

        Ensures that a distribution's setup_requires requirements can still be
        installed and used locally even if a conflicting version of that
        requirement is already on the path.
        zdoes-not-matterÚproject_nameZfoobarÚversionz0.0zsetup.pyz--namez9Installing setup.py requirements caused a VersionConflictNr   r�   r‰   éÿÿÿÿ)Úpkg_resourcesÚ__getstate__rC   r   rB   r–   r…   r#   r$   r%   r†   r‡   r   r   rˆ   Ú	readlinesr&   r›   ÚstripÚ__setstate__)	r   Zpr_stateZ	fake_distÚtemp_dirr‰   rŠ   Ústdoutrm   Úlinesr   r   r   Ú.test_setup_requires_overrides_version_conflict1  s$    		
$z@TestSetupRequires.test_setup_requires_overrides_version_conflictN)	r   r   r   rž   ÚstaticmethodÚ
contextlibÚcontextmanagerr•   r¯   r   r   r   r   rŒ   ÷   s   #rŒ   c             C   sÍ   i d d 6d d 6d g d 6t  j j |  ƒ g d 6} t  j j |  d ƒ } t  j j | d ƒ } t  j | ƒ t | d	 ƒ } | j t j d
 | ƒ ƒ | j	 ƒ  t  j j |  d ƒ } t
 | t j d ƒ ƒ | S)zÔCreates a source tree under path for a trivial test package that has a
    single requirement in setup_requires--a tarball for that requirement is
    also created and added to the dependency_links argument.
    r‰   r   z0.0r¥   zfoobar==0.1Zsetup_requiresÚdependency_linkszsetup.pyrJ   z=        import setuptools
        setuptools.setup(**%r)
    zfoobar-0.1.tar.gzz�            import setuptools
            setuptools.setup(
                name='foobar',
                version='0.1'
            )
        )r#   r$   Úabspathr%   ÚmkdirrL   rM   r    r¡   rO   rŸ   )r$   Ztest_setup_attrsr‰   rŠ   r]   Zfoobar_pathr   r   r   r…   T  s"    


r…   c             C   sœ   t  j d d ƒ } y
 t } Wn t k
 r6 t } Yn X| | j d ƒ ƒ } t | j ƒ  ƒ | _ t  j	 |  d ƒ } z | j
 | d | ƒWd | j ƒ  Xd S)z‹Create a simple sdist tarball at dist_path, containing just a
    setup.py, the contents of which are provided by the setup_py string.
    r   zsetup.pyzutf-8zw:gzÚfileobjN)ÚtarfileÚTarInfor   ÚAttributeErrorr   Úencoder›   ÚgetvalueÚsizerL   ÚaddfilerO   )r£   Úsetup_pyZsetup_py_fileZMemFileZsetup_py_bytesr*   r   r   r   rŸ   y  s    
rŸ   c             C   s   d  S)Nr   )rK   r   r   r   r7   Ž  s    r7   c             c   sJ   t  j ƒ  } t j ƒ  } z |  | ƒ | VWd  |  | ƒ t j | ƒ Xd  S)N)r    r!   r#   r@   r(   r)   )Zcdr¬   Zorig_dirr   r   r   r–   �  s    
	
r–   c              k   s[   t  j j ƒ  } t  j j |  ƒ z	 d  VWd  x |  D] } t  j | =q2 Wt  j j | ƒ Xd  S)N)r#   ru   ÚcopyÚupdate)ZupdatesZold_envÚkeyr   r   r   r—   ˜  s    	r—   c             c   sB   t  j d  d  … } |  t  j d  d  … <d  V| t  j d  d  … <d  S)N)r1   Úargv)ÚreplZold_argvr   r   r   r˜   £  s    r˜   c              c   s-   t  j j }  d t  j _ d V|  t  j _ d S)a  
    When the setuptools tests are run using setup.py test, and then
    one wants to invoke another setup() command (such as easy_install)
    within those tests, it's necessary to reset the global variable
    in distutils.core so that the setup() command will run naturally.
    N)Ú	distutilsÚcoreÚ_setup_stop_after)Zsetup_stop_afterr   r   r   r‡   ª  s    r‡   c              c   su   t  j }  t  j } t ƒ  } t  _ t ƒ  } t  _ z | | f VWd | j d ƒ | j d ƒ |  t  _ | t  _ Xd S)zk
    Redirect stdout/stderr to StringIO objects to prevent console output from
    distutils commands.
    Nr   )r1   r­   rm   r   Úseek)Z
old_stdoutZ
old_stderrZ
new_stdoutZ
new_stderrr   r   r   r†   ¸  s    			r†   )7Ú__doc__r1   r#   r(   r    ZunittestrR   r±   r    r·   ri   Údistutils.corerÄ   Zsetuptools.compatr   r   r   r   Zsetuptools.sandboxr   r   Zsetuptools.command.easy_installr   r	   r
   r   r   Zsetuptools.commandrU   Zsetuptools.distr   r§   r   r   rC   Zsetuptools.tests.serverr�   Úobjectr   Ú
executabler4   rN   ZTestCaser   r?   rI   rŒ   r…   rŸ   r²   r–   r—   r˜   r‡   r†   r   r   r   r   Ú<module>   sH   ""1z]%
