a
    	3jG"                     @   s   d dl mZ d dl mZ e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mZ ddlZddlZG dd dejZG d	d
 d
eZejeed\ZZG dd deZejeed\ZZG dd deZejeed\ZZedkre  dS )   )abc)utilzimportlib.machinery    N)make_legacy_pycc                   @   s   e Zd ZdZdd Zdd Zd"ddddd	Zd
d Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zeejdkddd Zd d! ZdS )#FinderTestsaE  For a top-level module, it should just be found directly in the
    directory being searched. This is true for a directory with source
    [top-level source], bytecode [top-level bc], or both [top-level both].
    There is also the possibility that it is a package [top-level package], in
    which case there will be a directory with the module name and an
    __init__.py file. If there is a directory without an __init__.py an
    ImportWarning is returned [empty dir].

    For sub-modules and sub-packages, the same happens as above but only use
    the tail end of the name [sub module] [sub package] [sub empty].

    When there is a conflict between a package and module having the same name
    in the same directory, the package wins out [package over module]. This is
    so that imports of modules within the package can occur rather than trigger
    an import error.

    When there is a package and module with the same name, always pick the
    package over the module [package over module]. This is so that imports from
    the package have the possibility of succeeding.

    c                 C   s4   | j j| j jf| j j| j jfg}| j j|g|R  S N)	machinerySourceFileLoaderSOURCE_SUFFIXESSourcelessFileLoaderBYTECODE_SUFFIXES
FileFinder)selfrootloader_details r   b/www/server/python_manager/versions/3.9.10/lib/python3.9/test/test_importlib/source/test_finder.py
get_finder)   s    zFinderTests.get_finderc                 C   s   |  |}| j||ddS )NTloader_only)r   _find)r   r   modulefinderr   r   r   import_0   s    
zFinderTests.import_Ncompile_unlinkc          	      C   s   |du r|h}t j| }|r6|D ]}t||  q"|r|D ]V}t||  zt||  W q> ty } z|jtj	kr~ W Y d}~q>d}~0 0 q>| 
|d |}| t|d |W  d   S 1 s0    Y  dS )zTest the finding of 'test' with the creation of modules listed in
        'create'.

        Any names listed in 'compile_' are byte-compiled. Modules
        listed in 'unlink' have their source files deleted.

        N.rootload_module)r   create_modules
py_compilecompileosr   r   OSErrorerrnoENOENTr   
assertTruehasattr)	r   testZcreater   r   mappingnameerrorloaderr   r   r   run_test4   s"    zFinderTests.run_testc                 C   s2   |  d | j ddhdhd | j ddhd d S )NZ	top_levelr   r   r-   r   r   r   r   test_moduleQ   s
    

