B
    u9a8$  ã               @   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r–e ¡  dS ).é    N)Úsupportza.moduleÚaÚsysÚbÚczb.somethingzÊa/__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.zZ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.barz®a/__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ÚerrnoZEEXISTÚopen)r   r   Úe© r   ú'/usr/lib/python3.7/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ÚmodulesZassertEqualZany_missing_maybeÚshutilZrmtreer   )ÚselfÚinfor'   r#   r$   Zimport_thisr*   ÚmissingZmaybe_missingr   ZmfÚfoundZbadÚmayber   r   r   Ú_do_testø   s    


zModuleFinderTest._do_testc             C   s   |   t¡ d S )N)r1   Úpackage_test)r,   r   r   r   Útest_package  s    zModuleFinderTest.test_packagec             C   s   |   t¡ d S )N)r1   Ú
maybe_test)r,   r   r   r   Ú
test_maybe  s    zModuleFinderTest.test_maybec             C   s   |   t¡ d S )N)r1   Úmaybe_test_new)r,   r   r   r   Útest_maybe_new  s    zModuleFinderTest.test_maybe_newc             C   s   |   t¡ d S )N)r1   Úabsolute_import_test)r,   r   r   r   Útest_absolute_imports  s    z&ModuleFinderTest.test_absolute_importsc             C   s   |   t¡ d S )N)r1   Úrelative_import_test)r,   r   r   r   Útest_relative_imports"  s    z&ModuleFinderTest.test_relative_importsc             C   s   |   t¡ d S )N)r1   Úrelative_import_test_2)r,   r   r   r   Útest_relative_imports_2%  s    z(ModuleFinderTest.test_relative_imports_2c             C   s   |   t¡ d S )N)r1   Úrelative_import_test_3)r,   r   r   r   Útest_relative_imports_3(  s    z(ModuleFinderTest.test_relative_imports_3c             C   s   |   t¡ d S )N)r1   Úrelative_import_test_4)r,   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
)Úcfile)r
   r   r   r   Ú	importlibÚ	machineryÚSOURCE_SUFFIXESÚBYTECODE_SUFFIXESr   r   Ú
py_compileÚcompileÚremover1   Úbytecode_test)r,   Ú	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   Zcaptured_stdoutr1   r4   ÚgetvalueZassertIn)r,   Zold_pathÚnew_pathÚoutputZ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Úranger1   )r,   Zextended_opargs_testr   r   r   Útest_extended_opargsB  s
    z%ModuleFinderTest.test_extended_opargsN)Ú__name__Ú
__module__Ú__qualname__r1   r3   r5   r7   r9   r;   r=   r?   rA   rO   rT   rW   r   r   r   r   r"   ÷   s   

r"   Ú__main__) r
   r   Zimportlib.machineryrC   rG   r+   ZunittestZtempfileZtestr   r%   Zmkdtempr   r   r   Ú__file__r&   r4   r6   r2   r8   r:   r<   r>   r@   rJ   r   r!   ZTestCaser"   rX   Úmainr   r   r   r   Ú<module>   s   	
Y
