Your IP : 216.73.216.213


Current Path : /proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/test_import.cpython-34.pyo

�
g f��@s�ddlZddlZddlmZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
jZddlZddlZddlZddlZddlZddlmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$ddlm%Z%ej&ej'd�Z(dd�Z)ej*ddd	d
��Z+Gdd�dej,�Z-e(Gd
d�dej,��Z.Gdd�dej,�Z/Gdd�dej,�Z0Gdd�dej,�Z1Gdd�dej,�Z2Gdd�dej,�Z3Gdd�dej,�Z4e#Gdd�dej,��Z5e#Gdd�dej,��Z6Gdd �d ej,�Z7e8d!kr�ej9�ndS)"�N)�_get_sourcefile)�EnvironmentVarGuard�TESTFN�check_warnings�forget�	is_jython�make_legacy_pyc�rmtree�run_unittest�	swap_attr�	swap_item�
temp_umask�unlink�unload�create_empty_file�cpython_only�TESTFN_UNENCODABLE)�
script_helperz*test meaningful only when writing bytecodecCsLx;|d|d|d|d|dfD]}t|�q*Wtd�dS)Nz.pyz.pycz.pyoz.pywz	$py.class�__pycache__)rr	)�name�f�r�5/opt/alt/python34/lib64/python3.4/test/test_import.py�remove_files s
r�ccs�|p	d}tj���}tj|||�}tjj|d�}z2tjjd|�||fVtjj|�Wd|dk	r�|tj|<n|tjkr�tj|=nXWdQXdS)NZspamr)	rZtemp_dir�make_script�sys�modules�pop�path�insert�remove)r�sourceZtempdirrZ
old_modulerrr�_ready_to_import*sr#c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zddd
�Zdd�Z	dd�Z
dd�Zedd��Z
dd�Zdd�Zdd�Zdd�Zedd��Zd d!�Zd"d#�Zd$S)%�ImportTestscCstt�tj�dS)N)rr�	importlib�invalidate_caches)�selfrrr�setUpAs
zImportTests.setUpcCstt�dS)N)rr)r'rrr�tearDownEszImportTests.tearDownc	Cs&|jt��ddl}WdQXdS)Nr)�assertRaises�ImportError�RAnDoM)r'r,rrr�test_case_sensitivityHsz!ImportTests.test_case_sensitivitycCsddlm}dS)Nr)�double_const)�testr.)r'r.rrr�test_double_constNszImportTests.test_double_constcs��fdd�}tjjdtj�zP|d�tjjd�rwx-dddd	d
dgD]}||�q`WnWdtjd=XdS)Nc	s�t|}td}tr'td}n
td}t|d��a}td|dd|�tjd�}tjd�}td	|d|�td
|d|�WdQXttjkr�tjt=ntj	�z�yt
t�}Wn<tk
r}z�jd||f�WYdd}~XnX�j
|j|d|��j
|j|d|�Wdtt�t|�t|�t|�XdS)
Nz.pyoz	$py.classz.pyc�wz)# This tests Python's ability to import azfile.�filei�za =zb =zimport from %s failed: %sz'module loaded (%s) but contents invalid)rr�open�print�randomZ	randrangerrr%r&�
__import__r+�fail�assertEqual�a�brr)	�extr"ZpyoZpycrr9r:�mod�err)r'rr�test_with_extensionTs8





*


z4ImportTests.test_import.<locals>.test_with_extensionrz.py�winz.PYz.Pyz.pYz.pywz.PYWz.pYw)rrr �os�curdir�platform�
startswith)r'r>r;r)r'r�test_importSs$
zImportTests.test_importZlonglistc"Cs|d}t|d��E}|jd�x!td�D]}|jd�q6W|jd�WdQXztj|�Wdt|�Xtjjd�t	j
�i}z"t|�td|d|�Wdtjd=t|d
�t|d�|j
�ytj|=Wntk
rYnXXdS)
Nz.pyr1zd = [
i�z"",
�]rzimport ��c�o���)r3�write�range�
py_compile�compilerrr�appendr%r&r�exec�clearr�KeyError)r'�module�filenamer�i�	namespacerrr�test_module_with_large_stack�s.






z(ImportTests.test_module_with_large_stackcCs�td}t|d��}tdd|�WdQXtjjdtj�tj	�ttj
krntj
t=nzKxDdddgD]3}|jtt
t�|jttj
d	|�q�WWdtjd=tt�XdS)
Nz.pyr1za = 1/0r2rrF��z'damaged module in sys.modules on %i try)rr3r4rrr r@rAr%r&rr*�ZeroDivisionErrorr6ZassertNotInr)r'r"rrTrrr�test_failing_import_sticks�s



z&ImportTests.test_failing_import_stickscCssddl}ddl}|j|||j�|jt|jd��ddlj}|j||j|j�dS)Nr�__file__)r/�test.support�assertIs�__name__�
assertTrue�hasattr�support)r'�xr/�yrrr�test_import_name_binding�sz$ImportTests.test_import_name_bindingcCsTttjd}t|d��}|jd�WdQXtjjdtj�z�t	t�}|j
ttj�|j|j
dd�|j|jdd�tt�t|d��}|jd�WdQX|jttj|�tjjt�}|j|d	�|j|j
d
d�|j|jdd�Wdtjd=tt�tt�XdS)N�pyr1z
a = 1
b=2
rrFz!module has wrong attribute valuesrWza = 10
b=20//0
z$expected module to be in sys.modules�
)rr@�extsepr3rJrrr rAr6�assertInrr8r9r:rr*rYr%�reload�getZassertIsNotNoner)r'r"rr<rrr�test_failing_reload�s(


zImportTests.test_failing_reloadcCstd}t|d��}|jd�WdQXtjjdtj�z�tt�}|j	|j
jd��tj|�tj
t=t|�tj�tt�}tjj|j
�\}}|j|d�Wdtjd=tt�ttj
krtj
t=nXdS)Nz.pyr1ztest = None
r�.pyc�.pyo)rlrm)rr3rJrrr r@rAr6r_r[�endswithr!rrr%r&�splitextrhr)r'r"rr<�baser;rrr�test_file_to_source�s$






zImportTests.test_file_to_sourcecCs�tjjt�}tj�}y|j|�Wn(tk
rY|jdj	|��YnX|j
t��}t|�WdQXdS)Nzpath is not encodable to {})
r@r�abspathrr�getfilesystemencoding�encode�UnicodeEncodeError�skipTest�formatr*r+r6)r'r�encodingrGrrr�test_import_by_filenames
z#ImportTests.test_import_by_filenamecCs/tjdttjd��}tj|�dS)Nrz�            import sys
            class C:
               def __del__(self):
                  import importlib
            sys.argv.insert(0, C())
            )rrr�textwrap�dedent�assert_python_ok)r'Ztestfnrrr�!test_import_in_del_does_not_crashsz-ImportTests.test_import_in_del_does_not_crashcCstjjdtj�z�td}tjj|�}t	|d��}WdQXytj
|d�Wnztk
r�|jd�Yn\t
k
r�}z<|jttdd�kr��n|jd	j|��WYdd}~XnXtt�tj|�Wdtjd=tt�XdS)Nrz.pyr1rW�!�z-cannot set modification time to large integerZ	EOVERFLOWz2cannot set modification time to large integer ({})l���l���)r�r�)rrr r@rArr%�util�cache_from_sourcer3�utime�
OverflowErrorrv�OSError�errno�getattrrwr6�statr)r'r"Zcompiledr�errr�test_timestamp_overflows$

)

z#ImportTests.test_timestamp_overflowcCs=ytdddg�Wntk
r8|jd�YnXdS)NZhttp�fromlistZblahzfromlist must allow bogus names)r6r+r7)r'rrr�test_bogus_fromlist3s
zImportTests.test_bogus_fromlistcCsAddg}tj|�}|j�\}}|jd|�dS)Nz-cz&del __builtins__.__import__; import ossImportError)rZspawn_pythonZcommunicaterh)r'�args�popen�stdout�stderrrrr�test_delete_builtins_import9sz'ImportTests.test_delete_builtins_importc	Cs-|jtd��ddlm}WdQXdS)Nz^No module named 'bogus'r)�foo)�assertRaisesRegexr+�bogusr�)r'r�rrr�/test_from_import_message_for_nonexistent_module@sz;ImportTests.test_from_import_message_for_nonexistent_modulec	Cs-|jtd��ddlm}WdQXdS)Nz^cannot import name 'bogus'r)r�)r�r+�rer�)r'r�rrr�,test_from_import_message_for_existing_moduleDsz8ImportTests.test_from_import_message_for_existing_moduleN)r^�
__module__�__qualname__r(r)r-r0rDrVrZrdrk�skip_if_dont_write_bytecoderqryr}r�r�rr�r�r�rrrrr$?s".(&
r$c@s�eZdZejejdkd�dd��Zejejdkd�dd��Zejejdkd�dd��Z	d	d
�Z
dS)�FilePermissionTests�posixz%test meaningful only on posix systemscCs�d}t|��lt��\\}}tjj|�}t|�}tjj|�se|j	d�ntj
|�}WdQXWdQX|jtt
j
|j��td|@��dS)N�zC__import__ did not result in creation of either a .pyc or .pyo filei�)r
r#r%r�r�r6r@r�existsr7r�r8�oct�S_IMODE�st_mode)r'�maskrr�cached_pathrR�	stat_inforrr�test_creation_modeMsz&FilePermissionTests.test_creation_modecCs�d}td��zt��j\}}tjj|�}tj||�t|�tjj	|�ss|j
d�ntj|�}WdQXWdQX|jt
tj|j��t
|��dS)Ni�r�zC__import__ did not result in creation of either a .pyc or .pyo file)r
r#r%r�r�r@�chmodr6rr�r7r�r8r�r�r�)r'�moderrr�r�rrr�test_cached_mode_issue_2051^s
z/FilePermissionTests.test_cached_mode_issue_2051cCs�d}td��zt��j\}}tjj|�}tj||�t|�tjj	|�ss|j
d�ntj|�}WdQXWdQX|dB}|jt
tj|j��t
|��dS)N�r�zC__import__ did not result in creation of either a .pyc or .pyo file�)r
r#r%r�r�r@r�r6rr�r7r�r8r�r�r�)r'r�rrr�r�Zexpectedrrr�test_cached_readonlyns

z(FilePermissionTests.test_cached_readonlycCsjt��[\}}t|d��}|jd�WdQXtj|�}tj||j|jdf�tj|d�t	|�}|j
|jd�tj|d�t|d��}|jd�WdQXt|�t
j�t	|�}|j
|jd�t|�t|�t
j�|d	}tjt
jj|�|�t	|�}|j
|jd�WdQXdS)
Nr1zx = 'original'
i�r�Zoriginali�zx = 'rewritten'
Z	rewrittenrH)r#r3rJr@r�r��st_atime�st_mtimer�r6r8rbrr%r&r�renamer�r�)r'rrr�s�mZ
bytecode_onlyrrr�test_pyc_always_writable~s, 





z,FilePermissionTests.test_pyc_always_writableN)r^r�r��unittest�
skipUnlessr@rr�r�r�r�rrrrr�Isr�c@s�eZdZdZdZejje�Z	ejj
e	e�ejdZe
jje�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Zdd�ZdS)�PycRewritingTestsZunlikely_module_namez�
import sys
code_filename = sys._getframe().f_code.co_filename
module_filename = __file__
constant = 1
def func():
    pass
func_filename = func.__code__.co_filename
rec	Cs�tjdd�|_tjj|jd�|_tj|j	�t
|jd��}|j|j
�WdQXtjjd|j	�tj�dS)Nr1r)rr�sys_pathrr�module_name�orig_moduler@�mkdir�dir_namer3�	file_namerJ�
module_sourcer r%r&)r'rrrrr(�szPycRewritingTests.setUpcCss|jtjdd�<|jdk	r;|jtj|j<n
t|j�t|j�t|j	�t
|j�dS)N)r�rrr�rr�rrr��
compiled_namer	r�)r'rrrr)�s


zPycRewritingTests.tearDowncCs*t�}t|j||�tj|jS)N)�globalsr6r�rr)r'�nsrrr�
import_module�s	zPycRewritingTests.import_modulecCs�|j�}|j|j|j�|j|j|j�|j|j|j�tj|j=|j�}|j|j|j�|j|j|j�|j|j|j�dS)N)	r�r8�module_filenamer��
code_filename�
func_filenamerrr�)r'r<rrr�test_basics�s
zPycRewritingTests.test_basicscCshtj|jdd�|j�}|j|j|j�|j|j|j�|j|j|j�dS)N�dfilezanother_module.py)rLrMr�r�r8r�r�r�)r'r<rrr�test_incorrect_code_name�s
z*PycRewritingTests.test_incorrect_code_namecCs�d}tj|jd|�tj|j�t|j�}tj�|j�}|j	|j
|�|j	|j|�|j	|j|�dS)Nzanother_module.pyr�)
rLrMr�r@r!rr%r&r�r8r�r�r�)r'�target�pyc_filer<rrr�test_module_without_source�s
z,PycRewritingTests.test_module_without_sourcecCsJtj|j�t|jd��%}|jd�}tj|�}WdQXt|j	�}t
jj}|j
d�}|||<t|�|j|j|j|j|j|jt|�|j|j|j|j|j|j|j|j�}t|jd��$}|j|�tj||�WdQX|j�}|j |j!j|j�dS)N�rb�rF�wb)"rLrMr�r3r��read�marshal�load�list�	co_constsr%r��__code__�index�type�co_argcount�co_kwonlyargcount�
co_nlocals�co_stacksize�co_flags�co_code�tuple�co_names�co_varnames�co_filename�co_name�co_firstlineno�	co_lnotab�co_freevars�co_cellvarsrJ�dumpr8Zconstant)r'r�header�codeZ	constantsZforeign_code�posr<rrr�test_foreign_code�s&

z#PycRewritingTests.test_foreign_codeN)r^r�r�r�r�r@rrrrr��joinrgr�r%r�r�r�r(r)r�r�r�r�r�rrrrr��s	 	
r�c@sgeZdZdZeZdd�Zdd�Zd	d
�Ze	j
ejdkd�d
d��Z
dS)�
PathsTestsr/�testäöüß�testéè�
test°³²cCs*tj|j�tjdd�|_dS)N)r@r�rr�syspath)r'rrrr(szPathsTests.setUpcCs't|j�|jtjdd�<dS)N)r	rr�r)r'rrrr)s
zPathsTests.tearDownc	Cs{ttjj|jd�d��}|jd�WdQXtjj|jd�td�}|j|j	d�t
d�dS)Nztest_trailing_slash.pyr1z testdata = 'test_trailing_slash'�/�test_trailing_slash)r3r@rr�rJrrNr6r8�testdatar)r'rr<rrrr�s$zPathsTests.test_trailing_slash�win32zWindows-specificc	%Cs�ttjj|jd�d��}|jd�WdQXtj�tjj|j�}ddl}|j	�}|d}d||f}||dd�7}ytj
|�WnZtk
r	}z:|jtj
tjfkr�|jd|f�n�WYdd}~XnXtjjd|�ytd�}Wn<tk
rk}z|jd	||f�WYdd}~XnX|j|jd�|j|jj|�|j�td�dS)
Nztest_unc_path.pyr1ztestdata = 'test_unc_path'rz\\%s\%s$rWz%cannot access administrative share %rZ
test_unc_pathz,could not import 'test_unc_path' from %r: %r)r3r@rr�rJr%r&rr�socketZgethostname�listdirr�r�ZEPERMZEACCESrvrr r6r+r7r8r�r_r[rCr)	r'rrr�ZhnZdriveZuncr�r<rrr�
test_UNC_paths0$

	!zPathsTests.test_UNC_pathN)ztestr�r�r�)r^r�r�ZSAMPLESrrr(r)r�r�r�rrBr�rrrrr��s	r�c@sFeZdZdd�ZeZdd�Zdd�Zdd�Zd	S)
�RelativeImportTestscCstd�dS)Nztest.relimport)r)r'rrrr)5szRelativeImportTests.tearDowncCs*ddlm}|jt|d��dS)NrF)�	relimportr�)rr�r_r`)r'r�rrr�test_relimport_star9sz'RelativeImportTests.test_relimport_starcs��fdd�}tdddd��|�tdddd��|�tdddd��|jt|�tdddd��|jt|�tdt���|jt|�dS)	Ncstd��dS)Nzfrom . import relimport)rOr)r�rr�check_relativeDsz:RelativeImportTests.test_issue3221.<locals>.check_relative�__package__r/r^ztest.notarealmoduleznotarealpkg.notarealmoduler�)�dictr*�SystemError�object�	TypeError)r'r�r)r�r�test_issue3221>sz"RelativeImportTests.test_issue3221c	Cs7|jt��"ddlm}|jd�WdQXdS)NrF)�sepz>explicit relative import triggered an implicit absolute import)r*r+r@rr7)r'rrrr�#test_absolute_import_without_future[sz7RelativeImportTests.test_absolute_import_without_futureN)r^r�r�r)r(r�r�rrrrrr�3s
r�c@seZdZdd�ZdS)�OverridingImportBuiltinTestscCs�ddl}dd�}|j|�|�ttddd���|j|�d�WdQXtt�ddd���|j|�|�WdQXdS)	NrcSsddl}|S)Nr)r@)r@rrrr�jsz?OverridingImportBuiltinTests.test_override_builtin.<locals>.foor6cWsdS)Nrr)rbrrr�<lambda>oszDOverridingImportBuiltinTests.test_override_builtin.<locals>.<lambda>rcWsdS)Nrr)rbrrrrus)r@r8r�builtinsrr�)r'r@r�rrr�test_override_builtinfsz2OverridingImportBuiltinTests.test_override_builtinN)r^r�r�rrrrrresrc@seZdZejjZdd�Zdd�Zdd�Z	e
dd��Zej
ejd	kd
�ejeed�o�ej�dkd
�e
dd����Ze
dd��Ze
dd��Zdd�Ze
dd��Ze
dd��Zdd�Zdd�ZdS)�PycacheTestscCs%tt�td�t|j�dS)Nr)rrr	rr")r'rrr�_clean~s

