
    <e0                        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
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%          z   gZd& Zd' Z G d( d)ej                  Zed*k    r ej                     dS 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   mymoduler   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
a_utf8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')
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                     t           j                            |           }	 t          j        |           n-# t          $ r }|j        t
          j        k    r Y d }~nd }~ww xY wt          | d          S )Nwb)ospathdirnamemakedirsOSErrorerrnoEEXISTopen)r   r   es      -/usr/lib/python3.11/test/test_modulefinder.py	open_filer'   "  s    good##G
G   7el"" #"""" ds   6 
A  AA c                    d }	 |                                 D ]}t          |          t          k    r|                    d          }|                    d          s|                    d          r+|                    |                                dz              |r|                                 t          |          t          k    r|                    d          }t          t          j                            | |                                                    }		 |r|                                 d S d S # |r|                                 w w xY w)Nr          	   
)
splitlinestypebytesencode
startswithwritestripclosedecoder'   r   r   join)test_dirsourceofilines       r&   create_packager:   ,  s>   
C%%'' 
	F 
	FDDzzU""{{7++t$$ F(>(> F		$**,,.////  IIKKK::&&;;w//DXtzz|| D DEE
	F  	IIKKKKK	 	3 	IIKKKK	s   DD< <Ec                       e Zd Zd Zd Zddg ej        fdZd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdS )ModuleFinderTestc                     t          j                    | _        | j        t          j                            t           j                  g| _        d S N)tempfilemkdtempr6   r   r   r   __file__	test_pathselfs    r&   setUpzModuleFinderTest.setUp?  s5     (**-9J)K)KL    c                 8    t          j        | j                   d S r>   )shutilrmtreer6   rC   s    r&   tearDownzModuleFinderTest.tearDownC  s    dm$$$$$rF   Fr   c                    |\  }}}}	}
t          | j        |
            || j        ||          }|                    |           |r|                                 t          t          |                    }t          |j                  }|                     ||           |	                                \  }}|                     ||           |                     ||	           d S )N)r   debugreplace_paths)
r:   r6   rB   import_hookreportsortedsetmodulesassertEqualany_missing_maybe)rD   inforO   rL   rM   modulefinder_classimport_thisrR   missingmaybe_missingr7   mffoundbadmaybes                  r&   _do_testzModuleFinderTest._do_testF  s    ?C<Wg}ft}f---T^56CE E E
{### 	IIKKK W&&rz""((( ))++
Ug&&&.....rF   c                 :    |                      t                     d S r>   )r^   package_testrC   s    r&   test_packagezModuleFinderTest.test_packagea  s    l#####rF   c                 :    |                      t                     d S r>   )r^   
maybe_testrC   s    r&   
test_maybezModuleFinderTest.test_maybed  s    j!!!!!rF   c                 :    |                      t                     d S r>   )r^   maybe_test_newrC   s    r&   test_maybe_newzModuleFinderTest.test_maybe_newg  s    n%%%%%rF   c                 :    |                      t                     d S r>   )r^   absolute_import_testrC   s    r&   test_absolute_importsz&ModuleFinderTest.test_absolute_importsj      *+++++rF   c                 :    |                      t                     d S r>   )r^   relative_import_testrC   s    r&   test_relative_importsz&ModuleFinderTest.test_relative_importsm  rk   rF   c                 :    |                      t                     d S r>   )r^   relative_import_test_2rC   s    r&   test_relative_imports_2z(ModuleFinderTest.test_relative_imports_2p      ,-----rF   c                 :    |                      t                     d S r>   )r^   relative_import_test_3rC   s    r&   test_relative_imports_3z(ModuleFinderTest.test_relative_imports_3s  rr   rF   c                 :    |                      t                     d S r>   )r^   relative_import_test_4rC   s    r&   test_relative_imports_4z(ModuleFinderTest.test_relative_imports_4v  rr   rF   c                 :    |                      t                     d S r>   )r^   syntax_error_testrC   s    r&   test_syntax_errorz"ModuleFinderTest.test_syntax_errory  s    '(((((rF   c                 :    |                      t                     d S r>   )r^   same_name_as_bad_testrC   s    r&   test_same_name_as_badz&ModuleFinderTest.test_same_name_as_bad|  s    +,,,,,rF   c                    t           j                            | j        d          }|t          j        j        d         z   }|t          j        j        d         z   }t          |          5 }|	                    d
                    d                     d d d            n# 1 swxY w Y   t          j        ||           t          j        |           |                     t                     d S )Nr   r   ztesting_modulefinder = True
