
    daf0                        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$j1                  d%      z   gZd& Zd' Z G d( d)ej8                        Zed*k(  r ej>                          yy)+    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                  j                  |       }	 t        j                  |       t        | d      S # t        $ r(}|j
                  t
        j                  k7  r Y d }~8d }~ww xY w)Nwb)ospathdirnamemakedirsOSErrorerrnoEEXISTopen)r   r   es      1/root/Python-3.12.4/Lib/test/test_modulefinder.py	open_filer'   "  s^    ggood#G
G d  77ell" #s   A 	A3A..A3c                 4   d }	 |j                         D ]  }t        |      t        k7  r|j                  d      }|j	                  d      s|j	                  d      r#|j                  |j                         dz          k|r|j                          t        |      t        k(  r|j                  d      }t        t        j                  j                  | |j                                     } 	 |r|j                          y y # |r|j                          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DDzU"{{7+t$(>		$**,./IIK:&;;w/DXtzz| DE
	F IIK 3IIK s   C)D D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y)ModuleFinderTestc                     t        j                         | _        | j                  t        j                  j                  t         j                        g| _        y N)tempfilemkdtempr6   r   r   r   __file__	test_pathselfs    r&   setUpzModuleFinderTest.setUp?  s5     ((*--9J9J)KL    c                 B    t        j                  | j                         y r>   )shutilrmtreer6   rC   s    r&   tearDownzModuleFinderTest.tearDownC  s    dmm$rF   Fr   c                    |\  }}}}	}
t        | j                  |
        || j                  ||      }|j                  |       |r|j	                          t        t        |            }t        |j                        }| j                  ||       |j                         \  }}| j                  ||       | j                  ||	       y )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
{#IIK W&rzz"( ))+
Ug&.rF   c                 .    | j                  t               y r>   )r^   package_testrC   s    r&   test_packagezModuleFinderTest.test_packagea  s    l#rF   c                 .    | j                  t               y r>   )r^   
maybe_testrC   s    r&   
test_maybezModuleFinderTest.test_maybed  s    j!rF   c                 .    | j                  t               y r>   )r^   maybe_test_newrC   s    r&   test_maybe_newzModuleFinderTest.test_maybe_newg  s    n%rF   c                 .    | j                  t               y r>   )r^   absolute_import_testrC   s    r&   test_absolute_importsz&ModuleFinderTest.test_absolute_importsj      *+rF   c                 .    | j                  t               y r>   )r^   relative_import_testrC   s    r&   test_relative_importsz&ModuleFinderTest.test_relative_importsm  rk   rF   c                 .    | j                  t               y r>   )r^   relative_import_test_2rC   s    r&   test_relative_imports_2z(ModuleFinderTest.test_relative_imports_2p      ,-rF   c                 .    | j                  t               y r>   )r^   relative_import_test_3rC   s    r&   test_relative_imports_3z(ModuleFinderTest.test_relative_imports_3s  rr   rF   c                 .    | j                  t               y r>   )r^   relative_import_test_4rC   s    r&   test_relative_imports_4z(ModuleFinderTest.test_relative_imports_4v  rr   rF   c                 .    | j                  t               y r>   )r^   syntax_error_testrC   s    r&   test_syntax_errorz"ModuleFinderTest.test_syntax_errory  s    '(rF   c                 .    | j                  t               y 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                  | j                  d      }|t        j
                  j                  d   z   }|t        j
                  j                  d   z   }t        |      5 }|j                  dj                  d             d d d        t        j                  ||       t        j                  |       | j                  t               y # 1 sw Y   KxY w)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    GGLL4	)"5"5"E"Ea"HH!I$7$7$I$I!$LL{# 	HtJJ6==gFG	H;m<
		+m$		H 	Hs   6!C!!C*c                    t         j                  j                  | j                  dd      }t         j                  j                  | j                  dd      }t	        j
                         5 }| j                  t        d||fg       d d d        j                         }d|d|}| j                  ||       y # 1 sw Y   4xY w)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    77<<sK@77<<sI>$$& 	@&MM*A*2H)=(>  @	@ "5=xHh'	@ 	@s   +B::Cc           
      b    dddgg g dt        t        d            z  g}| j                  |       y )Nr   r   zVa.py
                                %r
                                import b
b.py
i   )listranger^   )rD   extended_opargs_tests     r&   test_extended_opargsz%ModuleFinderTest.test_extended_opargs  s@    #J
 5<		  	*+rF   c                 .    | j                  t               y r>   )r^   coding_default_utf8_testrC   s    r&   test_coding_default_utf8z)ModuleFinderTest.test_coding_default_utf8  s    ./rF   c                 .    | j                  t               y r>   )r^   coding_explicit_utf8_testrC   s    r&   test_coding_explicit_utf8z*ModuleFinderTest.test_coding_explicit_utf8  s    /0rF   c                 .    | j                  t               y r>   )r^   coding_explicit_cp1252_testrC   s    r&   test_coding_explicit_cp1252z,ModuleFinderTest.test_coding_explicit_cp1252  s    12rF   c                 d     G d dt         j                        }| j                  t        |       y )Nc                   (     e Zd Z fdZ fdZ xZS )AModuleFinderTest.test_load_module_api.<locals>.CheckLoadModuleApic                 $    t        |   |i | y r>   )super__init__)rD   argskwds	__class__s      r&   r   zJModuleFinderTest.test_load_module_api.<locals>.CheckLoadModuleApi.__init__  s     $/$/rF   c                 4    |\  }}}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w*62xKKrF   )__name__
__module____qualname__r   r   __classcell__)r   s   @r&   CheckLoadModuleApir     s    0L LrF   r   )rV   )modulefinderModuleFinderr^   ri   )rD   r   s     r&   test_load_module_apiz%ModuleFinderTest.test_load_module_api  s*    	L!:!: 	L 	*?Q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<   >  sz    M% %*"YeYrYr /6$"&,,...)-%(,013
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r	,   r B  " J  % P *I  *
  E L"	  !E2	  x	  x	   F7O
	  $uSx(( uSn zHMMO rF   