zPycacheTests._cleancCsftd|_|j�t|jd��}tdd|�WdQXtjjdtj	�t
j�dS)Nz.pyr1z/# This is a test file written by test_import.pyr2r)rr"rr3r4rrr r@rAr%r&)r'�fprrrr(�s

zPycacheTests.setUpcCstjd=|j�dS)Nr)rrr)r'rrrr)�s
zPycacheTests.tearDowncCs�|jtjjd��tt�|jtjjd��|jtjjtjjddjt|j	t
rrdnd����dS)Nrz
{}.{}.py{}rGrH)�assertFalser@rr�r6rr_r�rw�tag�	__debug__)r'rrr�test_import_pyc_path�s
	z!PycacheTests.test_import_pyc_pathr�z%test meaningful only on posix systems�geteuidrz=due to varying filesystem permission semantics (issue #11956)c
Csqtd��tt�WdQX|jtjjd��|jtjjtjjddj	t|j
����dS)N�rz	{}.{}.pyc)r
r6rr_r@rr�r	r�rwr
)r'rrr�test_unwritable_directory�s

z&PycacheTests.test_unwritable_directorycCsstt�tjj|j�}|jtjj	|��tj
|j�tt�tj�|j
ttt�dS)N)r6rr%r�r�r"r_r@rr�r!rr&r*r+)r'r�rrr�test_missing_source�s


