Your IP : 216.73.216.52


Current Path : /opt/alt/python310/lib64/python3.10/test/test_import/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/test/test_import/__pycache__/__init__.cpython-310.pyc

o

0�i��@sPddlZddlZddlZddlZddlZddlmZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlmZddlmZddlmZmZmZmZddlmZmZmZmZm Z ddl!m"Z"m#Z#m$Z$m%Z%m&Z&ddlm'Z'dd	lm(Z(dd
l)m*Z*ddl+m,Z,e�-ej.d�Z/d
d�Z0ej1d+dd��Z2Gdd�dej3�Z4e/Gdd�dej3��Z5Gdd�dej3�Z6Gdd�dej3�Z7Gdd�dej3�Z8Gdd�dej3�Z9Gdd�dej3�Z:Gd d!�d!ej3�Z;eGd"d#�d#ej3��Z<eGd$d%�d%ej3��Z=Gd&d'�d'ej3�Z>Gd(d)�d)ej3�Z?e@d*k�r&e�A�dSdS),�N)�_get_sourcefile)�mock)�	os_helper)�	is_jython�	swap_attr�	swap_item�cpython_only)�forget�make_legacy_pyc�unlink�unload�
DirsOnSysPath)�TESTFN�rmtree�
temp_umask�TESTFN_UNENCODABLE�temp_dir)�
script_helper)�threading_helper)�uncache)�
ModuleTypez*test meaningful only when writing bytecodecCs6|d|d|d|dfD]}t|�qtd�dS)N�.py�.pyc�.pyw�	$py.class�__pycache__)rr)�name�f�r�@/opt/alt/python310/lib64/python3.10/test/test_import/__init__.py�remove_files%s�
r �c
cs��|pd}t��[}t�|||�}tj�|d�}z'tj�d|�||fVtj�|�W|dur5|tj|<n&|tjvr>tj|=n|durI|tj|<w|tjvrRtj|=wWd�dSWd�dS1sfwYdS)N�spamr)	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�Ze	d
d��Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdAdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zed&d'��Zd(d)�Zd*d+�Zed,d-��Zd.d/�Ze	d0d1��Zd2d3�Zd4d5�Zd6d7�Ze	d8d9��Z d:d;�Z!e"�#e$j%d<kd=�d>d?��Z&d@S)B�ImportTestscCstt�t��dS�N)r r�	importlib�invalidate_caches��selfrrr�setUpE�zImportTests.setUpcCstt�dSr-)rrr0rrr�tearDownI�zImportTests.tearDowncC�8|�t��
ddl}Wd�dS1swYdS�Nr)�assertRaises�ModuleNotFoundError�(something_that_should_not_exist_anywhere�r1r:rrr�&test_import_raises_ModuleNotFoundErrorLs
"�z2ImportTests.test_import_raises_ModuleNotFoundErrorcC�<|�t��ddlm}Wd�dS1swYdS)Nr)�blah)r8r9r:r>)r1r>rrr�:test_from_import_missing_module_raises_ModuleNotFoundErrorP�"�zFImportTests.test_from_import_missing_module_raises_ModuleNotFoundErrorcCr=)Nr)r:)r8�ImportErrorr.r:r;rrr�0test_from_import_missing_attr_raises_ImportErrorTr@z<ImportTests.test_from_import_missing_attr_raises_ImportErrorcCsn|�t��}ddlm}Wd�n1swY|�|jjd�|�|jjtj�|�	t
|j�d�dS)Nr��i_dont_exist�osz7cannot import name 'i_dont_exist' from 'os' \(.*os.py\))r8rArErD�assertEqual�	exceptionrr'�__file__�assertRegex�str�r1�cmrDrrr�/test_from_import_missing_attr_has_name_and_pathXs�z;ImportTests.test_from_import_missing_attr_has_name_and_pathcCsvddl}|�t��}ddlm}Wd�n1swY|�|jjd�|�|jj|j�|�	t
|j�d�dS)NrrC�	_testcapizCcannot import name 'i_dont_exist' from '_testcapi' \(.*\.(so|pyd)\))rNr8rArDrFrGrr'rHrIrJ)r1rNrLrDrrr�2test_from_import_missing_attr_has_name_and_so_path_s�z>ImportTests.test_from_import_missing_attr_has_name_and_so_pathcCsX|�t��}ddlm}Wd�n1swY|�|jjd�|�|jj�dS)NrrC�_warning)	r8rArPrDrFrGrZassertIsNoner'rKrrr�&test_from_import_missing_attr_has_namehs
�z2ImportTests.test_from_import_missing_attr_has_namecCsZ|�t��}ddlm}Wd�n1swY|�|jjddh�|�|j�dS)NrrC�	posixpathZntpath)r8rAZos.pathrD�assertInrGr�assertIsNotNonerKrrr�/test_from_import_missing_attr_path_is_canonicalos
�z;ImportTests.test_from_import_missing_attr_path_is_canonicalc	Cs�ddl}t��S\}}t|ddd��
}|�d�Wd�n1s!wYi}|�t|�|��d���td|�d�|�Wd�n1sHwY|�d	|�Wd�n1s]wYt��T\}}t|ddd��
}|�d
�Wd�n1swYi}|�t|�|��d���td|�d�|�Wd�n1s�wY|�d	|�Wd�dS1s�wYdS)Nr�w�utf-8��encodingz__all__ = [b'invalid_type']z\.__all__ must be strzfrom z	 import *sinvalid_typez%globals()[b'invalid_type'] = object()z\.__dict__ must be str)	�rer+�open�write�assertRaisesRegex�	TypeError�escape�exec�assertNotIn)r1rZrr'r�globalsrrr�"test_from_import_star_invalid_typeus2����	���"�z.ImportTests.test_from_import_star_invalid_typecCr6r7)r8rA�RAnDoM)r1rdrrr�test_case_sensitivity�s
"�z!ImportTests.test_case_sensitivitycCsddlm}dS)Nr)�double_const)�testrf)r1rfrrr�test_double_const�szImportTests.test_double_constcsj�fdd�}tj�dtj�z!|d�tj�d�r"dD]
}||�qWtjd=dSWtjd=dStjd=w)Nc
sLt|}trtd}ntd}t|ddd��(}td|d|d�t�d	�}t�d	�}td
||d�td||d�Wd�n1sAwYttjvrOtjt=t�	�zEzt
t�}Wntyu}z��d||f�WYd}~nd}~ww��
|j|d
|���
|j|d
|�Wtt�t|�t|�dStt�t|�t|�w)NrrrVrWrXz)# This tests Python's ability to import azfile.��filei�za =zb =zimport from %s failed: %sz'module loaded (%s) but contents invalid)rrr[�print�randomZ	randranger$r%r.r/�
__import__rA�failrF�a�br	r)�extr*Zpycrrorp�mod�errr0rr�test_with_extension�sF
�

