B
    '(äbI3  ã               @   s~   d dl Z d dlmZ d dlmZmZmZ d dlmZm	Z	 d dl
mZ e j e j ed¡¡ZG dd„ deƒZG d	d
„ d
eƒZdS )é    N)ÚOptions)ÚFindModuleCacheÚSearchPathsÚModuleNotFoundReason)ÚSuiteÚassert_equal)Úpackage_pathZmodulefinderc               @   sÞ   e Zd Zddœdd„Zddœdd„Zddœdd„Zddœd	d
„Zddœdd„Zddœdd„Zddœdd„Z	ddœdd„Z
ddœdd„Zddœdd„Zddœdd„Zddœdd„Zddœdd„Zddœdd„Zddœdd „ZdS )!ÚModuleFinderSuiteN)Úreturnc             C   s¦   t dtj td¡tj td¡tj td¡tj td¡tj td¡tj td¡tj td¡fddd	| _tƒ }d
|_t| jd |d| _	tƒ }d|_t| jd |d| _
d S )N© znsx-pkg1znsx-pkg2znsx-pkg3znsy-pkg1znsy-pkg2Úpkg1Úpkg2)Úpython_pathÚ	mypy_pathr   Útypeshed_pathT)ÚfscacheÚoptionsF)r   ÚosÚpathÚjoinÚ	data_pathÚsearch_pathsr   Únamespace_packagesr   Úfmc_nsÚfmc_nons)Úselfr   r   r   úI/home/dcms/DCMS/lib/python3.7/site-packages/mypy/test/testmodulefinder.pyÚsetUp   s"    
zModuleFinderSuite.setUpc             C   s   | j  d¡}ttj|ƒ dS )zG
        If namespace_packages is False, we shouldn't find nsx
        ÚnsxN)r   Úfind_moduler   r   Ú	NOT_FOUND)r   Úfound_moduler   r   r   Ú test__no_namespace_packages__nsx(   s    z2ModuleFinderSuite.test__no_namespace_packages__nsxc             C   s   | j  d¡}ttj|ƒ dS )zJ
        If namespace_packages is False, we shouldn't find nsx.a.
        znsx.aN)r   r   r   r   r    )r   r!   r   r   r   Ú"test__no_namespace_packages__nsx_a/   s    z4ModuleFinderSuite.test__no_namespace_packages__nsx_ac             C   s*   | j  d¡}tj tdd¡}t||ƒ dS )zL
        Find find pkg1/a.py for "a" with namespace_packages False.
        Úar   za.pyN)r   r   r   r   r   r   r   )r   r!   Úexpectedr   r   r   Ú+test__no_namespace_packages__find_a_in_pkg16   s    z=ModuleFinderSuite.test__no_namespace_packages__find_a_in_pkg1c             C   s,   | j  d¡}tj tddd¡}t||ƒ d S )NÚbr   z__init__.py)r   r   r   r   r   r   r   )r   r!   r%   r   r   r   Ú+test__no_namespace_packages__find_b_in_pkg2>   s    z=ModuleFinderSuite.test__no_namespace_packages__find_b_in_pkg2c             C   s*   | j  d¡}tj tdd¡}t||ƒ dS )z|
        There's no __init__.py in any of the nsx dirs, return
        the path to the first one found in mypypath.
        r   znsx-pkg1N)r   r   r   r   r   r   r   )r   r!   r%   r   r   r   Ú'test__find_nsx_as_namespace_pkg_in_pkg1C   s    z9ModuleFinderSuite.test__find_nsx_as_namespace_pkg_in_pkg1c             C   s.   | j  d¡}tj tdddd¡}t||ƒ dS )zP
        Find nsx-pkg1/nsx/a/__init__.py for "nsx.a" in namespace mode.
        znsx.aznsx-pkg1r   r$   z__init__.pyN)r   r   r   r   r   r   r   )r   r!   r%   r   r   r   Útest__find_nsx_a_init_in_pkg1L   s    z/ModuleFinderSuite.test__find_nsx_a_init_in_pkg1c             C   s.   | j  d¡}tj tdddd¡}t||ƒ dS )zP
        Find nsx-pkg2/nsx/b/__init__.py for "nsx.b" in namespace mode.
        znsx.bznsx-pkg2r   r'   z__init__.pyN)r   r   r   r   r   r   r   )r   r!   r%   r   r   r   Útest__find_nsx_b_init_in_pkg2T   s    z/ModuleFinderSuite.test__find_nsx_b_init_in_pkg2c             C   s.   | j  d¡}tj tdddd¡}t||ƒ dS )zK
        Find nsx-pkg3/nsx/c/c.py for "nsx.c.c" in namespace mode.
        znsx.c.cznsx-pkg3r   Úczc.pyN)r   r   r   r   r   r   r   )r   r!   r%   r   r   r   Útest__find_nsx_c_c_in_pkg3\   s    z,ModuleFinderSuite.test__find_nsx_c_c_in_pkg3c             C   s.   | j  d¡}tj tdddd¡}t||ƒ dS )zG
        Prefer nsy-pkg1/a/__init__.pyi file over __init__.py.
        znsy.aznsy-pkg1Únsyr$   z__init__.pyiN)r   r   r   r   r   r   r   )r   r!   r%   r   r   r   Útest__find_nsy_a__init_pyid   s    z,ModuleFinderSuite.test__find_nsy_a__init_pyic             C   s.   | j  d¡}tj tdddd¡}t||ƒ dS )zÅ
        There is a nsy-pkg2/nsy/b.pyi, but also a nsy-pkg2/nsy/b/__init__.py.
        We expect to find the latter when looking up "nsy.b" as
        a package is preferred over a module.
        znsy.bznsy-pkg2r.   r'   z__init__.pyN)r   r   r   r   r   r   r   )r   r!   r%   r   r   r   Útest__find_nsy_b__init_pyl   s    z+ModuleFinderSuite.test__find_nsy_b__init_pyc             C   s,   | j  d¡}tj tddd¡}t||ƒ dS )z©
        There is a nsy-pkg2/nsy/c.pyi and nsy-pkg2/nsy/c.py
        We expect to find the former when looking up "nsy.b" as
        .pyi is preferred over .py.
        znsy.cznsy-pkg2r.   zc.pyiN)r   r   r   r   r   r   r   )r   r!   r%   r   r   r   Útest__find_nsy_c_pyiv   s    z&ModuleFinderSuite.test__find_nsy_c_pyic             C   s*   | j  d¡}tj tdd¡}t||ƒ d S )Nr$   r   za.py)r   r   r   r   r   r   r   )r   r!   r%   r   r   r   Útest__find_a_in_pkg1€   s    z&ModuleFinderSuite.test__find_a_in_pkg1c             C   s,   | j  d¡}tj tddd¡}t||ƒ d S )Nr'   r   z__init__.py)r   r   r   r   r   r   r   )r   r!   r%   r   r   r   Útest__find_b_init_in_pkg2…   s    z+ModuleFinderSuite.test__find_b_init_in_pkg2c             C   s   | j  d¡}ttj|ƒ d S )NÚd)r   r   r   r   r    )r   r!   r   r   r   Útest__find_d_nowhereŠ   s    z&ModuleFinderSuite.test__find_d_nowhere)Ú__name__Ú