zFinderTests.test_modulec                 C   s>   |  ddh | j ddhdhdhd | j ddhdhd d S )NZpkgpkg.__init__r   r.   r/   r0   r   r   r   test_package[   s
    zFinderTests.test_packagec                 C   s\   t dd<}tj|d }| |d}| t|d W d    n1 sN0    Y  d S )Nr2   pkg.subr   r   r   r"   pathdirnamer   r&   r'   )r   r)   pkg_dirr,   r   r   r   test_module_in_packagee   s    z"FinderTests.test_module_in_packagec                 C   s`   t dd}|<}tj|d }| |d}| t|d W d    n1 sR0    Y  d S )Nr2   zpkg.sub.__init__r4   r   r5   )r   contextr)   r8   r,   r   r   r   test_package_in_packagel   s
    z#FinderTests.test_package_in_packagec                 C   s0   d}|  |d||h}| d|| d S )NZ_tempz{0}.__init____init__)r-   formatZassertInget_filename)r   r*   r,   r   r   r   test_package_over_modulet   s    z$FinderTests.test_package_over_modulec                 C   sH   t d*}| |d d}| | W d    n1 s:0    Y  d S )NZblahr   Z
sdfsadsadf)r   r   r   assertIsNone)r   r)   Znothingr   r   r   test_failurey   s    zFinderTests.test_failurec              	   C   s   | j d| j j| j jf}tdd}|d W d    n1 sD0    Y  z.| j|ddd}| t|d W t	
d nt	
d 0 d S )	N zmod.pywz# test file for importlibmodTr   r   )r   r   r	   r
   openwriter   r&   r'   r"   r   )r   r   filer,   r   r   r   test_empty_string_for_dir~   s    (z%FinderTests.test_empty_string_for_dirc                 C   s:   | j d| j j| j jf}d|_|  | |jd d S )NrB   *   )r   r   r	   r
   _path_mtimeinvalidate_cachesassertEqual)r   r   r   r   r   test_invalidate_caches   s    z"FinderTests.test_invalidate_cachesc                 C   st   d}t |8}| |d }| j|ddd}| | W d    n1 sL0    Y  | j|ddd}| | d S )NrD   r   Tr   )r   r   r   r   ZassertIsNotNoner@   )r   rD   r)   r   foundr   r   r   test_dir_removal_handling   s    (z%FinderTests.test_dir_removal_handlingwin32z>os.chmod() does not support the needed arguments under Windowsc                    sn   t  }t|jj  fdd}| || t|jtjtj	B  | 
|j}| |d}| || j d S )Nc                    s    t | j  | ddd dS )zCleanup function for the temporary directory.

            Since we muck with the permissions, we want to set them back to
            their original values to make sure the directory can be properly
            cleaned up.

            N)r"   chmodr*   __exit__)tempdirZoriginal_moder   r   cleanup   s    z3FinderTests.test_no_read_directory.<locals>.cleanupdoesnotexist)tempfileTemporaryDirectoryr"   statr*   st_modeZ
addCleanuprR   S_IWUSRS_IXUSRr   r   rM   	NOT_FOUND)r   rT   rV   r   rO   r   rU   r   test_no_read_directory   s    z"FinderTests.test_no_read_directoryc                 C   sR   t  6}| |j}| |d}| || j W d    n1 sD0    Y  d S )NrW   )rX   NamedTemporaryFiler   r*   r   rM   r^   )r   Zfile_objr   rO   r   r   r   test_ignore_file   s    
zFinderTests.test_ignore_file)N)__name__
__module____qualname____doc__r   r   r-   r1   r3   r9   r;   r?   rA   rH   rN   rP   unittestZ
skipUnlesssysplatformr_   ra   r   r   r   r   r      s$   

		
r   c                   @   s   e Zd ZdZdddZdS )FinderTestsPEP451NFc                 C   s   | |}|d ur|jS |S r   )	find_specr,   )r   r   r*   r   specr   r   r   r      s    
zFinderTestsPEP451._find)Frb   rc   rd   r^   r   r   r   r   r   ri      s   ri   )r   c                   @   s   e Zd Zdg fZdddZdS )FinderTestsPEP420NFc                 C   sR   t  6 t dt ||}|r,|d n|W  d    S 1 sD0    Y  d S )Nignorer   )warningscatch_warningssimplefilterDeprecationWarningfind_loader)r   r   r*   r   Zloader_portionsr   r   r   r      s    

zFinderTestsPEP420._find)Frl   r   r   r   r   rm      s   rm   c                   @   s   e Zd ZdZdddZdS )FinderTestsPEP302NFc                 C   sB   t  & t dt ||W  d    S 1 s40    Y  d S )Nrn   )ro   rp   rq   rr   find_module)r   r   r*   r   r   r   r   r      s    
zFinderTestsPEP302._find)Frl   r   r   r   r   rt      s   rt   __main__)rB   r   r   Zimport_importlibr   r$   r"   r    rZ   rg   rX   Ztest.supportr   rf   ro   r   ri   Z	test_bothZFrozen_FinderTestsPEP451ZSource_FinderTestsPEP451rm   ZFrozen_FinderTestsPEP420ZSource_FinderTestsPEP420rt   ZFrozen_FinderTestsPEP302ZSource_FinderTestsPEP302rb   mainr   r   r   r   <module>   s6   
 .