r   )cfile)r   r   r5   r6   	importlib	machinerySOURCE_SUFFIXESBYTECODE_SUFFIXESr'   r1   r/   
py_compilecompileremover^   bytecode_test)rD   	base_pathsource_pathbytecode_pathfiles        r&   test_bytecodezModuleFinderTest.test_bytecode  s   GLL44	)"5"Ea"HH!I$7$I!$LL{## 	HtJJ6==gFFGGG	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H;m<<<<
	+m$$$$$s   ))BB"%B"c                    t           j                            | j        dd          }t           j                            | j        dd          }t	          j                    5 }|                     t          d||fg           d d d            n# 1 swxY w Y   |                                }d|d|}| 	                    ||           d S )Nr   z	module.pyzspam.py   )rL   rM   zco_filename z changed to )
r   r   r5   r6   r   captured_stdoutr^   rc   getvalueassertIn)rD   old_pathnew_pathoutputexpecteds        r&   test_replace_pathsz#ModuleFinderTest.test_replace_paths  s   7<<sK@@7<<sI>>$&& 	@&MM*A*2H)=(>  @ @ @	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ ""5=XXxxHh'''''s    !BBBc           
      |    dddgg g dt          t          d                    z  g}|                     |           d S )Nr   r   zVa.py
                                %r
                                import b
b.py
i   )listranger^   )rD   extended_opargs_tests     r&   test_extended_opargsz%ModuleFinderTest.test_extended_opargs  sQ    #J
 5<<		  	*+++++rF   c                 :    |                      t                     d S r>   )r^   coding_default_utf8_testrC   s    r&   test_coding_default_utf8z)ModuleFinderTest.test_coding_default_utf8  s    ./////rF   c                 :    |                      t                     d S r>   )r^   coding_explicit_utf8_testrC   s    r&   test_coding_explicit_utf8z*ModuleFinderTest.test_coding_explicit_utf8  s    /00000rF   c                 :    |                      t                     d S r>   )r^   coding_explicit_cp1252_testrC   s    r&   test_coding_explicit_cp1252z,ModuleFinderTest.test_coding_explicit_cp1252  s    122222rF   c                 n     G d dt           j                  }|                     t          |           d S )Nc                   (     e Zd Z fdZ fdZ xZS )AModuleFinderTest.test_load_module_api.<locals>.CheckLoadModuleApic                 :     t                      j        |i | d S r>   )super__init__)rD   argskwds	__class__s      r&   r   zJModuleFinderTest.test_load_module_api.<locals>.CheckLoadModuleApi.__init__  s%      $/$/////rF   c                 X    |\  }}}t                                          ||||          S r>   )r   load_module)	rD   fqnamefppathname	file_infosuffixmoder-   r   s	           r&   r   zMModuleFinderTest.test_load_module_api.<locals>.CheckLoadModuleApi.load_module  s-    %."dww**62xKKKrF   )__name__
__module____qualname__r   r   __classcell__)r   s   @r&   CheckLoadModuleApir     sZ        0 0 0 0 0L L L L L L L L LrF   r   )rV   )modulefinderModuleFinderr^   ri   )rD   r   s     r&   test_load_module_apiz%ModuleFinderTest.test_load_module_api  sW    	L 	L 	L 	L 	L!: 	L 	L 	L 	*?QRRRRRrF   N)r   r   r   rE   rJ   r   r   r^   ra   rd   rg   rj   rn   rq   ru   rx   r{   r~   r   r   r   r   r   r   r    rF   r&   r<   r<   >  s\       M M M% % % %*"YeYr / / / /6$ $ $" " "& & &, , ,, , ,. . .. . .. . .) ) )- - -% % %( ( (, , ,0 0 01 1 13 3 3
S 
S 
S 
S 
SrF   r<   __main__) r   r"   importlib.machineryr   r   rH   unittestr?   testr   r   rc   rf   r`   ri   rm   rp   rt   rw   r   rz   r}   r   r   r/   r   r'   r:   TestCaser<   r   mainr   rF   r&   <module>r      s   				                      $ 
 
 
EM?
    EM?  666r	,       r B    " J    % P *I  *
  E L"	  !!!E2	  x	  x	   F7OO
	      $uS uS uS uS uSx( uS uS uSn zHMOOOOO rF   