
 X<                 @   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   T/home/ubuntu/projects/ifolica/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)zRegression 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)zCreates 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)zCreate 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]%
