B
    18\8$                 @   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ddddgdgdgd	gZdddddd
gdgdgdgZdddddddgddgg dgZdddddddd
ddg	ddgg dgZdd
dddddddddddgg g dgZdddddddddddd dd!g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'd( Zd)d* ZG d+d, d,ejZed-kre  dS ).    N)supportza.moduleasysbczb.somethingza/__init__.py
a/module.py
                                from b import something
                                from c import something
b/__init__.py
                                from sys import *
Z
__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 *
za.bza.cZmymoduleZ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
zb.xzb.yzb.z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
za.b.yza.b.zza.b.cza.b.c.moduleCza.b.c.dza.b.c.eza.b.xa  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
za.sysza.b.c.fz	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
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 *
 c          
   C   sV   t j| }yt | W n0 tk
rJ } z|jtjkr: W d d }~X Y nX t| dS )Nw)ospathdirnamemakedirsOSErrorerrnoEEXISTopen)r   r   e r   Z/oak/stanford/groups/akundaje/marinovg/programs/Python-3.7.3/Lib/test/test_modulefinder.py	open_file   s    r   c             C   sx   d }z`xZ|   D ]N}|ds(|dr<|| d  q|rH|  ttjt	| }qW W d |rr|  X d S )N 	
)

splitlines
startswithwritestripcloser   r   r   joinTEST_DIR)sourceZofiliner   r   r   create_package   s    r#   c               @   st   e Zd Zddg 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S )ModuleFinderTestFr   c          	   C   s   |\}}}}}	t |	 zptjt||d}
|
| |r>|
  tt|}t|
j}| 	|| |

 \}}| 	|| | 	|| W d tt X d S )N)r   debugreplace_paths)r#   modulefinderZModuleFinder	TEST_PATHZimport_hookreportsortedsetmodulesassertEqualZany_missing_maybeshutilrmtreer    )selfinfor)   r%   r&   Zimport_thisr,   missingZmaybe_missingr!   Zmffoundbadmayber   r   r   _do_test   s    


zModuleFinderTest._do_testc             C   s   |  t d S )N)r6   package_test)r0   r   r   r   test_package  s    zModuleFinderTest.test_packagec             C   s   |  t d S )N)r6   
maybe_test)r0   r   r   r   
test_maybe  s    zModuleFinderTest.test_maybec             C   s   |  t d S )N)r6   maybe_test_new)r0   r   r   r   test_maybe_new  s    zModuleFinderTest.test_maybe_newc             C   s   |  t d S )N)r6   absolute_import_test)r0   r   r   r   test_absolute_imports  s    z&ModuleFinderTest.test_absolute_importsc             C   s   |  t d S )N)r6   relative_import_test)r0   r   r   r   test_relative_imports"  s    z&ModuleFinderTest.test_relative_importsc             C   s   |  t d S )N)r6   relative_import_test_2)r0   r   r   r   test_relative_imports_2%  s    z(ModuleFinderTest.test_relative_imports_2c             C   s   |  t d S )N)r6   relative_import_test_3)r0   r   r   r   test_relative_imports_3(  s    z(ModuleFinderTest.test_relative_imports_3c             C   s   |  t d S )N)r6   relative_import_test_4)r0   r   r   r   test_relative_imports_4+  s    z(ModuleFinderTest.test_relative_imports_4c          	   C   sr   t jtd}|tjjd  }|tjjd  }t|}|	d W d Q R X t
j||d t | | t d S )Nr   r   ztesting_modulefinder = True
)Zcfile)r   r   r   r    	importlib	machinerySOURCE_SUFFIXESBYTECODE_SUFFIXESr   r   
py_compilecompileremover6   bytecode_test)r0   	base_pathsource_pathbytecode_pathfiler   r   r   test_bytecode.  s    

zModuleFinderTest.test_bytecodec          	   C   sn   t jtdd}t jtdd}t }| jtd||fgd W d Q R X | }d||f }| 	|| d S )Nr   z	module.pyzspam.py   )r%   r&   zco_filename %r changed to %r)
r   r   r   r    r   captured_stdoutr6   r9   getvalueassertIn)r0   Zold_pathnew_pathoutputexpectedr   r   r   test_replace_paths8  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ranger6   )r0   Zextended_opargs_testr   r   r   test_extended_opargsB  s
    z%ModuleFinderTest.test_extended_opargsN)__name__
__module____qualname__r6   r8   r:   r<   r>   r@   rB   rD   rF   rS   r[   r^   r   r   r   r   r$      s   

r$   __main__) r   r   importlib.machineryrG   rK   r.   unittesttempfiletestr   r'   mkdtempr    r   r   __file__r(   r9   r;   r7   r=   r?   rA   rC   rE   rN   r   r#   TestCaser$   r_   mainr   r   r   r   <module>   s   	
Y