__module__Ú__qualname__r   r"   r#   r&   r(   r)   r*   r+   r-   r/   r0   r1   r2   r3   r5   r   r   r   r   r	      s   	

r	   c               @   sF   e Zd Zddœdd„Zeedœdd„Zddœdd	„Zddœd
d„ZdS )ÚModuleFinderSitePackagesSuiteN)r
   c             C   s°   t j t j td¡¡| _t j | jd¡t j | jdd¡t j | jdd¡| jf}tdt j td¡ft|ƒdd| _	t
ƒ }d	|_t| j	d |d
| _t
ƒ }d|_t| j	d |d
| _d S )Nzmodulefinder-site-packagesÚbazz..znot-a-directoryzmodulefinder-srcr   r   )r   r   r   r   T)r   r   F)r   r   Úrelpathr   r   Úpackage_dirr   r   Útupler   r   r   r   r   r   )r   Zpackage_pathsr   r   r   r   r   ‘   s$    

z#ModuleFinderSitePackagesSuite.setUp)Úpartsr
   c             G   s   t jj| jf|žŽ S )N)r   r   r   r<   )r   r>   r   r   r   r   ¬   s    z"ModuleFinderSitePackagesSuite.pathc          &   C   sÄ  d|   d¡fd|   dd¡fd|   dd¡fd|   ddd¡fdtjfd	tjfd
