a
    ze0                     @   s  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	 d dl
Z
e Zee jejgZdg ddgdgdgZdg ddgdgd	gZdg d
ddgg dgZdg dddgg dgZdg dg g dgZdg dg g dgZdddgdgg dgZdddgg g dgZddgg g dgZdg ddgg dgZdg ddgg dgZdddgg g d gZdddgg g d!gZd"d"dgg g d#d$d% gZd&d' Z d(d) Z!G d*d+ d+ej"Z#e$d,kre%  dS )-    N)supporta.module)ar   sysbczb.somethingza/__init__.py
a/module.py
                                from b import something
                                from c import something
b/__init__.py
                                from sys import *
)r   r   r   r   
__future__a  a/__init__.py
a/module.py
                                from b import something
                                from c import something
b/__init__.py
                                from __future__ import absolute_import
                                from sys import *
)r   a.bza.cr   Zmymoduler   Zblahblaha  mymodule.py
a/__init__.py
                                import blahblah
                                from a import b
                                import c
a/module.py
                                import sys
                                from a import b as x
                                from a.c import sillyname
a/b.py
a/c.py
                                from a.module import x
                                import mymodule as sillyname
                                from sys import version_info
)	r   r   r   zb.xzb.yzb.zr   r   gczaj  mymodule.py
a/__init__.py
a/module.py
                                from __future__ import absolute_import
                                import sys # sys
                                import blahblah # fails
                                import gc # gc
                                import b.x # b.x
                                from b import y # b.y
                                from b.z import * # b.z.*
a/gc.py
a/sys.py
                                import mymodule
a/b/__init__.py
a/b/x.py
a/b/y.py
a/b/z.py
b/__init__.py
                                import z
b/unused.py
b/x.py
b/y.py
b/z.py
)r   r   r   r	   a.b.ya.b.za.b.ca.b.c.moduleCa.b.c.da.b.c.ea.b.xr
   a  mymodule.py
a/__init__.py
                                from .b import y, z # a.b.y, a.b.z
a/module.py
                                from __future__ import absolute_import # __future__
                                import gc # gc
a/gc.py
a/sys.py
a/b/__init__.py
                                from ..b import x # a.b.x
                                #from a.b.c import moduleC
                                from .c import moduleC # a.b.moduleC
a/b/x.py
a/b/y.py
a/b/z.py
a/b/g.py
a/b/c/__init__.py
                                from ..c import e # a.b.c.e
a/b/c/moduleC.py
                                from ..c import d # a.b.c.d
a/b/c/d.py
a/b/c/e.py
a/b/c/x.py
)r   r   za.sysr	   r   r   r   r   r   r   za.b.c.fr   z	a.anothera  mymodule.py
a/__init__.py
                                from . import sys # a.sys
a/another.py
a/module.py
                                from .b import y, z # a.b.y, a.b.z
a/gc.py
a/sys.py
a/b/__init__.py
                                from .c import moduleC # a.b.c.moduleC
                                from .c import d # a.b.c.d
a/b/x.py
a/b/y.py
a/b/z.py
a/b/c/__init__.py
                                from . import e # a.b.c.e
a/b/c/moduleC.py
                                #
                                from . import f   # a.b.c.f
                                from .. import x  # a.b.x
                                from ... import another # a.another
a/b/c/d.py
a/b/c/e.py
a/b/c/f.py
r   za.barza/__init__.py
                                def foo(): pass
a/module.py
                                from . import foo
                                from . import bar
zza/__init__.py
                                def foo(): pass
a/module.py
                                from . import *
 )r   r   r   zb.moduleza/__init__.py
a/module.py
                                import b.module
b/__init__.py
b/module.py
                                ?  # SyntaxError: invalid syntax
)r   r   r   zb.cza/__init__.py
a/module.py
                                import c
                                from b import c
b/__init__.py
b/c.py
Za_utf8Zb_utf8u  a_utf8.py
                                # use the default of utf8
                                print('Unicode test A code point 2090 ₐ that is not valid in cp1252')
                                import b_utf8
b_utf8.py
                                # use the default of utf8
                                print('Unicode test B code point 2090 ₐ that is not valid in cp1252')
uz  a_utf8.py
                                # coding=utf8
                                print('Unicode test A code point 2090 ₐ that is not valid in cp1252')
                                import b_utf8
b_utf8.py
                                # use the default of utf8
                                print('Unicode test B code point 2090 ₐ that is not valid in cp1252')
Za_cp1252s   a_cp1252.py
                                # coding=cp1252
                                # 0xe2 is not allowed in utf8
                                print('CP1252 test Pt')
                                import b_utf8
u   b_utf8.py
                                # use the default of utf8
                                print('Unicode test A code point 2090 ₐ that is not valid in cp1252')
utf-8c              
   C   sX   t j| }zt | W n2 tyL } z|jtjkr8 W Y d }~n
d }~0 0 t| dS )Nwb)ospathdirnamemakedirsOSErrorerrnoEEXISTopen)r   r   e r   ,/usr/lib/python3.9/test/test_modulefinder.py	open_file%  s    r!   c                 C   s   d }z|   D ]z}t|tkr(|d}|ds<|drP|| d  q|r\|  t|tkrr|d}t	t
jt| }qW |r|  n|r|  0 d S )Nr          	   
)
splitlinestypebytesencode
startswithwritestripclosedecoder!   r   r   joinTEST_DIR)sourceZofiliner   r   r    create_package/  s     


r2   c                   @   s   e Zd Zddg ejf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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'S )(ModuleFinderTestFr   c              	   C   s   |\}}}}	}
t |
 zx|t||d}|| |r<|  tt|}t|j}| || | \}}| || | ||	 W t	