�
��
�
��
z4ImportTests.test_import.<locals>.test_with_extensionrr�win)z.PYz.Pyz.pYrz.PYWz.pYw)r$r'r(rE�curdir�platform�
startswith)r1rtrqrr0r�test_import�s"
��zImportTests.test_import�longlistcCsL|d}t|ddd��}|�d�td�D]}|�d�q|�d�Wd�n1s,wYzt�|�Wt|�nt|�wtj�d	�t	�
�i}z3t|�td
|d|�Wtjd=t|d�t|d
�|�
�ztj|=WdSty�YdSwtjd=t|d�t|d
�|�
�ztj|=Wwty�Yww)NrrVrWrXzd = [
i�z"",
�]r!zimport ����c�o)r[r\�range�
py_compile�compilerr$r'�appendr.r/r
r`�clearr%�KeyError)r1�module�filenamer�i�	namespacerrr�test_module_with_large_stack�sD
����z(ImportTests.test_module_with_large_stackcCs�td}t|ddd��}td|d�Wd�n1swYtj�dtj�t�	�ttj
vr6tj
t=z!dD]}|�tt
t�|�ttj
d	|�q9Wtjd=tt�dStjd=tt�w)
NrrVrWrXza = 1/0rir)���z'damaged module in sys.modules on %i try)rr[rkr$r'r(rErvr.r/r%r8�ZeroDivisionErrorrmrar )r1r*rr�rrr�test_failing_import_sticks�s&�

���
z&ImportTests.test_failing_import_stickscCsTddl}ddl}|�|||j�|�t|jd��ddlm}|�||j|j�dS)NrrH)rg�test.support�assertIs�__name__�
assertTrue�hasattr�support)r1�xrg�yrrr�test_import_name_binding�sz$ImportTests.test_import_name_bindingcCs�z
d}Wddlmm}n
ddlmm}wd}|dkr/ddlmm}|d7}|dkstd�D]}ddlmm}q3dS)N.r�
r�r�)Ztest.support.script_helperr�rr)r1r�r�rrr�test_issue31286s(��zImportTests.test_issue31286cCsNttjd}t|ddd��
}|�d�Wd�n1swYtj�dtj�znt	t�}|�
ttj�|�|j
dd�|�|jd	d�tt�t|ddd��
}|�d
�Wd�n1sbwY|�ttj|�tj�t�}|�|d�|�|j
dd�|�|jd	d�Wtjd=tt�tt�dStjd=tt�tt�w)
N�pyrVrWrXz
a = 1
b=2
rr�z!module has wrong attribute valuesr�za = 10
b=20//0
z$expected module to be in sys.modulesr�)rrE�extsepr[r\r$r'r(rvrmrSr%rFrorpr r8r�r.�reload�getrTr)r1r*rrrrrr�test_failing_reloads2���
zImportTests.test_failing_reloadcCstd}t|ddd��
}|�d�Wd�n1swYtj�dtj�zGtt�}|�	|j
�d��t�|�tj
t=t|�t��tt�}tj�|j
�\}}|�|d�Wtjd=tt�ttj
vrntj
t=dSdStjd=tt�ttj
vr�tj
t=w)NrrVrWrXztest = None
rr)rr[r\r$r'r(rErvrmr�rH�endswithr)r%r
r.r/�splitextrFr )r1r*rrr�baserqrrr�test_file_to_source?s0�

��

zImportTests.test_file_to_sourcecCs~tj�t�}t��}z|�|�Wnty"|�d�	|��Ynw|�
t��
}t|�Wd�dS1s8wYdS)Nzpath is not encodable to {})
rEr'�abspathrr$�getfilesystemencoding�encode�UnicodeEncodeError�skipTest�formatr8rArm)r1r'rYr}rrr�test_import_by_filenameWs�
"�z#ImportTests.test_import_by_filenamecCs"t�dtt�d��}t�|�dS)Nr!z�            import sys
            class C:
               def __del__(self):
                  import importlib
            sys.argv.insert(0, C())
            )rr#r�textwrap�dedent�assert_python_ok)r1Ztestfnrrr�!test_import_in_del_does_not_crashasz-ImportTests.test_import_in_del_does_not_crashc
Cstj�dtj�zutd}tj�|�}t	|ddd��}Wd�n1s%wYzt�
|d�Wn7ty@|�d�Yn*t
yi}z|jttdd�ttd	d�fvrW�|�d
�|��WYd}~nd}~wwtt�t�|�Wtjd=tt�dStjd=tt�w)NrrrVrWrX)���r�z-cannot set modification time to large integerZ	EOVERFLOWZEINVALz2cannot set modification time to large integer ({}))r$r'r(rErvrr.�util�cache_from_sourcer[�utime�
OverflowErrorr��OSError�errno�getattrr�rm�statr )r1r*Zcompiledr�errr�test_timestamp_overflowls2�
����
z#ImportTests.test_timestamp_overflowcCs4z
tddgd�WdSty|�d�YdSw)NZhttpr>)�fromlistzfromlist must allow bogus names)rmrArnr0rrr�test_bogus_fromlist�s
�zImportTests.test_bogus_fromlistcCs.ddg}tj|�}|��\}}|�d|�dS)N�-cz&del __builtins__.__import__; import ossImportError)rZspawn_pythonZcommunicaterS)r1�args�popen�stdout�stderrrrr�test_delete_builtins_import�s
z'ImportTests.test_delete_builtins_importcC�>|�td��ddlm}Wd�dS1swYdS)Nz^No module named 'bogus'r)�foo)r]rA�bogusr�)r1r�rrr�/test_from_import_message_for_nonexistent_module��"�z;ImportTests.test_from_import_message_for_nonexistent_modulecCr�)Nz^cannot import name 'bogus'r)r�)r]rArZr�)r1r�rrr�,test_from_import_message_for_existing_module�r�z8ImportTests.test_from_import_message_for_existing_modulecCsvGdd�d�}d}|�t|�|�tj|<|�t��}ddlm}Wd�n1s+wY|�t	|j
�d�dS)Nc@�eZdZdd�ZdS)zIImportTests.test_from_import_AttributeError.<locals>.AlwaysAttributeErrorcSst�r-)�AttributeError)r1�_rrr�__getattr__�szUImportTests.test_from_import_AttributeError.<locals>.AlwaysAttributeError.__getattr__N)r��
__module__�__qualname__r�rrrr�AlwaysAttributeError��r��test_from_import_AttributeErrorr��does_not_existzScannot import name 'does_not_exist' from '<unknown module name>' (unknown location))�
addCleanuprr$r%r8rAr�r�rFrJrG)r1r��module_namerLr�rrrr��s��z+ImportTests.test_from_import_AttributeErrorc	Cs�ttdd��D|�t��ddlm}Wd�n1swY|�t��tjWd�n1s5wYWd�dSWd�dS1sMwYdS)Nr�rr�)rrEr8rAr�r�)r1r�rrr�test_issue31492�s���"�zImportTests.test_issue31492csdd��tj�dtj�tj�t�d��zid����fdd��td�D]S}t�	���fdd	�td
�D�}z,t
�|�j��
t
�d�Wd�n1sLwYWtj�dd�tj�dd�ntj�dd�tj�dd�w�durv��q#Wtjd=dStjd=w)
NcSs*|dkr|jjdkrt�d�dSdSdS)NZcall�has_deadlockg�������?)�f_code�co_name�time�sleep)�frame�event�argrrr�delay_has_deadlock�s�z8ImportTests.test_concurrency.<locals>.delay_has_deadlockr�datac
sVt������zddl}Wnty#}z|�WYd}~nd}~wwt�d�dSr7)r$�settrace�wait�package�
BaseException)r�r�)r�r��excrr�run�s
��z)ImportTests.test_concurrency.<locals>.runr�csg|]}tj�d��qS))�target)�	threadingZThread)�.0r�)r�rr�
<listcomp>�sz0ImportTests.test_concurrency.<locals>.<listcomp>r�r�zpackage.submodule)r$r'r(rE�join�dirnamerHrr�ZEventrZ
start_threads�setr�r�r%r&)r1r�Zthreadsr)r�r�r�r�r�test_concurrency�s, 
�����zImportTests.test_concurrency�win32�Windows-specificc
Cs�ddlm}|tj�}tj�d�j}tj	�
tj	�|�d�d|vr"dnd��}t
����}tj	�
|d�}t�|�tj	�
|tj	�tj��}t�tj|�t�||�t�tj	�
t�tj�d��D]}t�||�q^t�||�d}	d	d
�tjD�}	|dtj	�tj�|	d<tj|d
d�
dd�tj	�|��ddg�gtj|	tj	�|�d�t�||�tj|d
dgtj|	tj	�|�d�Wd�dS1s�wYdS)Nr)�GetModuleFileNameZ_sqlite3z
sqlite3{}.dllZ_dr!ZDLLszvcruntime*.dllcSsi|]
}|��tj|�qSr)�upperrE�environ)r��krrr�
<dictcomp>�sz:ImportTests.test_dll_dependency_import.<locals>.<dictcomp>�;Z
PYTHONPATHz-Scz	import oszp = os.add_dll_directory({!r})zimport _sqlite3zp.close)r��env�cwd)Z_winapir�r$Z	dllhandler.r��	find_spec�originrEr'r�r�r�rr�mkdir�basename�
executable�shutil�copy�globr_�prefixr�rH�
subprocessZ
check_callZSTDOUT)
r1r�ZdllnameZpydnameZdepname�tmpZtmp2Zpyexerr�rrr�test_dll_dependency_import�sP

�

 
���
�

�"�z&ImportTests.test_dll_dependency_importN)rz)'r�r�r�r2r4r<r?rBrMrrOrQrUrcrerhryr�r�r�r�r��skip_if_dont_write_bytecoder�r�r�r�r�r�r�r�r�r�r��unittest�
skipUnlessr$rwrrrrrr,CsJ

,(&




"r,c@sbeZdZe�ejdkd�dd��Ze�ejdkd�dd��Ze�ejdkd�dd��Z	d	d
�Z
dS)�FilePermissionTests�posix�%test meaningful only on posix systemsc	Cs�d}t|��7t��$\}}tj�|�}t|�}tj�|�s"|�	d�t�
|�}Wd�n1s1wYWd�n1s@wY|�tt
�
|j��td|@��dS)N��4__import__ did not result in creation of a .pyc filei�)rr+r.r�r�rmrEr'�existsrnr�rF�oct�S_IMODE�st_mode)r1�maskrr'�cached_pathr��	stat_inforrr�test_creation_modes
��
�z&FilePermissionTests.test_creation_modec	Cs�d}td��=t��*\}}tj�|�}t�||�t|�tj�	|�s(|�
d�t�|�}Wd�n1s7wYWd�n1sFwY|�t
t�|j��t
|��dS)N�r	r
�rr+r.r�r�rE�chmodrmr'rrnr�rFrr
r)r1�moderr'rrrrr�test_cached_mode_issue_2051s
�� 	z/FilePermissionTests.test_cached_mode_issue_2051c	Cs�d}td��=t��*\}}tj�|�}t�||�t|�tj�	|�s(|�
d�t�|�}Wd�n1s7wYWd�n1sFwY|dB}|�t
t�|j��t
|��dS)N�r	r
�r)r1rrr'rrZexpectedrrr�test_cached_readonly,s
��	 z(FilePermissionTests.test_cached_readonlyc	Cs`t���\}}t|ddd��
}|�d�Wd�n1swYt�|�}t�||j|jdf�t�|d�t	|�}|�
|jd�t�|d�t|ddd��
}|�d	�Wd�n1sawYt|�t
��t	|�}|�
|jd
�t|�t|�t
��|d}t�t
j�|�|�t	|�}|�
|jd
�Wd�dS1s�wYdS)NrVrWrXzx = 'original'
i�rZoriginalrzx = 'rewritten'
Z	rewrittenr})r+r[r\rEr�r��st_atime�st_mtimerrmrFr�rr.r/r�renamer�r�)r1rr'r�s�mZ
bytecode_onlyrrr�test_pyc_always_writable<s2�
�"�z,FilePermissionTests.test_pyc_always_writableN)r�r�r�rrrErrrrr rrrrrs�
�
�
rc@s|eZdZdZdZej�e�Z	ej�
e	e�ejdZe
j�e�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
r�cCs�tjdd�|_tj�|jd�|_t�|j	�t
|jddd��}|�|j
�Wd�n1s0wYtj�d|j	�t��dS)NrVrWrXr)r$r'�sys_pathr%r&r��orig_modulerEr��dir_namer[�	file_namer\�
module_sourcer(r.r/)r1rrrrr2ns�zPycRewritingTests.setUpcCsV|jtjdd�<|jdur|jtj|j<nt|j�t|j�t|j	�t
|j�dSr-)r"r$r'r#r%r�rrr%�
compiled_namerr$r0rrrr4ws



