Your IP : 216.73.217.32


Current Path : /opt/alt/python35/lib64/python3.5/test/test_import/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/test_import/__pycache__/__init__.cpython-35.pyc



��Yfҩ�@s	ddlZddlZddlmZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
jZddlZddlZddlZddlZddlZddlmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&ddlm'Z'ddl(m)Z)ej*ej+d�Z,dd�Z-ej.dd	d
d��Z/Gdd
�d
ej0�Z1e,Gdd�dej0��Z2Gdd�dej0�Z3Gdd�dej0�Z4Gdd�dej0�Z5Gdd�dej0�Z6Gdd�dej0�Z7Gdd�dej0�Z8e#Gdd�dej0��Z9e#Gdd�dej0��Z:Gd d!�d!ej0�Z;Gd"d#�d#ej0�Z<e=d$krej>�dS)%�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�temp_dir�
DirsOnSysPath)�
script_helper)�uncachez*test meaningful only when writing bytecodecCsEx4|d|d|d|dfD]}t|�q#Wtd�dS)Nz.pyz.pycz.pywz	$py.class�__pycache__)rr	)�name�f�r�>/opt/alt/python35/lib64/python3.5/test/test_import/__init__.py�remove_files"s
r�ccs�|p	d}t���}tj|||�}tjj|d�}z2tjjd|�||fVtjj|�Wd|dk	r�|tj|<n|tjkr�tj|=XWdQRXdS)NZspamr)	rr�make_script�sys�modules�pop�path�insert�remove)r�sourceZtempdirr"Z
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�Zedd��Zdd�Zedd��Zd d!�Zd"d#�Zd$d%�Zd&S)'�ImportTestscCstt�tj�dS)N)rr�	importlib�invalidate_caches)�selfrrr�setUpBs
zImportTests.setUpcCstt�dS)N)rr)r*rrr�tearDownFszImportTests.tearDownc	Cs'|jt��ddl}WdQRXdS)Nr)�assertRaises�ImportError�RAnDoM)r*r/rrr�test_case_sensitivityIsz!ImportTests.test_case_sensitivitycCsddlm}dS)Nr)�double_const)�testr1)r*r1rrr�test_double_constOszImportTests.test_double_constcs��fdd�}tjjdtj�zM|d�tjjd�rtx*dddd	d
dgD]}||�q`WWdtjd=XdS)Nc sjt|}trtd}n
td}t|d��a}td|dd|�tjd�}tjd�}td|d|�td	|d|�WdQRXttjkr�tjt=tj	�z�yt
t�}Wn<tk
r}z�jd
||f�WYdd}~XnX�j
|j|d|��j
|j|d|�Wdtt�t|�t|�XdS)Nz	$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	randrangerr r(r)�
__import__r.�fail�assertEqual�a�brr)�extr%Zpycrr<r=�mod�err)r*rr�test_with_extensionUs4




*

z4ImportTests.test_import.<locals>.test_with_extensionrz.py�winz.PYz.Pyz.pYz.pywz.PYWz.pYw)rr"r#�os�curdir�platform�
startswith)r*rAr>r)r*r�test_importTs"
zImportTests.test_importZlonglistc#Cs|d}t|d��E}|jd�x!td�D]}|jd�q6W|jd�WdQRXztj|�Wdt|�Xtjjd�t	j
�i}z"t|�td|d|�Wdtjd=t|d
�t|d�|j
�ytj|=Wntk
rYnXXdS)
Nz.pyr4zd = [
i�z"",
�]rzimport ��c�o���)r6�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|�WdQRXtjjdtj�tj	�ttj
krltj
t=zKxDdddgD]3}|jtt
t�|jttj
d	|�qWWdtjd=tt�XdS)
Nz.pyr4za = 1/0r5rrI��z'damaged module in sys.modules on %i try)rr6r7rr"r#rCrDr(r)r r-�ZeroDivisionErrorr9�assertNotInr)r*r%rrWrrr�test_failing_import_sticks�s



z&ImportTests.test_failing_import_stickscCssddl}ddl}|j|||j�|jt|jd��ddlj}|j||j|j�dS)Nr�__file__)r2�test.support�assertIs�__name__�
assertTrue�hasattr�support)r*�xr2�yrrr�test_import_name_binding�sz$ImportTests.test_import_name_bindingcCsVttjd}t|d��}|jd�WdQRXtjjdtj�z�t	t�}|j
ttj�|j|j
dd�|j|jdd�tt�t|d��}|jd�WdQRX|jttj|�tjjt�}|j|d	�|j|j
d
d�|j|jdd�Wdtjd=tt�tt�XdS)N�pyr4z
a = 1
b=2
rrIz!module has wrong attribute valuesrZza = 10
b=20//0
z$expected module to be in sys.modules�
)rrC�extsepr6rMrr"r#rDr9�assertInr r;r<r=rr-r\r(�reload�getZassertIsNotNoner)r*r%rr?rrr�test_failing_reload�s(


zImportTests.test_failing_reloadcCstd}t|d��}|jd�WdQRXtjjdtj�z�tt�}|j	|j
jd��tj|�tj
t=t|�tj�tt�}tjj|j
�\}}|j|d�Wdtjd=tt�ttj
krtj
t=XdS)Nz.pyr4ztest = None
rz.pyc)rr6rMrr"r#rCrDr9rcr_�endswithr$r rr(r)�splitextr;r)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|�WdQRXdS)Nzpath is not encodable to {})
rCr"�abspathrr�getfilesystemencoding�encode�UnicodeEncodeError�skipTest�formatr-r.r9)r*r"�encodingrJrrr�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_crashcCs"tjjdtj�z�td}tjj|�}t	|d��}WdQRXytj
|d�Wn�tk
r�|jd�Ynkt
k
r�}zK|jttdd�ttd	d�fkr��|jd
j|��WYdd}~XnXtt�tj|�Wdtjd=tt�XdS)Nrz.pyr4rZ�!�z-cannot set modification time to large integerZ	EOVERFLOWZEINVALz2cannot set modification time to large integer ({})l���l���)r�r�)rr"r#rCrDrr(�util�cache_from_sourcer6�utime�
OverflowErrorrx�OSError�errno�getattrryr9�statr)r*r%Zcompiledr�errr�test_timestamp_overflows&

)

z#ImportTests.test_timestamp_overflowcCs=ytdddg�Wntk
r8|jd�YnXdS)NZhttp�fromlistZblahzfromlist must allow bogus names)r9r.r:)r*rrr�test_bogus_fromlist4s
zImportTests.test_bogus_fromlistcCsAddg}tj|�}|j�\}}|jd|�dS)Nz-cz&del __builtins__.__import__; import ossImportError)rZspawn_pythonZcommunicaterl)r*�args�popen�stdout�stderrrrr�test_delete_builtins_import:sz'ImportTests.test_delete_builtins_importc	Cs.|jtd��ddlm}WdQRXdS)Nz^No module named 'bogus'r)�foo)�assertRaisesRegexr.�bogusr�)r*r�rrr�/test_from_import_message_for_nonexistent_moduleAsz;ImportTests.test_from_import_message_for_nonexistent_modulec	Cs.|jtd��ddlm}WdQRXdS)Nz^cannot import name 'bogus'r)r�)r�r.�rer�)r*r�rrr�,test_from_import_message_for_existing_moduleEsz8ImportTests.test_from_import_message_for_existing_modulec	CsdGdd�d�}d}|jt|�|�tj|<|jt��ddlm}WdQRXdS)Nc@seZdZdd�ZdS)zIImportTests.test_from_import_AttributeError.<locals>.AlwaysAttributeErrorcSs
t�dS)N)�AttributeError)r*�_rrr�__getattr__MszUImportTests.test_from_import_AttributeError.<locals>.AlwaysAttributeError.__getattr__N)rb�
__module__�__qualname__r�rrrr�AlwaysAttributeErrorLsr��test_from_import_AttributeErrorr)�does_not_exist)�
addCleanuprrr r-r.r�r�)r*r��module_namer�rrrr�Isz+ImportTests.test_from_import_AttributeErrorN)rbr�r�r+r,r0r3rGrYr^rhro�skip_if_dont_write_bytecodersr{rr�r�rr�r�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|��jt��Y\}}tjj|�}t|�}tjj|�sb|j	d�tj
|�}WdQRXWdQRX|jtt
j
|j��td|@��dS)N�z4__import__ did not result in creation of a .pyc filei�)r
r&r(r�r�r9rCr"�existsr:r�r;�oct�S_IMODE�st_mode)r*�maskrr"�cached_pathrU�	stat_inforrr�test_creation_mode[s
z&FilePermissionTests.test_creation_modecCs�d}td��xt��g\}}tjj|�}tj||�t|�tjj	|�sp|j
d�tj|�}WdQRXWdQRX|jt
tj|j��t
|��dS)Ni�r�z4__import__ did not result in creation of a .pyc file)r
r&r(r�r�rC�chmodr9r"r�r:r�r;r�r�r�)r*�moderr"r�r�rrr�test_cached_mode_issue_2051ls

z/FilePermissionTests.test_cached_mode_issue_2051cCs�d}td��xt��g\}}tjj|�}tj||�t|�tjj	|�sp|j
d�tj|�}WdQRXWdQRX|dB}|jt
tj|j��t
|��dS)N�r�z4__import__ did not result in creation of a .pyc file�)r
r&r(r�r�rCr�r9r"r�r:r�r;r�r�r�)r*r�rr"r�r�Zexpectedrrr�test_cached_readonly|s


z(FilePermissionTests.test_cached_readonlycCsmt��]\}}t|d��}|jd�WdQRXtj|�}tj||j|jdf�tj|d�t	|�}|j
|jd�tj|d�t|d��}|jd�WdQRXt|�t
j�t	|�}|j
|jd�t|�t|�t
j�|d	}tjt
jj|�|�t	|�}|j
|jd�WdQRXdS)
Nr4zx = 'original'
i�r�Zoriginali�zx = 'rewritten'
Z	rewrittenrJ)r&r6rMrCr�r��st_atime�st_mtimer�r9r;rfrr(r)r�renamer�r�)r*rr"r�s�mZ
bytecode_onlyrrr�test_pyc_always_writable�s, 





z,FilePermissionTests.test_pyc_always_writableN)rbr�r��unittest�
skipUnlessrCrr�r�r�r�rrrrr�Ws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
ric
Cs�tjdd�|_tjj|jd�|_tj|j	�t
|jd��}|j|j
�WdQRXtjjd|j	�tj�dS)Nr4r)rr"�sys_pathr r!r��orig_modulerC�mkdir�dir_namer6�	file_namerM�
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�rr"r�r r�rrr��
compiled_namer	r�)r*rrrr,�s


zPycRewritingTests.tearDowncCs*t�}t|j||�tj|jS)N)�globalsr9r�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�r;�module_filenamer��
code_filename�
func_filenamerr r�)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)rOrPr�r�r;r�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�)
rOrPr�rCr$rr(r)r�r;r�r�r�)r*�target�pyc_filer?rrr�test_module_without_source�s
z,PycRewritingTests.test_module_without_sourcecCsLtj|j�t|jd��%}|jd�}tj|�}WdQRXt|j	�}t
jj}|j
d�}|||<t|�|j|j|j|j|j|jt|�|j|j|j|j|j|j|j|j�}t|jd��$}|j|�tj||�WdQRX|j�}|j |j!j|j�dS)N�rb�rI�wb)"rOrPr�r6r��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_cellvarsrM�dumpr;Zconstant)r*r�header�codeZ	constantsZforeign_code�posr?rrr�test_foreign_code�s&

z#PycRewritingTests.test_foreign_codeN)rbr�r�r�r�rCr"rtrr��joinrkr�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)�
PathsTestsr2�testäöüß�testéè�
test°³²cCs*tj|j�tjdd�|_dS)N)rCr�r"r�syspath)r*rrrr+szPathsTests.setUpcCs't|j�|jtjdd�<dS)N)r	r"r�r)r*rrrr,s
zPathsTests.tearDownc
Cs|ttjj|jd�d��}|jd�WdQRXtjj|jd�td�}|j|j	d�t
d�dS)Nztest_trailing_slash.pyr4z testdata = 'test_trailing_slash'�/�test_trailing_slash)r6rCr"r�rMrrQr9r;�testdatar)r*rr?rrrr�s$zPathsTests.test_trailing_slash�win32zWindows-specificc	&Cs�ttjj|jd�d��}|jd�WdQRXtj�tjj|j�}ddl}|j	�}|d}d||f}||dd�7}ytj
|�Wn]tk
r
}z=|jtj
tjtjfkr�|jd|f��WYdd}~XnXtjjd|�ytd�}Wn<tk
ro}z|jd	||f�WYdd}~XnX|j|jd�|j|jj|�|j�td�dS)
Nztest_unc_path.pyr4ztestdata = 'test_unc_path'rz\\%s\%s$rZz%cannot access administrative share %rZ
test_unc_pathz,could not import 'test_unc_path' from %r: %r)r6rCr"r�rMr(r)rt�socketZgethostname�listdirr�r�ZEPERMZEACCES�ENOENTrxrr#r9r.r:r;r�rcr_rFr)	r*rr"r�ZhnZdriveZuncr�r?rrr�
test_UNC_path s0$

!	!zPathsTests.test_UNC_pathN)r2r�r�r�)rbr�r�ZSAMPLESrr"r+r,r�r�r�rrEr�rrrrr�	s	r�c@s^eZdZdd�ZeZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
S)�RelativeImportTestscCstd�dS)Nztest.relimport)r)r*rrrr,@szRelativeImportTests.tearDowncCs*ddlm}|jt|d��dS)NrZ)�	relimportr)rrrcrd)r*rrrr�test_relimport_starDsz'RelativeImportTests.test_relimport_starcs��fdd�}tdddd��|�tdddd��|�tdddd��|jt|�tdddd��|jt|�tdt���|jt|�dS)	Ncstd��dS)Nzfrom . import relimport)rRr)r�rr�check_relativeOsz:RelativeImportTests.test_issue3221.<locals>.check_relative�__package__r2rbztest.notarealmoduleznotarealpkg.notarealmoduler�)�dictr-r.�object�	TypeError)r*rr)r�r�test_issue3221Isz"RelativeImportTests.test_issue3221c	Cs8|jt��"ddlm}|jd�WdQRXdS)NrI)�sepz>explicit relative import triggered an implicit absolute import)r-r.rCr	r:)r*r	rrr�#test_absolute_import_without_futurefsz7RelativeImportTests.test_absolute_import_without_futurecCs�tjjtjjt�dd�}tdd��bt|��N|jt��ddl	}WdQRX|j
dtj�|j
dtj�WdQRXWdQRXdS)N�data�package2�
submodule1�
submodule2r)
rCr"r��dirnamer_rrr-r.r
r]rr )r*r"r
rrr�test_import_from_non_packageos$z0RelativeImportTests.test_import_from_non_packagecCsctddd��Jttjjtjjt�d���ddl}|jj	WdQRXWdQRXdS)Nrzpackage2.submodule1zpackage2.submodule2rr)
rrrCr"r�rr_Zpackage2.submodule1r
r)r*rrrr�!test_import_from_unloaded_packagews(z5RelativeImportTests.test_import_from_unloaded_packageN)
rbr�r�r,r+rrr
rrrrrrr>s	rc@seZdZdd�ZdS)�OverridingImportBuiltinTestscCs�ddl}dd�}|j|�|�ttddd���|j|�d�WdQRXtt�ddd���|j|�|�WdQRXdS)	NrcSsddl}|S)Nr)rC)rCrrrr��sz?OverridingImportBuiltinTests.test_override_builtin.<locals>.foor9cWsdS)Nr�r)rfrrr�<lambda>�szDOverridingImportBuiltinTests.test_override_builtin.<locals>.<lambda>r�cWsdS)Nr�r)rfrrrr�s)rCr;r�builtinsrr�)r*rCr�rrr�test_override_builtinsz2OverridingImportBuiltinTests.test_override_builtinN)rbr�r�rrrrrr~src@seZdZdd�Zdd�Zdd�Zedd��Zej	e
jd	kd
�eje
e
d�o~e
j�dkd
�edd����Zedd��Zedd��Zdd�Zedd��Zedd��Zdd�Zdd�ZdS)�PycacheTestscCs%tt�td�t|j�dS)Nr)rrr	rr%)r*rrr�_clean�s

zPycacheTests._cleancCsgtd|_|j�t|jd��}tdd|�WdQRXtjjdtj	�t
j�dS)Nz.pyr4z/# This is a test file written by test_import.pyr5r)rr%rr6r7rr"r#rCrDr(r))r*�fprrrr+�s

zPycacheTests.setUpcCs:tjdtjks"td��tjd=|j�dS)NrzUnexpected sys.path[0])rr"rCrD�AssertionErrorr)r*rrrr,�s"
zPycacheTests.tearDowncCs}|jtjjd��tt�|jtjjd��tjj	|j
�}|jtjj|�dj|t��dS)Nrz*bytecode file {!r} for {!r} does not exist)�assertFalserCr"r�r9rrcr(r�r�r%ry)r*�pyc_pathrrr�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Csxtd��tt�WdQRX|jtjjd��tjj	|j
�}|jtjj|�dj|t��dS)N�rz"bytecode file {!r} for {!r} exists)
r
r9rrcrCr"r�r(r�r�r%rry)r*rrrr�test_unwritable_directory�s
z&PycacheTests.test_unwritable_directorycCsstt�tjj|j�}|jtjj	|��tj
|j�tt�tj�|j
ttt�dS)N)r9rr(r�r�r%rcrCr"r�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)r9rrr%rCr$rr(r)r;r_r"r�rD�relpath)r*r�r�rrr�test_missing_source_legacy�s


z'PycacheTests.test_missing_source_legacycCsKtt�}tjjtd�}|j|jtjj	tj
|��dS)Nz.py)r9rr(r�r�r;�
__cached__rCr"r�rD)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)r9rrr%rCr$rr(r)r;r#r"r�rDr!)r*r�r�rrr�test___cached___legacy_pyc�s


z'PycacheTests.test___cached___legacy_pyccCsdd�}tjd�|j|�ttjjdd�d��WdQRXttjjdd�d��WdQRXtj�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>.cleanupr&z__init__.pyr4zfoo.pyzpep3147.foo)rCr�r�r6r"r�r(r)r9r�r�r;r#rDrr )r*r'r��init_pyc�foo_pycrrr�test_package___cached__�s


	%!z$PycacheTests.test_package___cached__cCsIdd�}tjd�|j|�ttjjdd�d��WdQRXttjjdd�d��WdQRXtj�td�}t	d�t	d�tj�td�}tj
jtjjdd��}|j|j
tjjtj|��tj
jtjjdd��}|jtjdj
tjjtj|��dS)NcSs"td�td�td�dS)Nr&zpep3147.foo)r	rrrrrr'
s

z>PycacheTests.test_package___cached___from_pyc.<locals>.cleanupr&z__init__.pyr4zfoo.pyzpep3147.foo)rCr�r�r6r"r�r(r)r9rr�r�r;r#rDrr )r*r'r�r(r)rrr� test_package___cached___from_pyc
s&





	%!z-PycacheTests.test_package___cached___from_pyccCsctt�tt�t|jd��}tdd|�WdQRXtt�}|j|jd�dS)Nr<zx = 5r5r�)r9rrr6r%r7r;rf)r*rr�rrr�test_recompute_pyc_same_second%s

z+PycacheTests.test_recompute_pyc_same_secondN)rbr�r�rr+r,r�rr�r�rCr�skipIfrdrrr r"r$r%r*r+r,rrrrr�s 
$rc@s~eZdZdZedZdd�Zdd�Zeje	e
d�pYe
j�dkd
�ej
jdd���Zd
S)�TestSymbolicallyLinkedPackageZsamplez-taggedcCs1tjj|j�tjj|j�tjdd�|_tj	|j�|j
tjj|j�tjj|jd�}tjj|�tjj
|�s�t�tj|j|jdd�|j
tjj|j�tj�|jtjj|j�d�tjjtjj|jd��s-t�dS)Nz__init__.pyZtarget_is_directoryT)r2rer	�tagged�package_namerr"�
orig_sys_pathrCr�r�r�rr�r�symlinkrr(r)r;�isdir�isfile)r*Z	init_filerrrr+4s
z#TestSymbolicallyLinkedPackage.setUpcCs|jtjdd�<dS)N)r1rr")r*rrrr,Ksz&TestSymbolicallyLinkedPackage.tearDown�getwindowsversion�rzWindows Vista or later requiredcCsodgtjdd�<tjj|j�s1t�tjjtjj|jd��s[t�tj|j�dS)N�.z__init__.py)	rr"rCr�r0rr�r(r�)r*rrr�test_symlinked_dir_importableOs*z;TestSymbolicallyLinkedPackage.test_symlinked_dir_importableN)r6r)rbr�r�r0r/r+r,r�r�rdrr5r2reZskip_unless_symlinkr8rrrrr.0s
r.c@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ImportlibBootstrapTestscCstjd}|j|�dS)N�_frozen_importlib)rr rc)r*r?rrr�test_frozen_importlibbs
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<rr rar;rbrrcr_rp)r*r<r?rrr�"test_frozen_importlib_is_bootstrapfs
z:ImportlibBootstrapTests.test_frozen_importlib_is_bootstrapcCsvddlm}tjd}|j||�|j|jd�|j|jd�|j|j	j
d�|j	�dS)Nr)�_bootstrap_external�_frozen_importlib_externalzimportlib._bootstrap_externalr(z_bootstrap_external.py)r(r>rr rar;rbrrcr_rp)r*r>r?rrr�4test_frozen_importlib_external_is_bootstrap_externalns
zLImportlibBootstrapTests.test_frozen_importlib_external_is_bootstrap_externalcCs7ddlm}tjd}|j|j|j�dS)Nr)�	machineryr:)r(rArr ra�
ModuleSpec)r*rAr?rrr�test_there_can_be_only_onevs
z2ImportlibBootstrapTests.test_there_can_be_only_oneN)rbr�r�r;r=r@rCrrrrr9^sr9c@s:eZdZdZdd�Zdd�Zdd�ZdS)	�GetSourcefileTestsz�Test importlib._bootstrap_external._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
CsPtjd��:}d|_td}td}|jt|�|�WdQRXdS)Nz*importlib._bootstrap_external._path_isfileTz.pycz.py)�mock�patch�return_valuerr;r)r*�_path_isfiler"Zexpectrrr�test_get_sourcefile�s
	

z&GetSourcefileTests.test_get_sourcefilec
CsFtjd��0}d|_td}|jt|�|�WdQRXdS)Nz*importlib._bootstrap_external._path_isfileFz.pyc)rErFrGrr;r)r*rHr"rrr�test_get_sourcefile_no_source�s	
z0GetSourcefileTests.test_get_sourcefile_no_sourcecCs$td}|jt|�|�dS)Nz.bad_ext)rr;r)r*r"rrr�test_get_sourcefile_bad_ext�s
z.GetSourcefileTests.test_get_sourcefile_bad_extN)rbr�r��__doc__rIrJrKrrrrrDs	rDc@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)rCr�rrr"�old_pathr#)r*rrrr+�s
zImportTracebackTests.setUpcCs$|jtjdd�<tt�dS)N)rNrr"r	r)r*rrrr,�szImportTracebackTests.tearDownz.pyc
Cs]tjjt||�}t|d��}|j|�WdQRX|jt|�tj	�|S)Nr4)
rCr"r�rr6rMr�rr(r))r*r?�contentsr>Zfnamerrrr�
create_module�s
z"ImportTracebackTests.create_modulecCs�g}xL|rT|jj}|j}|s;||dkrH|j|�|j}q	W|jt|�t|�|�x-t||�D]\}}|j||�q�WdS)NrIrL)	�tb_frame�f_coder�rQ�tb_nextr;�len�ziprl)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__r:rYr_)r*rZr�rVrrr�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)rPr�r.r[r:rYr_)r*r�r�rVrrr�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)rPr�r\r[r:rYr_)r*r�r�rVrrr�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)rPr�r\r[r:rYr_)r*r�r�rVrrr�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)rPr��SyntaxErrorr[r:rYr_)r*r�r�rVrrr�test_syntax_error�s
z&ImportTracebackTests.test_syntax_errorcCs�d}|jt|�tjjt|�}tj|�tjj|d�}t|d��}|j|�WdQRXtjj|d�}t|d��}|j|�WdQRXt	j
�||fS)N�_parent_fooz__init__.pyr4zbar.py)r�rrCr"r�rr�r6rMr(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)rg�_parent_foo.barr\r[r:rYr_)r*rerfrcr�rVrrr�test_broken_submodules
z*ImportTracebackTests.test_broken_submodulecCs�|jdd�\}}yddlm}Wn.tk
r\}z|j}WYdd}~XnX|jd�|j|t|g�dS)Nrz1/0r)r_z#ImportError should have been raised)rgrcr_r\r[r:rYr_)r*rerfr_r�rVrrr�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)rgrhr\r[r:rYr_)r*rerfrcr�rVrrr�test_broken_parents
z'ImportTracebackTests.test_broken_parentcCs�|jdd�\}}yddlm}Wn.tk
r\}z|j}WYdd}~XnX|jd�|j|t|g�dS)Nz1/0rr)r_z)ZeroDivisionError should have been raised)rgrcr_r\r[r:rYr_)r*rerfr_r�rVrrr�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)NrIrr)r�rrr�exec_module6sz9ImportTracebackTests.test_import_bug.<locals>.exec_modulerz)ZeroDivisionError should have been raisedz<frozen importlib)rPrr �vars�SourceLoaderrnr�r\r[r:rYr_)r*r(Zold_exec_modulernr�r�rVrrr�test_import_bug+s"

z$ImportTracebackTests.test_import_bugzneed TESTFN_UNENCODABLEcCsStjdtd�}|jt|�|dd�}tjdd|dd�dS)	Nr�passr[z-czmod = __import__(%a)Z
__isolatedF���)rrrr�rr~)r*Zpynamerrrr�test_unencodable_filenameFs
z.ImportTracebackTests.test_unencodable_filenameN)rbr�r�r+r,rPrYr\r]r^r`rbrgrirjrkrlrrqr�r�rrtrrrrrM�s 







