
#þîh£  ã               @   sO   d  d l  Z  d  d l Z d  d l m Z d d l m Z Gd d „  d ƒ Z d S)é    N)Úpaths_on_pythonpathé   )Ú
namespacesc               @   s@   e  Z d  Z d d „  Z d d „  Z d d „  Z d d „  Z d	 S)
ÚTestNamespacesc       	   	   C   sÿ   t  j | d ƒ } t  j | d ƒ } | d } | d } | | f } t j d d d t | ƒ d t | ƒ g } t j | ƒ t  j | ƒ t j d d d t | ƒ d t | ƒ g } t j | ƒ t j d	 d
 g } t t	 t | ƒ ƒ � t j | ƒ Wd QRXd S)zø
        Installing two packages sharing the same namespace, one installed
        to a site dir and the other installed just to a path on PYTHONPATH
        should leave the namespace in tact and both packages reachable by
        import.
        z	myns.pkgAz	myns.pkgBzsite-packageszpath-packagesz-mzpip.__main__Úinstallz-tz-cz"import myns.pkgA; import myns.pkgBN)
r   Úbuild_namespace_packageÚsysÚ
executableÚstrÚ
subprocessÚ
check_callÚmake_site_dirr   Úmap)	ÚselfÚtmpdirÚpkg_AÚpkg_BÚsite_packagesZpath_packagesÚtargetsÚinstall_cmdÚ
try_import© r   úF/tmp/pip-build-zijwfla7/setuptools/setuptools/tests/test_namespaces.pyÚtest_mixed_site_and_non_site
   s6    

			z+TestNamespaces.test_mixed_site_and_non_sitec             C   sÇ   t  j | d ƒ } | d } | j ƒ  t j d d d d t | ƒ t | ƒ g } t t | ƒ g ƒ � t j | ƒ Wd QRXt  j	 | ƒ t j d d	 g } t t | ƒ g ƒ � t j | ƒ Wd QRXd S)
zc
        Ensure that a namespace package doesn't break on import
        of pkg_resources.
        z	myns.pkgAÚpackagesz-mÚpipr   z-tNz-czimport pkg_resources)
r   r   Úmkdirr   r	   r
   r   r   r   r   )r   r   ÚpkgÚtargetr   r   r   r   r   Útest_pkg_resources_import4   s$    

		z(TestNamespaces.test_pkg_resources_importc             C   s¬   t  j | d ƒ } | d } t j d d d t | ƒ d t | ƒ g } t j | ƒ t  j | ƒ t j d d g } t t | ƒ g ƒ � t j | d	 t | ƒ ƒWd
 QRXd
 S)z—
        Installing a namespace packages but also having it in the current
        working directory, only one version should take precedence.
        z	myns.pkgAr   z-mzpip.__main__r   z-tz-cz&import pkg_resources; import myns.pkgAÚcwdN)	r   r   r   r	   r
   r   r   r   r   )r   r   r   r   r   Úpkg_resources_impr   r   r   Ú(test_namespace_package_installed_and_cwdP   s     
		z7TestNamespaces.test_namespace_package_installed_and_cwdc             C   s¾   t  j | d ƒ } t  j | d ƒ } | d } t j d d d t | ƒ d t | ƒ g } t j | ƒ t  j | ƒ t j d d	 g } t t | ƒ g ƒ � t j | d
 t | ƒ ƒWd QRXd S)z±
        Installing one namespace package and also have another in the same
        namespace in the current working directory, both of them must be
        importable.
        z	myns.pkgAz	myns.pkgBr   z-mzpip.__main__r   z-tz-cz8import pkg_resources; import myns.pkgA; import myns.pkgBr    N)	r   r   r   r	   r
   r   r   r   r   )r   r   r   r   r   r   r!   r   r   r   Ú5test_packages_in_the_same_namespace_installed_and_cwdm   s"    
		zDTestNamespaces.test_packages_in_the_same_namespace_installed_and_cwdN)Ú__name__Ú
__module__Ú__qualname__r   r   r"   r#   r   r   r   r   r   	   s   *r   )r   r   Zsetuptools._pathr   Ú r   r   r   r   r   r   Ú<module>   s   