zPycRewritingTests.tearDowncCs t�}t|j||�tj|jSr-)rbrmr�r$r%)r1�nsrrr�
import_module�szPycRewritingTests.import_modulecCs~|��}|�|j|j�|�|j|j�|�|j|j�tj|j=|��}|�|j|j�|�|j|j�|�|j|j�dSr-)	r)rF�module_filenamer%�
code_filename�
func_filenamer$r%r��r1rrrrr�test_basics�s
zPycRewritingTests.test_basicscCsLtj|jdd�|��}|�|j|j�|�|j|j�|�|j|j�dS�Nzanother_module.py)�dfile)r�r�r%r)rFr*r+r,r-rrr�test_incorrect_code_name�s
z*PycRewritingTests.test_incorrect_code_namecCshd}tj|j|d�t�|j�t|j�}t��|��}|�	|j
|�|�	|j|�|�	|j|�dSr/)
r�r�r%rEr)r
r.r/r)rFr*r+r,)r1r��pyc_filerrrrr�test_module_without_source�s
z,PycRewritingTests.test_module_without_sourcecCs�t�|j�t|jd��}|�d�}t�|�}Wd�n1s!wYt|j	�}t
jj}|�
d�}|||<|jt|�d�}t|jd��}|�|�t�||�Wd�n1s\wY|��}|�|jj|j�dS)N�rb�r�)�	co_consts�wb)r�r�r%r[r'�read�marshal�load�listr6r.r)�__code__�index�replace�tupler\�dumprFZconstant�co_filename)r1r�header�codeZ	constantsZforeign_code�posrrrrr�test_foreign_code�s 
�


�z#PycRewritingTests.test_foreign_codeN)r�r�r�r�r&rEr'r�rr$r�r�r%r.r�r�r'r2r4r)r.r1r3rErrrrr![s		
r!c@sFeZdZdZeZdd�Zdd�Zdd�Ze	�
ejdkd	�d
d��Z
dS)
�
PathsTests)rgutestäöüßutestéèu
test°³²cCs t�|j�tjdd�|_dSr-)rEr�r'r$�syspathr0rrrr2�szPathsTests.setUpcCst|j�|jtjdd�<dSr-)rr'rGr$r0rrrr4�s
zPathsTests.tearDowncCsxttj�|jd�ddd��
}|�d�Wd�n1swYtj�|jd�td�}|�|j	d�t
d�dS)Nztest_trailing_slash.pyrVrWrXz testdata = 'test_trailing_slash'�/�test_trailing_slash)r[rEr'r�r\r$r�rmrF�testdatar)r1rrrrrrrI�s��zPathsTests.test_trailing_slashr�r�c	
Cs\ttj�|jd�d��
}|�d�Wd�n1swYt��tj�|j�}ddl}|�	�}|d}d||f}||dd�7}zt�
|�Wn tyl}z|jtj
tjtjfvrg|�d|f��d}~wwtj�d|�ztd�}Wnty�}z|�d	||f�WYd}~nd}~ww|�|jd�|�|j�|�|j�td�dS)
Nztest_unc_path.pyrVztestdata = 'test_unc_path'rz\\%s\%s$r�z%cannot access administrative share %rZ
test_unc_pathz,could not import 'test_unc_path' from %r: %r)r[rEr'r�r\r.r/r��socketZgethostname�listdirr�r�ZEPERMZEACCESZENOENTr�r$r(rmrArnrFrJr�rHrxr)	r1rr'rKZhnZdriveZuncr�rrrrr�
test_UNC_path�s<������zPathsTests.test_UNC_pathN)r�r�r�ZSAMPLESrr'r2r4rIrrr$rwrMrrrrrF�s
rFc@sHeZdZdd�ZeZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dS)�RelativeImportTestscCstd�dS)Nztest.relimport)rr0rrrr4�r5zRelativeImportTests.tearDowncCs ddlm}|�t|d��dS)Nr�)�	relimportrN)r!rOr�r�)r1rOrrr�test_relimport_star�sz'RelativeImportTests.test_relimport_starcs|�fdd�}tddd��|�tddd��|�tddd��|�t|�tddd��|�t|�tt�d��|�t|�dS)	Ncstd��dS)Nzfrom . import relimport)r`r�r(rr�check_relative�sz:RelativeImportTests.test_issue3221.<locals>.check_relativergztest.notarealmodule)�__package__r�znotarealpkg.notarealmoduler�)rS)�dictr8r9�objectr^)r1rRrrQr�test_issue3221�sz"RelativeImportTests.test_issue3221cCst�dddd�dS)Nz-W�ignorer�zfoo = 1; from . import foo)rZassert_python_failurer0rrr�)test_parentless_import_shadowed_by_globals
�z=RelativeImportTests.test_parentless_import_shadowed_by_globalcCsF|�t��ddlm}|�d�Wd�dS1swYdS)Nr�)�sepz>explicit relative import triggered an implicit absolute import)r8rArErYrn)r1rYrrr�#test_absolute_import_without_futures"�z7RelativeImportTests.test_absolute_import_without_futurec
Cs�tj�tj�t�dd�}tdd��Lt|��/|�t��ddl	}Wd�n1s+wY|�
dtj�|�
dtj�Wd�n1sHwYWd�dSWd�dS1s`wYdS)Nr��package2�
submodule1�
submodule2r)
rEr'r�r�rHrr
r8rAr\rar$r%)r1r'r\rrr�test_import_from_non_package s
�P�z0RelativeImportTests.test_import_from_non_packagec	Cs�tddd��6ttj�tj�t�d���ddl}|jj	Wd�n1s'wYWd�dSWd�dS1s?wYdS)Nr[zpackage2.submodule1zpackage2.submodule2r�r)
rr
rEr'r�r�rHZpackage2.submodule1r\r])r1r[rrr�!test_import_from_unloaded_package(s�
P�z5RelativeImportTests.test_import_from_unloaded_packageN)r�r�r�r4r2rPrVrXrZr^r_rrrrrN�s	rNc@r�)�OverridingImportBuiltinTestscCs�ddl}dd�}|�|�|�ttddd���|�|�d�Wd�n1s)wYtt�ddd���|�|�|�Wd�dS1sJwYdS)	NrcSsddl}|Sr7�rErarrrr�4sz?OverridingImportBuiltinTests.test_override_builtin.<locals>.foormcW�dS�N�r�r�rrr�<lambda>9�zDOverridingImportBuiltinTests.test_override_builtin.<locals>.<lambda>rdcWrbrcrrerrrrf?rg)rErFr�builtinsrrb)r1rEr�rrr�test_override_builtin0s�"�z2OverridingImportBuiltinTests.test_override_builtinN)r�r�r�rirrrrr`/r�r`c@s�eZdZdd�Zdd�Zdd�Zedd��Ze�	e
jd	kd
�e�e
e
d�o*e
��dkd
�edd����Zedd��Zedd��Zdd�Zedd��Zedd��Zdd�Zdd�ZdS)�PycacheTestscCstt�td�t|j�dS)Nr)r	rrrr*r0rrr�_cleanFszPycacheTests._cleancCsjtd|_|��t|jddd��}td|d�Wd�n1s"wYtj�dtj	�t
��dS)NrrVrWrXz/# This is a test file written by test_import.pyrir)rr*rkr[rkr$r'r(rErvr.r/)r1�fprrrr2Ks
�zPycacheTests.setUpcCs,tjdtjksJd��tjd=|��dS)NrzUnexpected sys.path[0])r$r'rErvrkr0rrrr4SszPycacheTests.tearDowncCsZ|�tj�d��tt�|�tj�d��tj�	|j
�}|�tj�|�d�|t��dS)Nrz*bytecode file {!r} for {!r} does not exist)�assertFalserEr'rrmrr�r.r�r�r*r��r1Zpyc_pathrrr�test_import_pyc_pathXs�z!PycacheTests.test_import_pyc_pathrr�geteuidrz=due to varying filesystem permission semantics (issue #11956)cCsptd��tt�Wd�n1swY|�tj�d��tj�	|j
�}|�tj�|�d�|t��dS)N�rz"bytecode file {!r} for {!r} exists)
rrmrr�rEr'rr.r�r�r*rmr�rnrrr�test_unwritable_directorybs

��z&PycacheTests.test_unwritable_directorycCsVtt�tj�|j�}|�tj�	|��t�
|j�tt�t��|�
ttt�dSr-)rmrr.r�r�r*r�rEr'rr)r	r/r8rA)r1r2rrr�test_missing_sourcersz PycacheTests.test_missing_sourcec
Cs|tt�t|j�}t�|j�tt�t��tt�}z|�	|j
tj�t�
�tjtj�|���Wt�|�dSt�|�wr-)rmrr
r*rEr)rr.r/rFrHr'r��getcwdrv�relpath�r1r2rrrr�test_missing_source_legacy~s
�z'PycacheTests.test_missing_source_legacycCs<tt�}tj�td�}|�|jtj�	t�
�tj|��dS)Nr)rmrr.r�r�rF�
__cached__rEr'r�rtrv)r1rr2rrr�test___cached__�s$zPycacheTests.test___cached__c
Csbtt�t|j�}t�|j�tt�t��tt�}|�	|j
tj�t�
�tjtj�|���dSr-)rmrr
r*rEr)rr.r/rFrxr'r�rtrvrurvrrr�test___cached___legacy_pyc�s
�z'PycacheTests.test___cached___legacy_pyccCs
dd�}t�d�|�|�ttj�dd�d��Wd�n1s#wYttj�dd�d��Wd�n1s=wYt��td�}tj	�
tj�dd��}|�|jtj�t�
�tj|��tj	�
tj�dd��}|�tjdjtj�t�
�tj|��dS)NcS�td�td�td�dS�N�pep3147�pep3147.foo�rrrrrr�cleanup��z5PycacheTests.test_package___cached__.<locals>.cleanupr}�__init__.pyr7�foo.pyr~)rEr�r�r[r'r�r.r/rmr�r�rFrxrtrvr$r%�r1r�rZinit_pycZfoo_pycrrr�test_package___cached__�s&

��� �z$PycacheTests.test_package___cached__cCs*dd�}t�d�|�|�ttj�dd�d��Wd�n1s#wYttj�dd�d��Wd�n1s=wYt��td�}t	d�t	d�t��td�}tj
�tj�dd��}|�|j
tj�t��tj|��tj
�tj�dd��}|�tjdj
tj�t��tj|��dS)NcSr{r|rrrrrr��r�z>PycacheTests.test_package___cached___from_pyc.<locals>.cleanupr}r�r7r�r~)rEr�r�r[r'r�r.r/rmrr�r�rFrxrtrvr$r%r�rrr� test_package___cached___from_pyc�s.

��� �z-PycacheTests.test_package___cached___from_pyccCsftt�tt�t|jddd��}td|d�Wd�n1s!wYtt�}|�|jd�dS)NrorWrXzx = 5rird)rmrrr[r*rkrFr�)r1rlrrrr�test_recompute_pyc_same_second�s�z+PycacheTests.test_recompute_pyc_same_secondN)r�r�r�rkr2r4rrorrrEr�skipIfr�rprrrsrwryrzr�r�r�rrrrrjCs2
	��



rjc@sVeZdZdZedZdd�Zdd�Ze�e	e
d�pe
��dkd	�ej
d
d���ZdS)
�TestSymbolicallyLinkedPackageZsamplez-taggedcCs�t�|j�t�|j�tjdd�|_t�|j�|�	tj|j�tj�
|jd�}t�|�tj�|�s7J�tj
|j|jdd�|�	tj|j�t��|�tj�|j�d�tj�tj�
|jd��sfJ�dS)Nr�T)Ztarget_is_directory)rr�tagged�package_namer$r'�
orig_sys_pathrEr�r�r�Zcreate_empty_filer�symlinkrr.r/rF�isdir�isfile)r1Z	init_filerrrr2�s
 z#TestSymbolicallyLinkedPackage.setUpcCs|jtjdd�<dSr-)r�r$r'r0rrrr4�sz&TestSymbolicallyLinkedPackage.tearDown�getwindowsversion)�rzWindows Vista or later requiredcCsNdgtjdd�<tj�|j�sJ�tj�tj�|jd��sJ�t�|j�dS)N�.r�)r$r'rErr�r�r.r)r0rrr�test_symlinked_dir_importablesz;TestSymbolicallyLinkedPackage.test_symlinked_dir_importableN)r�r�r�r�r�r2r4rrr�r$r�rZskip_unless_symlinkr�rrrrr��s
�r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ImportlibBootstrapTestscCstjd}|�|�dS)N�_frozen_importlib)r$r%r�r-rrr�test_frozen_importlibs
z-ImportlibBootstrapTests.test_frozen_importlibcC�Xddlm}tjd}|�||�|�|jd�|�|jd�|�|j	�
d�|j	�dS)Nr)�
_bootstrapr�zimportlib._bootstrapr.z
_bootstrap.py)r.r�r$r%r�rFr�rSr�rHr�)r1r�rrrrr�"test_frozen_importlib_is_bootstrap�
z:ImportlibBootstrapTests.test_frozen_importlib_is_bootstrapcCr�)Nr)�_bootstrap_external�_frozen_importlib_externalzimportlib._bootstrap_externalr.z_bootstrap_external.py)r.r�r$r%r�rFr�rSr�rHr�)r1r�rrrrr�4test_frozen_importlib_external_is_bootstrap_external"r�zLImportlibBootstrapTests.test_frozen_importlib_external_is_bootstrap_externalcCs*ddlm}tjd}|�|j|j�dS)Nr)�	machineryr�)r.r�r$r%r��
ModuleSpec)r1r�rrrrr�test_there_can_be_only_one*s
z2ImportlibBootstrapTests.test_there_can_be_only_oneN)r�r�r�r�r�r�r�rrrrr�s
r�c@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.

    cCsVt�d��}d|_td}td}|�t|�|�Wd�dS1s$wYdS)N�*importlib._bootstrap_external._path_isfileTrr�rZpatchZreturn_valuerrFr)r1�_path_isfiler'Zexpectrrr�test_get_sourcefile=s"�z&GetSourcefileTests.test_get_sourcefilecCsNt�d��}d|_td}|�t|�|�Wd�dS1s wYdS)Nr�Frr�)r1r�r'rrr�test_get_sourcefile_no_sourceFs
"�z0GetSourcefileTests.test_get_sourcefile_no_sourcecCstd}|�t|�|�dS)Nz.bad_ext)rrFr)r1r'rrr�test_get_sourcefile_bad_extNsz.GetSourcefileTests.test_get_sourcefile_bad_extN)r�r�r��__doc__r�r�r�rrrrr�3s
	r�c@s�eZdZdd�Zdd�Zd$dd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zedd��Ze�ed �d!d"��Zd#S)%�ImportTracebackTestscCs,t�t�tjdd�|_tj�dt�dSr7)rEr�rr$r'�old_pathr(r0rrrr2Ws
zImportTracebackTests.setUpcCs|jtjdd�<tt�dSr-)r�r$r'rrr0rrrr4\szImportTracebackTests.tearDownrcCsbtj�t||�}t|ddd��
}|�|�Wd�n1s wY|�t|�t�	�|S)NrVrWrX)
rEr'r�rr[r\r�rr.r/)r1rr�contentsrqZfnamerrrr�
create_module`s�z"ImportTracebackTests.create_modulecCstg}|r|jj}|j}|r||dkr|�|�|j}|s|�t|�t|�|�t||�D]
\}}|�||�q-dS)Nr|)	�tb_framer�rAr��tb_nextrF�len�ziprS)r1�tb�filesZ
deduped_filesrC�fnZpatrrr�assert_tracebackhs
��z%ImportTracebackTests.assert_tracebackc
CsTzddl}Wnty}z	|j}WYd}~n
d}~ww|�d�|�|tg�dS)Nr�#ImportError should have been raised)�nonexistent_xyzzyrA�
__traceback__rnr�rH)r1r�r�r�rrr�test_nonexistent_modulets��
z,ImportTracebackTests.test_nonexistent_modulec
C�b|�dd�zddl}Wnty!}z	|j}WYd}~n
d}~ww|�d�|�|tdg�dS)Nr�zimport nonexistent_xyzzyrr�r�)r�r�rAr�rnr�rH�r1r�r�r�rrr�test_nonexistent_module_nested~���
z3ImportTracebackTests.test_nonexistent_module_nestedc
Cr�)Nr��1/0r�)ZeroDivisionError should have been raisedr��r�r�r�r�rnr�rHr�rrr�test_exec_failure�r�z&ImportTracebackTests.test_exec_failurec
Csp|�dd�|�dd�zddl}Wnty'}z	|j}WYd}~n
d}~ww|�d�|�|tddg�dS)	Nr�z
import bar�barr�rr�r��bar.pyr�r�rrr�test_exec_failure_nested�s��
z-ImportTracebackTests.test_exec_failure_nestedc
Cs`|�dd�zddl}Wnty!}z	|j}WYd}~n
d}~ww|�d�|�|tg�dS)Nr�zinvalid syntax is invalidrz#SyntaxError should have been raised)r�r��SyntaxErrorr�rnr�rHr�rrr�test_syntax_error�s��
z&ImportTracebackTests.test_syntax_errorcCs�d}|�t|�tj�t|�}t�|�tj�|d�}t|ddd��
}|�|�Wd�n1s2wYtj�|d�}t|ddd��
}|�|�Wd�n1sUwYt	�
�||fS)N�_parent_foor�rVrWrXr�)r�rrEr'r�rr�r[r\r.r/)r1�parent�childZpkg_nameZpkg_path�	init_pathr�bar_pathrrr�_setup_broken_package�s
��z*ImportTracebackTests._setup_broken_packagec
Csf|�dd�\}}zddl}Wnty#}z	|j}WYd}~n
d}~ww|�d�|�|t|g�dS)Nr!r�rr��r�Z_parent_foo.barr�r�rnr�rH�r1r�r�r�r�r�rrr�test_broken_submodule����
z*ImportTracebackTests.test_broken_submodulec
Csj|�dd�\}}zddlm}Wnty%}z	|j}WYd}~n
d}~ww|�d�|�|t|g�dS)Nr!r�r�r�r��r�r�r�r�r�rnr�rH�r1r�r�r�r�r�rrr�test_broken_from����
z%ImportTracebackTests.test_broken_fromc
Csf|�dd�\}}zddl}Wnty#}z	|j}WYd}~n
d}~ww|�d�|�|t|g�dS)Nr�r!rr�r�r�rrr�test_broken_parent�r�z'ImportTracebackTests.test_broken_parentc
Csj|�dd�\}}zddlm}Wnty%}z	|j}WYd}~n
d}~ww|�d�|�|t|g�dS)Nr�r!rr�r�r�r�rrr�test_broken_parent_from�r�z,ImportTracebackTests.test_broken_parent_fromc
Cs�|�dd�tjd}dt|j�vr|jj}nd}zBdd�}||j_zddl}Wnty=}z	|j}WYd}~n
d}~ww|�	d�|�
|td	tg�W|durV|j`dS||j_dS|durd|j`w||j_w)
Nr�r!r��load_modulecWsdddS)Nr�rr)r�rrr�exec_module�r5z9ImportTracebackTests.test_import_bug.<locals>.exec_modulerr�z<frozen importlib)r�r$r%�vars�SourceLoaderr�r�r�r�rnr�rH)r1r.Zold_exec_moduler�r�r�r�rrr�test_import_bug�s,

��

�z$ImportTracebackTests.test_import_bugzneed TESTFN_UNENCODABLEcCs>t�dtd�}|�t|�|dd�}tjdd|dd�dS)Nr!�pass���r�zmod = __import__(%a)F)Z
__isolated)rr#rr�rr�)r1Zpynamerrrr�test_unencodable_filename�s
�z.ImportTracebackTests.test_unencodable_filenameN)r)r�r�r�r2r4r�r�r�r�r�r�r�r�r�r�r�r�rr�rrrr�rrrrr�Us&










r�c@s`eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�CircularImportTestszQSee the docstrings of the modules being imported for the purpose of the
    test.cCs*ttj���D]}|�d�rtj|=qdS)zSMake sure no modules pre-exist in sys.modules which are being used to
        test.z&test.test_import.data.circular_importsN)r;r$r%�keysrx)r1�keyrrrr4