rMc@sReZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�CircularImportTestszQSee the docstrings of the modules being imported for the purpose of the
    test.cCs=x6ttjj��D]}|jd�rtj|=qWdS)zSMake sure no modules pre-exist in sys.modules which are being used to
        test.z&test.test_import.data.circular_importsN)r�rr �keysrF)r*�keyrrrr,VszCircularImportTests.tearDowncCs6yddl}Wntk
r1|jd�YnXdS)Nrz/circular import through relative imports failed)Z,test.test_import.data.circular_imports.basicr.r:)r*r2rrr�test_direct]s
zCircularImportTests.test_directcCs6yddl}Wntk
r1|jd�YnXdS)Nrz@relative import in module contributing to circular import failed)Z/test.test_import.data.circular_imports.indirectr.r:)r*r2rrr�
test_indirectcs
z!CircularImportTests.test_indirectcCs6yddl}Wntk
r1|jd�YnXdS)Nrz-circular import involving a subpackage failed)Z1test.test_import.data.circular_imports.subpackager.r:)r*r2rrr�test_subpackagejs
z#CircularImportTests.test_subpackagecCshyddljjjj}Wntk
r=|jd�YnXddlm}|j	|j|j�dS)Nrz9circular import with rebinding of module attribute failed)r�)
Z0test.test_import.data.circular_imports.rebindingrGrZcircular_imports�	rebindingr.r:Z-test.test_import.data.circular_imports.subpkgr�ra)r*r{r�rrr�test_rebindingps
z"CircularImportTests.test_rebindingN)	rbr�r�rLr,rxryrzr|rrrrruQsru�__main__)?r(�importlib.utilZimportlib._bootstrap_externalrrr�rCrErOr8r�rr�Z
unittest.mockrEr|r�Zshutil�
contextlibr`r2rrrrrrr	r
rrr
rrrrrrrrZtest.test_importlib.utilrr-�dont_write_bytecoder�r�contextmanagerr&ZTestCaser'r�r�r�rrrr.r9rDrMrurb�mainrrrr�<module>sXv		�S^5@�. !�(