z PycacheTests.test_missing_sourcecCs~tt�t|j�}tj|j�tt�tj�tt�}|j	|j
tjjtj
tjj|���dS)N)r6rrr"r@r!rr%r&r8r[rr�rA�relpath)r'r�r�rrr�test_missing_source_legacy�s


z'PycacheTests.test_missing_source_legacycCsKtt�}tjjtd�}|j|jtjj	tj
|��dS)Nz.py)r6rr%r�r�r8�
__cached__r@rr�rA)r'r�r�rrr�test___cached__�szPycacheTests.test___cached__cCs~tt�t|j�}tj|j�tt�tj�tt�}|j	|j
tjjtj
tjj|���dS)N)r6rrr"r@r!rr%r&r8rrr�rAr)r'r�r�rrr�test___cached___legacy_pyc�s


z'PycacheTests.test___cached___legacy_pyccCsdd�}tjd�|j|�ttjjdd�d��WdQXttjjdd�d��WdQXtj�td�}tj	j
tjjdd��}|j|jtjjtj
|��tj	j
tjjdd��}|jtjdjtjjtj
|��dS)NcSs"td�td�td�dS)N�pep3147zpep3147.foo)r	rrrrr�cleanup�s

z5PycacheTests.test_package___cached__.<locals>.cleanuprz__init__.pyr1zfoo.pyzpep3147.foo)r@r��
addCleanupr3rr�r%r&r6r�r�r8rrArr)r'rr��init_pyc�foo_pycrrr�test_package___cached__�s


	%!z$PycacheTests.test_package___cached__cCsGdd�}tjd�|j|�ttjjdd�d��WdQXttjjdd�d��WdQXtj�td�}t	d�t	d�tj�td�}tj