s

��zCircularImportTests.tearDowncC�.zddl}WdSty|�d�YdSw)Nrz/circular import through relative imports failed)Z,test.test_import.data.circular_imports.basicrArn�r1rgrrr�test_direct�
�zCircularImportTests.test_directcCr�)Nrz@relative import in module contributing to circular import failed)Z/test.test_import.data.circular_imports.indirectrArnr�rrr�
test_indirectr�z!CircularImportTests.test_indirectcCr�)Nrz-circular import involving a subpackage failed)Z1test.test_import.data.circular_imports.subpackagerArnr�rrr�test_subpackager�z#CircularImportTests.test_subpackagecCs`zddlmmmm}Wnty|�d�Ynwddlm}|�	|j|j�dS)Nrz9circular import with rebinding of module attribute failed)r�)
Z0test.test_import.data.circular_imports.rebindingryr�Zcircular_imports�	rebindingrArnZ-test.test_import.data.circular_imports.subpkgr�r�)r1r�r�rrr�test_rebinding$s"�z"CircularImportTests.test_rebindingcCr�)Nrz9circular import with binding a submodule to a name failed)Z.test.test_import.data.circular_imports.bindingrArnr�rrr�test_binding,r�z CircularImportTests.test_bindingcCsddl}ddl}dSr7)Z*test.test_import.data.circular_imports.use�-test.test_import.data.circular_imports.sourcer�rrr�test_crossreference12r3z(CircularImportTests.test_crossreference1cCsp|�t��}ddl}Wd�n1swYt|j�}|�d|�|�d|�|�d|�|�d|�dS)Nrz-test.test_import.data.circular_imports.sourcer"zpartially initialized modulezcircular import)r8r�r�rJrGrS)r1rLrg�errmsgrrr�test_crossreference26s
�
z(CircularImportTests.test_crossreference2cCsH|�t��}ddl}Wd�n1swY|�dt|j��dS)Nrz�cannot import name 'b' from partially initialized module 'test.test_import.data.circular_imports.from_cycle1' (most likely due to a circular import))r8rAZ2test.test_import.data.circular_imports.from_cycle1rSrJrG)r1rLrgrrr�test_circular_from_import?s
��z-CircularImportTests.test_circular_from_importcCs�|�td�|�td�ddlmmm}|�t��ddlm}Wd�n1s.wY|�	t
|�t�|�t
|�t�|�
t��d|_Wd�dS1sWwYdS)Nz test.test_import.data.unwritablez"test.test_import.data.unwritable.xrre�*)r�rZ test.test_import.data.unwritableryr��
unwritableZassertWarns�
ImportWarningr�ZassertNotEqual�typerrFr8r�)r1r�r�rrr�test_unwritable_moduleIs�"�z*CircularImportTests.test_unwritable_moduleN)r�r�r�r�r4r�r�r�r�r�r�r�r�r�rrrrr�s	
r��__main__)Nr!)Brh�
contextlibr�r��importlib.utilr.Zimportlib._bootstrap_externalrr9rEr�rlr�r�rr$r�r�r�rrr�rrrrrZtest.support.import_helperr	r
rrr
Ztest.support.os_helperrrrrrrrZtest.test_importlib.utilr�typesrr��dont_write_bytecoderr �contextmanagerr+ZTestCaser,rr!rFrNr`rjr�r�r�r�r�r��mainrrrr�<module>sr�	GSY6E". !1
R