o
    2gy3                     @  s   d dl mZ d dlZd dlmZmZmZ d dlmZ d dl	m
Z
 d dlmZmZ ejeje
dZG dd	 d	eZG d
d deZdS )    )annotationsN)FindModuleCacheModuleNotFoundReasonSearchPaths)Options)package_path)Suiteassert_equalmodulefinderc                   @  s   e Zd Zd"ddZd"ddZd"ddZd"d	d
Zd"ddZd"ddZd"ddZ	d"ddZ
d"ddZd"ddZd"ddZd"ddZd"ddZd"ddZd"dd Zd!S )#ModuleFinderSuitereturnNonec                 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 nsx-pkg1nsx-pkg2nsx-pkg3nsy-pkg1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   R/home/garg/my-data/venv/lib/python3.10/site-packages/mypy/test/testmodulefinder.pysetUp   s&   	zModuleFinderSuite.setUpc                 C     | 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%      z2ModuleFinderSuite.test__no_namespace_packages__nsxc                 C  r(   )zJ
        If namespace_packages is False, we shouldn't find nsx.a.
        nsx.aNr*   r-   r   r   r&   "test__no_namespace_packages__nsx_a,   r0   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   a.pyN)r$   r+   r   r   r   r    r	   r%   r.   expectedr   r   r&   +test__no_namespace_packages__find_a_in_pkg13   s   z=ModuleFinderSuite.test__no_namespace_packages__find_a_in_pkg1c                 C  ,   | j d}tjtddd}t|| d S Nbr   __init__.pyr#   r+   r   r   r   r    r	   r5   r   r   r&   +test__no_namespace_packages__find_b_in_pkg2;      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)   r   Nr<   r5   r   r   r&   'test__find_nsx_as_namespace_pkg_in_pkg1@   s   z9ModuleFinderSuite.test__find_nsx_as_namespace_pkg_in_pkg1c                 C  .   | 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.
        r1   r   r)   r3   r;   Nr<   r5   r   r   r&   test__find_nsx_a_init_in_pkg1I      z/ModuleFinderSuite.test__find_nsx_a_init_in_pkg1c                 C  r@   )zP
        Find nsx-pkg2/nsx/b/__init__.py for "nsx.b" in namespace mode.
        znsx.br   r)   r:   r;   Nr<   r5   r   r   r&   test__find_nsx_b_init_in_pkg2Q   rB   z/ModuleFinderSuite.test__find_nsx_b_init_in_pkg2c                 C  r@   )zK
        Find nsx-pkg3/nsx/c/c.py for "nsx.c.c" in namespace mode.
        znsx.c.cr   r)   cc.pyNr<   r5   r   r   r&   test__find_nsx_c_c_in_pkg3Y   rB   z,ModuleFinderSuite.test__find_nsx_c_c_in_pkg3c                 C  r@   )zG
        Prefer nsy-pkg1/a/__init__.pyi file over __init__.py.
        znsy.ar   nsyr3   __init__.pyiNr<   r5   r   r   r&   test__find_nsy_a__init_pyia   rB   z,ModuleFinderSuite.test__find_nsy_a__init_pyic                 C  r@   )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.br   rG   r:   r;   Nr<   r5   r   r   r&   test__find_nsy_b__init_pyi   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.cr   rG   zc.pyiNr<   r5   r   r   r&   test__find_nsy_c_pyis   s   z&ModuleFinderSuite.test__find_nsy_c_pyic                 C  s*   | j d}tjtdd}t|| d S )Nr3   r   r4   r<   r5   r   r   r&   test__find_a_in_pkg1}   s   z&ModuleFinderSuite.test__find_a_in_pkg1c                 C  r8   r9   r<   r5   r   r   r&   test__find_b_init_in_pkg2   r>   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&   test__find_d_nowhere   s   z&ModuleFinderSuite.test__find_d_nowhereNr   r   )__name__
__module____qualname__r'   r/   r2   r7   r=   r?   rA   rC   rF   rI   rJ   rK   rL   rM   rO   r   r   r   r&   r      s     






	








r   c                   @  s4   e Zd ZdddZdddZdd	d
ZdddZdS )ModuleFinderSitePackagesSuiter   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baz..znot-a-directorymodulefinder-srcr   r   r   Tr   F)r   r   relpathr   r   package_dirr   r    tupler!   r   r"   r   r#   r$   )r%   package_pathsr   r   r   r&   r'      s(   z#ModuleFinderSitePackagesSuite.setUppartsstrc                 G  s   t jj| jg|R  S )N)r   r   r   rY   )r%   r\   r   r   r&   r      s   z"ModuleFinderSitePackagesSuite.pathc                 C  s   g 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}|D ]\}}d2| d3 }| j|}t	||| qd S )4Nns_pkg_typedns_pkg_typed.ar4   ns_pkg_typed.br:   ns_pkg_typed.b.crE   ns_pkg_typed.a.a_varns_pkg_untypedns_pkg_untyped.ans_pkg_untyped.bns_pkg_untyped.b.cns_pkg_untyped.a.a_varns_pkg_w_stubsns_pkg_w_stubs.typedzns_pkg_w_stubs-stubstypedrH   ns_pkg_w_stubs.typed_inlinetyped_inliner;   ns_pkg_w_stubs.untyped	pkg_typedpkg_typed.apkg_typed.bpkg_typed.b.cpkg_typed.a.a_varpkg_untypedpkg_untyped.apkg_untyped.bpkg_untyped.b.cpkg_untyped.a.a_var
standalonestandalone.standalone_varbaz_pkgrU   ns_baz_pkg.a
ns_baz_pkgneighbor_pkgrV   rW   ns_neighbor_pkg.ans_neighbor_pkgdoes_not_existfoo.bar	foo-stubsbar.pyir3   r   Find() got {}; expected {})
r   r   r,   FOUND_WITHOUT_TYPE_HINTSr   r   r    r#   r+   r	   r%   casesmoduler6   templateactualr   r   r&   test__packages_with_ns   s   	
 "#%&'(*,.0z4ModuleFinderSitePackagesSuite.test__packages_with_nsc                 C  s  g 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}|D ]\}}d-| d. }| j|}t	||| qd S )/Nr^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rk   rl   r;   rm   rn   ro   r4   rp   r:   rq   rE   rr   rs   rt   ru   rv   rw   rx   ry   rz   rU   r{   r}   rV   rW   r~   r   r   r   r   r3   r   r   r   )
r   r,   r   r   r   r   r    r$   r+   r	   r   r   r   r&   test__packages_without_ns   s   	
 "#%&'(*,.0z7ModuleFinderSitePackagesSuite.test__packages_without_nsNrP   )r\   r]   r   r]   )rQ   rR   rS   r'   r   r   r   r   r   r   r&   rT      s
    


7rT   )
__future__r   r   mypy.modulefinderr   r   r   mypy.optionsr   mypy.test.configr   mypy.test.helpersr   r	   r   rX   r   r    r   rT   r   r   r   r&   <module>   s    