tjfdtjfdtjfdtjfd|   d¡fd|   ddd¡fd|   ddd¡fdtjfd|   dd¡fd|   dd¡fd|   ddd¡fd|   ddd¡fdtjfdtjfdtjfdtjfdtjfd tjfd!tjfd"tjfd#|   d$d#d¡fd%|   d$d&d¡fd'|   d(d)d'd¡fd*|   d(d)d+d¡fd,tjfd-|   d.d/¡fd0tj  td1d¡fg!}x6|D ].\}}d2| d3 }| j |¡}t	|||ƒ qŽW d S )4NÚns_pkg_typedzns_pkg_typed.aza.pyzns_pkg_typed.br'   zns_pkg_typed.b.czc.pyzns_pkg_typed.a.a_varÚns_pkg_untypedzns_pkg_untyped.azns_pkg_untyped.bzns_pkg_untyped.b.czns_pkg_untyped.a.a_varÚns_pkg_w_stubszns_pkg_w_stubs.typedzns_pkg_w_stubs-stubsÚtypedz__init__.pyizns_pkg_w_stubs.typed_inlineÚtyped_inlinez__init__.pyzns_pkg_w_stubs.untypedÚ	pkg_typedzpkg_typed.azpkg_typed.bzpkg_typed.b.czpkg_typed.a.a_varÚpkg_untypedzpkg_untyped.azpkg_untyped.bzpkg_untyped.b.czpkg_untyped.a.a_varÚ
standalonezstandalone.standalone_varÚbaz_pkgr:   zns_baz_pkg.aZ
ns_baz_pkgÚneighbor_pkgz..zmodulefinder-srczns_neighbor_pkg.aZns_neighbor_pkgÚdoes_not_existzfoo.barz	foo-stubszbar.pyir$   r   zFind(z) got {}; expected {})
r   r   r    ÚFOUND_WITHOUT_TYPE_HINTSr   r   r   r   r   r   )r   ÚcasesÚmoduler%   ÚtemplateÚactualr   r   r   Útest__packages_with_ns¯   sL    z4ModuleFinderSitePackagesSuite.test__packages_with_nsc          &   C   sŽ  dt jfdt jfdt jfdt jfdt jfdt jfdt jfdt jfd	t jfd
t jfdt jfdt jfd|  ddd¡fdt jfd|  dd¡fd|  dd¡fd|  ddd¡fd|  ddd¡fdt jfdt jfdt jfdt jfdt jfdt jfdt jfdt jfd |  d!d d¡fd"t jfd#|  d$d%d#d¡fd&t jfd't jfd(|  d)d*¡fd+tj td,d¡fg!}x6|D ].\}}d-| d. }| j |¡}t	|||ƒ qXW d S )/Nr?   zns_pkg_typed.azns_pkg_typed.bzns_pkg_typed.b.czns_pkg_typed.a.a_varr@   zns_pkg_untyped.azns_pkg_untyped.bzns_pkg_untyped.b.czns_pkg_untyped.a.a_varrA   zns_pkg_w_stubs.typedzns_pkg_w_stubs.typed_inlinerC   z__init__.pyzns_pkg_w_stubs.untypedrD   zpkg_typed.aza.pyzpkg_typed.br'   zpkg_typed.b.czc.pyzpkg_typed.a.a_varrE   zpkg_untyped.azpkg_untyped.bzpkg_untyped.b.czpkg_untyped.a.a_varrF   zstandalone.standalone_varrG   r:   zns_baz_pkg.arH   z..zmodulefinder-srczns_neighbor_pkg.arI   zfoo.barz	foo-stubszbar.pyir$   r   zFind(z) got {}; expected {})
r   r    rJ   r   r   r   r   r   r   r   )r   rK   rL   r%   rM   rN   r   r   r   Útest__packages_without_nsí   sL    z7ModuleFinderSitePackagesSuite.test__packages_without_ns)r6   r7   r8   r   Ústrr   rO   rP   r   r   r   r   r9      s   >r9   )r   Zmypy.optionsr   Zmypy.modulefinderr   r   r   Zmypy.test.helpersr   r   Zmypy.test.configr   r   r;   r   r   r	   r9   r   r   r   r   Ú<module>   s    