jtjjdd��}|j|j
tjjtj|��tj
jtjjdd��}|jtjdj
tjjtj|��dS)NcSs"td�td�td�dS)Nrzpep3147.foo)r	rrrrrr�s

z>PycacheTests.test_package___cached___from_pyc.<locals>.cleanuprz__init__.pyr1zfoo.pyzpep3147.foo)r@r�rr3rr�r%r&r6rr�r�r8rrArr)r'rr�rrrrr� test_package___cached___from_pyc�s&





	%!z-PycacheTests.test_package___cached___from_pyccCsbtt�tt�t|jd��}tdd|�WdQXtt�}|j|jd�dS)Nr9zx = 5r2r)r6rrr3r"r4r8rb)r'rr�rrr�test_recompute_pyc_same_seconds

z+PycacheTests.test_recompute_pyc_same_secondN)r^r�r�r�implementation�	cache_tagr
rr(r)r�rr�r�r@r�skipIfr`r
rrrrrrrrrrrrrys"	$
rc@s~eZdZdZedZdd�Zdd�Zeje	e
d�pYe
j�dkd
�ej
jdd���Zd
S)�TestSymbolicallyLinkedPackageZsamplez-taggedcCs�tjj|j�tjj|j�tjdd�|_tj	|j�|j
tjj|j�tjj|jd�}tjj|�tj
|j|jdd�|j
tjj|j�tj�|jtjj|j�d�dS)Nz__init__.pyZtarget_is_directoryT)r/rar	�tagged�package_namerr�
orig_sys_pathr@r�rr�r�symlinkrr%r&r8�isdir)r'Z	init_filerrrr(s
z#TestSymbolicallyLinkedPackage.setUpcCs|jtjdd�<dS)N)r$rr)r'rrrr)1sz&TestSymbolicallyLinkedPackage.tearDown�getwindowsversion�rzWindows Vista or later requiredcCs*dgtjdd�<tj|j�dS)N�.)rrr%r�r#)r'rrr�test_symlinked_dir_importable5sz;TestSymbolicallyLinkedPackage.test_symlinked_dir_importableN)r(r)r^r�r�r#r"r(r)r�r�r`rr'r/raZskip_unless_symlinkr*rrrrr!s
r!c@s4eZdZdd�Zdd�Zdd�ZdS)�ImportlibBootstrapTestscCstjd}|j|�dS)N�_frozen_importlib)rrr_)r'r<rrr�test_frozen_importlibHs
z-ImportlibBootstrapTests.test_frozen_importlibcCsvddlm}tjd}|j||�|j|jd�|j|jd�|j|j	j
d�|j	�dS)Nr)�
_bootstrapr,zimportlib._bootstrapr%z
_bootstrap.py)r%r.rrr]r8r^r�r_r[rn)r'r.r<rrr�"test_frozen_importlib_is_bootstrapLs
z:ImportlibBootstrapTests.test_frozen_importlib_is_bootstrapcCs7ddlm}tjd}|j|j|j�dS)Nr)�	machineryr,)r%r0rrr]�
FileFinder)r'r0r<rrr�test_there_can_be_only_oneTs
z2ImportlibBootstrapTests.test_there_can_be_only_oneN)r^r�r�r-r/r2rrrrr+Dsr+c@s:eZdZdZdd�Zdd�Zdd�ZdS)	�GetSourcefileTestsz�Test importlib._bootstrap._get_sourcefile() as used by the C API.

    Because of the peculiarities of the need of this function, the tests are
    knowingly whitebox tests.

    c