t nt	
t 0 d S )N)r   debugreplace_paths)r2   	TEST_PATHZimport_hookreportsortedsetmodulesZassertEqualZany_missing_maybeshutilrmtreer/   )selfinfor7   r4   r5   modulefinder_classZimport_thisr:   missingZmaybe_missingr0   ZmffoundZbadmayber   r   r    _do_testB  s     


zModuleFinderTest._do_testc                 C   s   |  t d S N)rC   package_testr=   r   r   r    test_package`  s    zModuleFinderTest.test_packagec                 C   s   |  t d S rD   )rC   
maybe_testrF   r   r   r    
test_maybec  s    zModuleFinderTest.test_maybec                 C   s   |  t d S rD   )rC   maybe_test_newrF   r   r   r    test_maybe_newf  s    zModuleFinderTest.test_maybe_newc                 C   s   |  t d S rD   )rC   absolute_import_testrF   r   r   r    test_absolute_importsi  s    z&ModuleFinderTest.test_absolute_importsc                 C   s   |  t d S rD   )rC   relative_import_testrF   r   r   r    test_relative_importsl  s    z&ModuleFinderTest.test_relative_importsc                 C   s   |  t d S rD   )rC   relative_import_test_2rF   r   r   r    test_relative_imports_2o  s    z(ModuleFinderTest.test_relative_imports_2c                 C   s   |  t d S rD   )rC   relative_import_test_3rF   r   r   r    test_relative_imports_3r  s    z(ModuleFinderTest.test_relative_imports_3c                 C   s   |  t d S rD   )rC   relative_import_test_4rF   r   r   r    test_relative_imports_4u  s    z(ModuleFinderTest.test_relative_imports_4c                 C   s   |  t d S rD   )rC   syntax_error_testrF   r   r   r    test_syntax_errorx  s    z"ModuleFinderTest.test_syntax_errorc                 C   s   |  t d S rD   )rC   same_name_as_bad_testrF   r   r   r    test_same_name_as_bad{  s    z&ModuleFinderTest.test_same_name_as_badc                 C   s   t jtd}|tjjd  }|tjjd  }t| }|	d
d W d    n1 s\0    Y  tj||d t | | t d S )Nr   r   ztesting_modulefinder = True
r   )cfile)r   r   r.   r/   	importlib	machinerySOURCE_SUFFIXESBYTECODE_SUFFIXESr!   r*   r(   
py_compilecompileremoverC   bytecode_test)r=   	base_pathsource_pathbytecode_pathfiler   r   r    test_bytecode~  s    
.
zModuleFinderTest.test_bytecodec                 C   s   t jtdd}t jtdd}t &}| jtd||fgd W d    n1 sT0    Y  | }d||f }| 	|| d S )Nr   z	module.pyzspam.py   )r4   r5   zco_filename %r changed to %r)
r   r   r.   r/   r   Zcaptured_stdoutrC   rH   getvalueZassertIn)r=   Zold_pathnew_pathoutputZexpectedr   r   r    test_replace_paths  s    
$z#ModuleFinderTest.test_replace_pathsc                 C   s,   dddgg g dt td g}| | d S )Nr   r   zVa.py
                                %r
                                import b
b.py
i   )listrangerC   )r=   Zextended_opargs_testr   r   r    test_extended_opargs  s    

z%ModuleFinderTest.test_extended_opargsc                 C   s   |  t d S rD   )rC   coding_default_utf8_testrF   r   r   r    test_coding_default_utf8  s    z)ModuleFinderTest.test_coding_default_utf8c                 C   s   |  t d S rD   )rC   coding_explicit_utf8_testrF   r   r   r    test_coding_explicit_utf8  s    z*ModuleFinderTest.test_coding_explicit_utf8c                 C   s   |  t d S rD   )rC   coding_explicit_cp1252_testrF   r   r   r    test_coding_explicit_cp1252  s    z,ModuleFinderTest.test_coding_explicit_cp1252c                 C   s$   G dd dt j}| jt|d d S )Nc                       s(   e Zd Z fddZ fddZ  ZS )zAModuleFinderTest.test_load_module_api.<locals>.CheckLoadModuleApic                    s   t  j|i | d S rD   )super__init__)r=   argskwds	__class__r   r    rw     s    zJModuleFinderTest.test_load_module_api.<locals>.CheckLoadModuleApi.__init__c                    s   |\}}}t  ||||S rD   )rv   load_module)r=   Zfqnamefppathname	file_infosuffixmoder&   rz   r   r    r|     s    
zMModuleFinderTest.test_load_module_api.<locals>.CheckLoadModuleApi.load_module)__name__
__module____qualname__rw   r|   __classcell__r   r   rz   r    CheckLoadModuleApi  s   r   )r?   )modulefinderModuleFinderrC   rL   )r=   r   r   r   r    test_load_module_api  s    	z%ModuleFinderTest.test_load_module_apiN)r   r   r   r   r   rC   rG   rI   rK   rM   rO   rQ   rS   rU   rW   rY   rg   rl   ro   rq   rs   ru   r   r   r   r   r    r3   A  s$   

r3   __main__)&r   r   Zimportlib.machineryr[   r_   r;   Zunittesttempfiletestr   r   mkdtempr/   r   r   __file__r6   rH   rJ   rE   rL   rN   rP   rR   rT   rb   rV   rX   rp   rr   r(   rt   r!   r2   ZTestCaser3   r   mainr   r   r   r    <module>   s   !%	(	
s