CsOtjd��:}d|_td}td}|jt|�|�WdQXdS)Nz!importlib._bootstrap._path_isfileTz.pycz.py)�mock�patch�return_valuerr8r)r'�_path_isfilerZexpectrrr�test_get_sourcefilegs
	

z&GetSourcefileTests.test_get_sourcefilec
CsEtjd��0}d|_td}|jt|�|�WdQXdS)Nz!importlib._bootstrap._path_isfileFz.pyc)r4r5r6rr8r)r'r7rrrr�test_get_sourcefile_no_sourceps	
z0GetSourcefileTests.test_get_sourcefile_no_sourcecCs$td}|jt|�|�dS)Nz.bad_ext)rr8r)r'rrrr�test_get_sourcefile_bad_extxs
z.GetSourcefileTests.test_get_sourcefile_bad_extN)r^r�r��__doc__r8r9r:rrrrr3]s	r3c@s�eZdZdd�Zdd�Zddd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zedd��Zejed �d!d"��Zd#S)$�ImportTracebackTestscCs:tjt�tjdd�|_tjjdt�dS)Nr)r@r�rrr�old_pathr )r'rrrr(�s
zImportTracebackTests.setUpcCs$|jtjdd�<tt�dS)N)r=rrr	r)r'rrrr)�szImportTracebackTests.tearDownz.pyc	Cs\tjjt||�}t|d��}|j|�WdQX|jt|�tj	�|S)Nr1)
r@rr�rr3rJrrr%r&)r'r<�contentsr;Zfnamerrrr�
create_module�s
z"ImportTracebackTests.create_modulecCs�g}xO|rW|jj}|j}|s;||dkrK|j|�n|j}q	W|jt|�t|�|�x-t||�D]\}}|j||�q�WdS)NrFrI)	�tb_frame�f_coder�rN�tb_nextr8�len�ziprh)r'�tb�filesZ
deduped_filesr��fnZpatrrr�assert_traceback�s		
z%ImportTracebackTests.assert_tracebackcCseyddl}Wn.tk
r@}z|j}WYdd}~XnX|jd�|j|tg�dS)Nrz#ImportError should have been raised)�nonexistent_xyzzyr+�
__traceback__r7rHr[)r'rIr�rErrr�test_nonexistent_module�s
z,ImportTracebackTests.test_nonexistent_modulecCsx|jdd�yddl}Wn.tk
rP}z|j}WYdd}~XnX|jd�|j|tdg�dS)Nr�zimport nonexistent_xyzzyrz#ImportError should have been raisedzfoo.py)r?r�r+rJr7rHr[)r'r�r�rErrr�test_nonexistent_module_nested�s
z3ImportTracebackTests.test_nonexistent_module_nestedcCsx|jdd�yddl}Wn.tk
rP}z|j}WYdd}~XnX|jd�|j|tdg�dS)Nr�z1/0rz)ZeroDivisionError should have been raisedzfoo.py)r?r�rYrJr7rHr[)r'r�r�rErrr�test_exec_failure�s
z&ImportTracebackTests.test_exec_failurecCs�|jdd�|jdd�yddl}Wn.tk
r`}z|j}WYdd}~XnX|jd�|j|tddg�dS)	Nr�z
import bar�barz1/0rz)ZeroDivisionError should have been raisedzfoo.pyzbar.py)r?r�rYrJr7rHr[)r'r�r�rErrr�test_exec_failure_nested�s
z-ImportTracebackTests.test_exec_failure_nestedcCsu|jdd�yddl}Wn.tk
rP}z|j}WYdd}~XnX|jd�|j|tg�dS)Nr�zinvalid syntax is invalidrz#SyntaxError should have been raised)r?r��SyntaxErrorrJr7rHr[)r'r�r�rErrr�test_syntax_error�s
z&ImportTracebackTests.test_syntax_errorcCs�d}|jt|�tjjt|�}tj|�tjj|d�}t|d��}|j|�WdQXtjj|d�}t|d��}|j|�WdQXt	j
�||fS)N�_parent_fooz__init__.pyr1zbar.py)rrr@rr�rr�r3rJr%r&)r'�parentZchildZpkg_nameZpkg_path�	init_pathr�bar_pathrrr�_setup_broken_package�s

z*ImportTracebackTests._setup_broken_packagecCs�|jdd�\}}yddl}Wn.tk
rX}z|j}WYdd}~XnX|jd�|j|t|g�dS)Nrz1/0rz)ZeroDivisionError should have been raised)rV�_parent_foo.barrYrJr7rHr[)r'rTrUrRr�rErrr�test_broken_submodule�s
z*ImportTracebackTests.test_broken_submodulecCs�|jdd�\}}yddlm}Wn.tk
r\}z|j}WYdd}~XnX|jd�|j|t|g�dS)Nrz1/0r)rNz#ImportError should have been raised)rVrRrNrYrJr7rHr[)r'rTrUrNr�rErrr�test_broken_from�s
z%ImportTracebackTests.test_broken_fromcCs�|jdd�\}}yddl}Wn.tk
rX}z|j}WYdd}~XnX|jd�|j|t|g�dS)Nz1/0rrz)ZeroDivisionError should have been raised)rVrWrYrJr7rHr[)r'rTrUrRr�rErrr�test_broken_parent�s
z'ImportTracebackTests.test_broken_parentcCs�|jdd�\}}yddlm}Wn.tk
r\}z|j}WYdd}~XnX|jd�|j|t|g�dS)Nz1/0rr)rNz)ZeroDivisionError should have been raised)rVrRrNrYrJr7rHr[)r'rTrUrNr�rErrr�test_broken_parent_from�s
z,ImportTracebackTests.test_broken_parent_fromcCs�|jdd�tjd}dt|j�krA|jj}nd}z�dd�}||j_yddl}Wn.tk
r�}z|j}WYdd}~XnX|j	d�|j
|td	tg�Wd|dkr�|j`n||j_XdS)
Nr�rr,�load_modulecWsdddS)NrFrr)r�rrr�exec_modulesz9ImportTracebackTests.test_import_bug.<locals>.exec_modulerz)ZeroDivisionError should have been raisedz<frozen importlib)r?rr�vars�SourceLoaderr]r�rYrJr7rHr[)r'r%Zold_exec_moduler]r�r�rErrr�test_import_bug	s"

z$ImportTracebackTests.test_import_bugzneed TESTFN_UNENCODABLEcCsStjdtd�}|jt|�|dd�}tjdd|dd�dS)	Nr�passrXz-czmod = __import__(%a)Z
__isolatedF���)rrrrrr|)r'Zpynamerrrr�test_unencodable_filename$s
z.ImportTracebackTests.test_unencodable_filenameN)r^r�r�r(r)r?rHrKrLrMrOrQrVrXrYrZr[rr`r�r�rrcrrrrr<s 







r<�__main__):r%�importlib.utilZimportlib._bootstraprrr�r@rBrLr5r�rr�Z
unittest.mockr4rzr�Zshutil�
contextlibr\r/rrrrrrr	r
rrr
rrrrrrr �dont_write_bytecoder�r�contextmanagerr#ZTestCaser$r�r�r�r�rrr!r+r3r<r^�mainrrrr�<module>sTj	
�V^52�.!