Your IP : 216.73.216.213


Current Path : /opt/alt/python38/lib64/python3.8/test/test_import/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/test/test_import/__pycache__/__init__.cpython-38.pyc

U

i�f���@s(ddlZddlZddlmZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlmZddlZddlZddlZddlZddlZddlmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%ddlm&Z&ddl'm(Z(e�)ej*d�Z+dd�Z,ej-d%d
d��Z.Gdd
�d
ej/�Z0e+Gdd�dej/��Z1Gdd�dej/�Z2Gdd�dej/�Z3Gdd�dej/�Z4Gdd�dej/�Z5Gdd�dej/�Z6Gdd�dej/�Z7e"Gdd�dej/��Z8e"Gdd�dej/��Z9Gd d!�d!ej/�Z:Gd"d#�d#ej/�Z;e<d$k�r$e�=�dS)&�N)�_get_sourcefile)�TESTFN�forget�	is_jython�make_legacy_pyc�rmtree�	swap_attr�	swap_item�
temp_umask�unlink�unload�cpython_only�TESTFN_UNENCODABLE�temp_dir�
DirsOnSysPath)�
script_helper)�uncachez*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/python38/lib64/python3.8/test/test_import/__init__.py�remove_files%s�
r�c
cs�|pd}t��t}t�|||�}tj�|d�}z(tj�d|�||fVtj�|�W5|dk	rj|tj|<n|tjkr|tj|=XW5QRXdS)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)rr�	importlib�invalidate_caches��selfrrr�setUpEszImportTests.setUpcCstt�dSr))rrr,rrr�tearDownIszImportTests.tearDownc	Cs"|�t��ddl}W5QRXdS�Nr)�assertRaises�ModuleNotFoundError�(something_that_should_not_exist_anywhere�r-r3rrr�&test_import_raises_ModuleNotFoundErrorLsz2ImportTests.test_import_raises_ModuleNotFoundErrorc	Cs&|�t��ddlm}W5QRXdS)Nr)�blah)r1r2r3r6)r-r6rrr�:test_from_import_missing_module_raises_ModuleNotFoundErrorPszFImportTests.test_from_import_missing_module_raises_ModuleNotFoundErrorc	Cs&|�t��ddlm}W5QRXdS)Nr)r3)r1�ImportErrorr*r3r4rrr�0test_from_import_missing_attr_raises_ImportErrorTsz<ImportTests.test_from_import_missing_attr_raises_ImportErrorc	CsZ|�t��}ddlm}W5QRX|�|jjd�|�|jjtj�|�	t
|j�d�dS)Nr��i_dont_exist�osz7cannot import name 'i_dont_exist' from 'os' \(.*os.py\))r1r8r<r;�assertEqual�	exceptionrr#�__file__�assertRegex�str�r-�cmr;rrr�/test_from_import_missing_attr_has_name_and_pathXs
z;ImportTests.test_from_import_missing_attr_has_name_and_pathc	Csbddl}|�t��}ddlm}W5QRX|�|jjd�|�|jj|j�|�	t
|j�d�dS)Nrr:�	_testcapizCcannot import name 'i_dont_exist' from '_testcapi' \(.*\.(so|pyd)\))rEr1r8r;r=r>rr#r?r@rA)r-rErCr;rrr�2test_from_import_missing_attr_has_name_and_so_path_sz>ImportTests.test_from_import_missing_attr_has_name_and_so_pathc	CsD|�t��}ddlm}W5QRX|�|jjd�|�|jj�dS)Nrr:�_warning)	r1r8rGr;r=r>rZassertIsNoner#rBrrr�&test_from_import_missing_attr_has_namehsz2ImportTests.test_from_import_missing_attr_has_namec	CsF|�t��}ddlm}W5QRX|�|jjddh�|�|j�dS)Nrr:�	posixpathZntpath)r1r8Zos.pathr;�assertInr>r�assertIsNotNonerBrrr�/test_from_import_missing_attr_path_is_canonicalosz;ImportTests.test_from_import_missing_attr_path_is_canonicalc
Csddl}t��p\}}t|d��}|�d�W5QRXi}|�t|�|��d���td|�d�|�W5QRX|�d|�W5QRXt��p\}}t|d��}|�d�W5QRXi}|�t|�|��d	���td|�d�|�W5QRX|�d|�W5QRXdS)
Nr�wz__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)r-rNrr#r�globalsrrr�"test_from_import_star_invalid_typeus*��z.ImportTests.test_from_import_star_invalid_typec	Cs"|�t��ddl}W5QRXdSr0)r1r8�RAnDoM)r-rXrrr�test_case_sensitivity�sz!ImportTests.test_case_sensitivitycCsddlm}dS)Nr)�double_const)�testrZ)r-rZrrr�test_double_const�szImportTests.test_double_constcsV�fdd�}tj�dtj�z*|d�tj�d�rDdD]}||�q6W5tjd=XdS)Nc
st|}trtd}ntd}t|d��F}td|d|d�t�d�}t�d�}td||d�td	||d�W5QRXttjkr�tjt=t�	�znztt�}Wn4t
k
r�}z��d
||f�W5d}~XYnX��|j|d|���|j|d|�W5t
t�t|�t|�XdS)NrrrMz)# This tests Python's ability to import azfile.��filei�za =zb =zimport from %s failed: %sz'module loaded (%s) but contents invalid)rrrO�print�randomZ	randranger r!r*r+rr�
__import__r8�failr=�a�b)�extr&Zpycrrcrd�mod�errr,rr�test_with_extension�s>
�


$
�
�z4ImportTests.test_import.<locals>.test_with_extensionrr�win)z.PYz.Pyz.pYrz.PYWz.pYw)r r#r$r<�curdir�platform�
startswith)r-rhrerr,r�test_import�s"zImportTests.test_import�longlistcCs�|d}t|d��2}|�d�td�D]}|�d�q&|�d�W5QRXzt�|�W5t|�Xtj�d�t	�
�i}zt|�td|d|�W5tjd=t|d	�t|d
�|��ztj|=Wnt
k
r�YnXXdS)NrrMzd = [
i�z"",
�]r����c�ozimport )rOrP�ranger�
py_compile�compiler r#�appendr*r+�clearr!�KeyErrorrrT)r-�module�filenamer�i�	namespacerrr�test_module_with_large_stack�s.

z(ImportTests.test_module_with_large_stackc	Cs�td}t|d��}td|d�W5QRXtj�dtj�t�	�ttj
krTtj
t=z0dD]&}|�t
tt�|�ttj
d|�qZW5tjd=tt�XdS)NrrMza = 1/0r]r)���z'damaged module in sys.modules on %i try)rrOr_r r#r$r<rjr*r+r!rr1�ZeroDivisionErrorrarU)r-r&rr{rrr�test_failing_import_sticks�s

�
z&ImportTests.test_failing_import_stickscCsTddl}ddl}|�|||j�|�t|jd��ddlm}|�||j|j�dS)Nrr?)r[�test.support�assertIs�__name__�
assertTrue�hasattr�support)r-�xr[�yrrr�test_import_name_binding�sz$ImportTests.test_import_name_bindingcCsjzd}W5ddlmm}Xd}|dkrFddlmm}|d7}q"td�D]}ddlmm}qNdS)Nr.�
r~r)Ztest.support.script_helperr�rrs)r-r�r{rrr�test_issue31286s
zImportTests.test_issue31286c	Csttjd}t|d��}|�d�W5QRXtj�dtj�z�tt�}|�ttj
�|�|jdd�|�|jdd�t	t�t|d��}|�d�W5QRX|�ttj|�tj
�t�}|�|d	�|�|jd
d�|�|jdd�W5tjd=t	t�t
t�XdS)N�pyrMz
a = 1
b=2
rr~z!module has wrong attribute valuesrza = 10
b=20//0
z$expected module to be in sys.modulesr�)rr<�extseprOrPr r#r$rjrrrarJr!r=rcrdr1r�r*�reload�getrK)r-r&rrfrrr�test_failing_reloads(zImportTests.test_failing_reloadc	Cs�td}t|d��}|�d�W5QRXtj�dtj�zft
t�}|�|j�
d��t�|�tj	t=t|�t��t
t�}tj�|j�\}}|�|d�W5tjd=tt�ttj	kr�tj	t=XdS)NrrMztest = None
rr)rrOrPr r#r$r<rjrr!rar�r?�endswithr%rr*r+�splitextr=)r-r&rrf�basererrr�test_file_to_source?s$

zImportTests.test_file_to_sourcec	Csjtj�t�}t��}z|�|�Wn$tk
rF|�d�	|��YnX|�
t��}t|�W5QRXdS)Nzpath is not encodable to {})
r<r#�abspathrr �getfilesystemencoding�encode�UnicodeEncodeError�skipTest�formatr1r8ra)r-r#�encodingrqrrr�test_import_by_filenameWsz#ImportTests.test_import_by_filenamecCs"t�dtt�d��}t�|�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_crashasz-ImportTests.test_import_in_del_does_not_crashc
Cs�tj�dtj�z�td}tj�	|�}t
|d��}W5QRXzt�|d�Wnntk
rj|�
d�YnRtk
r�}z4|jttdd�ttdd�fkr��|�
d�|��W5d}~XYnXtt�t�|�W5tjd=tt�XdS)	NrrrM)���r�z-cannot set modification time to large integerZ	EOVERFLOWZEINVALz2cannot set modification time to large integer ({}))r r#r$r<rjrrr*�util�cache_from_sourcerO�utime�
OverflowErrorr��OSError�errno�getattrr�ra�stat)r-r&Zcompiledr�errr�test_timestamp_overflowls(

�"z#ImportTests.test_timestamp_overflowcCs6ztddgd�Wntk
r0|�d�YnXdS)NZhttpr6)�fromlistzfromlist must allow bogus names)rar8rbr,rrr�test_bogus_fromlist�szImportTests.test_bogus_fromlistcCs.ddg}tj|�}|��\}}|�d|�dS)N�-cz&del __builtins__.__import__; import ossImportError)rZspawn_pythonZcommunicaterJ)r-�args�popen�stdout�stderrrrr�test_delete_builtins_import�s
z'ImportTests.test_delete_builtins_importc	Cs(|�td��ddlm}W5QRXdS)Nz^No module named 'bogus'r)�foo)rQr8�bogusr�)r-r�rrr�/test_from_import_message_for_nonexistent_module�sz;ImportTests.test_from_import_message_for_nonexistent_modulec	Cs(|�td��ddlm}W5QRXdS)Nz^cannot import name 'bogus'r)r�)rQr8rNr�)r-r�rrr�,test_from_import_message_for_existing_module�sz8ImportTests.test_from_import_message_for_existing_modulec	CsbGdd�d�}d}|�t|�|�tj|<|�t��}ddlm}W5QRX|�t	|j
�d�dS)Nc@seZdZdd�ZdS)zIImportTests.test_from_import_AttributeError.<locals>.AlwaysAttributeErrorcSst�dSr))�AttributeError)r-�_rrr�__getattr__�szUImportTests.test_from_import_AttributeError.<locals>.AlwaysAttributeError.__getattr__N)r��
__module__�__qualname__r�rrrr�AlwaysAttributeError�sr��test_from_import_AttributeErrorr��does_not_existzScannot import name 'does_not_exist' from '<unknown module name>' (unknown location))�
addCleanuprr r!r1r8r�r�r=rAr>)r-r��module_namerCr�rrrr��s�z+ImportTests.test_from_import_AttributeErrorc
CsZttdd��D|�t��ddlm}W5QRX|�t��tjW5QRXW5QRXdS)Nr�rr�)rr<r1r8r�r�)r-r�rrr�test_issue31492�s
zImportTests.test_issue31492cs�tj�dtj�tj�t�d��z�d���fdd��td�D]x}t�	���fdd�td�D�}z*tj
�|�j��t�d�W5QRXW5tj
�d	d�tj
�d
d�X�dk	r<��q<W5tjd=XdS)Nr�datac
s@���zddl}Wn&tk
r:}z|�W5d}~XYnXdSr0)�wait�package�
BaseException)r�r�)�event�excrr�run�s
z)ImportTests.test_concurrency.<locals>.runr�csg|]}tj�d��qS))�target)�	threadingZThread)�.0r�)r�rr�
<listcomp>�sz0ImportTests.test_concurrency.<locals>.<listcomp>rr�zpackage.submodule)r r#r$r<�join�dirnamer?rsr�ZEventr!r"r[r�Z
start_threads�set�time�sleep)r-r{Zthreadsr)r�r�r�r�test_concurrency�s 
zImportTests.test_concurrency�win32�Windows-specificc
Cs�ddlm}|tj�}tj�d�j}tj	�
tj	�|�d�d|krDdnd��}t
j����$}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�W5QRXdS)Nr)�GetModuleFileNameZ_sqlite3z
sqlite3{}.dllZ_drZDLLszvcruntime*.dllcSsi|]}|��tj|�qSr)�upperr<�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�originr<r#r�r�r�r[r�r�mkdir�basename�
executable�shutil�copy�globrS�prefixr�r?�
subprocessZ
check_callZSTDOUT)
r-r�ZdllnameZpydnameZdepnameZtmpZtmp2Zpyexerr�rrr�test_dll_dependency_import�sR

�
 
���
�

�z&ImportTests.test_dll_dependency_importN)rn)'r�r�r�r.r/r5r7r9rDr
rFrHrLrWrYr\rmr}r�r�r�r��skip_if_dont_write_bytecoder�r�r�r�r�r�r�r�r�r�r��unittest�
skipUnlessr rkr�rrrrr(CsH
,
(&




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|��Pt��>\}}tj�|�}t|�}tj�|�sD|�	d�t�
|�}W5QRXW5QRX|�tt
�
|j��td|@��dS)N��4__import__ did not result in creation of a .pyc filei�)r
r'r*r�r�rar<r#�existsrbr�r=�oct�S_IMODE�st_mode)r-�maskrr#�cached_pathry�	stat_inforrr�test_creation_modes
�z&FilePermissionTests.test_creation_modec
Cs�d}td��\t��J\}}tj�|�}t�||�t|�tj�	|�sP|�
d�t�|�}W5QRXW5QRX|�t
t�|j��t
|��dS)N�r�r��r
r'r*r�r�r<�chmodrar#r�rbr�r=r�r�r�)r-�moderr#r�r�rrr�test_cached_mode_issue_2051s
z/FilePermissionTests.test_cached_mode_issue_2051c
Cs�d}td��\t��J\}}tj�|�}t�||�t|�tj�	|�sP|�
d�t�|�}W5QRXW5QRX|dB}|�t
t�|j��t
|��dS)N�r�r��r�)r-r�rr#r�r�Zexpectedrrr�test_cached_readonly$s
z(FilePermissionTests.test_cached_readonlyc
Cst���
\}}t|d��}|�d�W5QRXt�|�}t�||j|jdf�t�|d�t	|�}|�
|jd�t�|d�t|d��}|�d�W5QRXt|�t
��t	|�}|�
|jd�t|�t|�t
��|d	}t�t
j�|�|�t	|�}|�
|jd�W5QRXdS)
NrMzx = 'original'
i�rZoriginalr�zx = 'rewritten'
Z	rewrittenrq)r'rOrPr<r�r��st_atime�st_mtimer�rar=r�rr*r+r�renamer�r�)r-rr#r�s�mZ
bytecode_onlyrrr�test_pyc_always_writable4s,
z,FilePermissionTests.test_pyc_always_writableN)r�r�r�r�r�r<rr�rrr	rrrrr��s�
�
�
r�c@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�c	Csntjdd�|_tj�|jd�|_t�|j	�t
|jd��}|�|j
�W5QRXtj�d|j	�t��dS)NrMr)r r#�sys_pathr!r"r��orig_moduler<r��dir_namerO�	file_namerP�
module_sourcer$r*r+)r-rrrrr.fszPycRewritingTests.setUpcCsV|jtjdd�<|jdk	r*|jtj|j<n
t|j�t|j�t|j	�t
|j�dSr))rr r#rr!r�rrr�
compiled_namerr
r,rrrr/os



zPycRewritingTests.tearDowncCs t�}t|j||�tj|jSr))rVrar�r r!)r-�nsrrr�
import_moduleyszPycRewritingTests.import_modulecCs~|��}|�|j|j�|�|j|j�|�|j|j�tj|j=|��}|�|j|j�|�|j|j�|�|j|j�dSr))	rr=�module_filenamer�
code_filename�
func_filenamer r!r��r-rfrrr�test_basics~s
zPycRewritingTests.test_basicscCsLtj|jdd�|��}|�|j|j�|�|j|j�|�|j|j�dS�Nzanother_module.py)�dfile)rtrurrr=rrrrrrr�test_incorrect_code_name�s
z*PycRewritingTests.test_incorrect_code_namecCshd}tj|j|d�t�|j�t|j�}t��|��}|�	|j
|�|�	|j|�|�	|j|�dSr)
rtrurr<r%rr*r+rr=rrr)r-r��pyc_filerfrrr�test_module_without_source�s
z,PycRewritingTests.test_module_without_sourcec	Cs�t�|j�t|jd��}|�d�}t�|�}W5QRXt|j	�}t
jj}|�
d�}|||<|jt|�d�}t|jd��}|�|�t�||�W5QRX|��}|�|jj|j�dS)N�rb�r~)�	co_consts�wb)rtrurrOr�read�marshal�load�listrr*r�__code__�index�replace�tuplerP�dumpr=Zconstant�co_filename)r-r�header�codeZ	constantsZforeign_code�posrfrrr�test_foreign_code�s



z#PycRewritingTests.test_foreign_codeN)r�r�r�r�rr<r#r�rr
r�r�rr*r�r�rr.r/rrrrr.rrrrr
Ss		
r
c@sFeZdZdZeZdd�Zdd�Zdd�Ze	�
ejdkd	�d
d��Z
dS)
�
PathsTests)r[utestäöüßutestéèu
test°³²cCs t�|j�tjdd�|_dSr))r<r�r#r �syspathr,rrrr.�szPathsTests.setUpcCst|j�|jtjdd�<dSr))rr#r0r r,rrrr/�s
zPathsTests.tearDownc	Cs`ttj�|jd�d��}|�d�W5QRXtj�|jd�td�}|�|j	d�t
d�dS)Nztest_trailing_slash.pyrMz testdata = 'test_trailing_slash'�/�test_trailing_slash)rOr<r#r�rPr rvrar=�testdatar)r-rrfrrrr2�szPathsTests.test_trailing_slashr�r�c	
CsRttj�|jd�d��}|�d�W5QRXt��tj�|j�}ddl}|�	�}|d}d||f}||dd�7}zt�
|�WnJtk
r�}z,|jtj
tjtjfkr�|�d|f��W5d}~XYnXtj�d|�ztd�}Wn6tk
�r }z|�d	||f�W5d}~XYnX|�|jd�|�|j�|�|j�td�dS)
Nztest_unc_path.pyrMztestdata = 'test_unc_path'rz\\%s\%s$rz%cannot access administrative share %rZ
test_unc_pathz,could not import 'test_unc_path' from %r: %r)rOr<r#r�rPr*r+r��socketZgethostname�listdirr�r�ZEPERMZEACCESZENOENTr�r r$rar8rbr=r3r�r?rlr)	r-rr#r4ZhnZdriveZuncr�rfrrr�
test_UNC_path�s2�zPathsTests.test_UNC_pathN)r�r�r�ZSAMPLESrr#r.r/r2r�r�r rkr6rrrrr/�s	r/c@sHeZdZdd�ZeZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dS)�RelativeImportTestscCstd�dS)Nztest.relimport)rr,rrrr/�szRelativeImportTests.tearDowncCs ddlm}|�t|d��dS)Nr)�	relimportr7)rr8r�r�)r-r8rrr�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)rTr�rrr�check_relative�sz:RelativeImportTests.test_issue3221.<locals>.check_relativer[ztest.notarealmodule)�__package__r�znotarealpkg.notarealmoduler�)r<)�dictr1r2�objectrR)r-r;rr:r�test_issue3221�sz"RelativeImportTests.test_issue3221cCst�dddd�dS)Nz-W�ignorer�zfoo = 1; from . import foo)rZassert_python_failurer,rrr�)test_parentless_import_shadowed_by_global	s
�z=RelativeImportTests.test_parentless_import_shadowed_by_globalc	Cs0|�t��ddlm}|�d�W5QRXdS)Nr~)�sepz>explicit relative import triggered an implicit absolute import)r1r8r<rBrb)r-rBrrr�#test_absolute_import_without_futuresz7RelativeImportTests.test_absolute_import_without_futurecCs�tj�tj�t�dd�}tdd��Tt|��@|�t��ddl	}W5QRX|�
dtj�|�
dtj�W5QRXW5QRXdS)Nr��package2�
submodule1�
submodule2r)
r<r#r�r�r?rrr1r8rErUr r!)r-r#rErrr�test_import_from_non_packagesz0RelativeImportTests.test_import_from_non_packagec
CsRtddd��<ttj�tj�t�d���ddl}|jj	W5QRXW5QRXdS)NrDzpackage2.submodule1zpackage2.submodule2r�r)
rrr<r#r�r�r?Zpackage2.submodule1rErF)r-rDrrr�!test_import_from_unloaded_packages
�z5RelativeImportTests.test_import_from_unloaded_packageN)r�r�r�r/r.r9r?rArCrGrHrrrrr7�s	r7c@seZdZdd�ZdS)�OverridingImportBuiltinTestsc	Csxddl}dd�}|�|�|�ttddd���|�|�d�W5QRXtt�ddd���|�|�|�W5QRXdS)	NrcSsddl}|Sr0�r<rJrrrr�+sz?OverridingImportBuiltinTests.test_override_builtin.<locals>.fooracWsdS�N�r�r�rrr�<lambda>0�zDOverridingImportBuiltinTests.test_override_builtin.<locals>.<lambda>rLcWsdSrKrrMrrrrN6rO)r<r=r�builtinsr	rV)r-r<r�rrr�test_override_builtin'sz2OverridingImportBuiltinTests.test_override_builtinN)r�r�r�rQrrrrrI&srIc@s�eZdZdd�Zdd�Zdd�Zedd��Ze�	e
jd	kd
�e�e
e
d�oTe
��dkd
�edd����Zedd��Zedd��Zdd�Zedd��Zedd��Zdd�Zdd�ZdS)�PycacheTestscCstt�td�t|j�dS)Nr)rrrrr&r,rrr�_clean=szPycacheTests._cleanc	CsRtd|_|��t|jd��}td|d�W5QRXtj�dtj	�t
��dS)NrrMz/# This is a test file written by test_import.pyr]r)rr&rSrOr_r r#r$r<rjr*r+)r-�fprrrr.Bs
zPycacheTests.setUpcCs,tjdtjkstd��tjd=|��dS)NrzUnexpected sys.path[0])r r#r<rj�AssertionErrorrSr,rrrr/JszPycacheTests.tearDowncCsZ|�tj�d��tt�|�tj�d��tj�	|j
�}|�tj�|�d�|t��dS)Nrz*bytecode file {!r} for {!r} does not exist)�assertFalser<r#r�rarr�r*r�r�r&r��r-Zpyc_pathrrr�test_import_pyc_pathOs��z!PycacheTests.test_import_pyc_pathr�r��geteuidrz=due to varying filesystem permission semantics (issue #11956)c	Cs\td��tt�W5QRX|�tj�d��tj�	|j
�}|�tj�|�d�|t��dS)N�rz"bytecode file {!r} for {!r} exists)
r
rarr�r<r#r�r*r�r�r&rVr�rWrrr�test_unwritable_directoryYs
��z&PycacheTests.test_unwritable_directorycCsVtt�tj�|j�}|�tj�	|��t�
|j�tt�t��|�
ttt�dSr))rarr*r�r�r&r�r<r#r�r%rr+r1r8)r-rrrr�test_missing_sourceisz PycacheTests.test_missing_sourcec
Csttt�t|j�}t�|j�tt�t��tt�}z,|�	|j
tj�t�
�tjtj�|���W5t�|�XdSr))rarrr&r<r%rr*r+r=r?r#r��getcwdrj�relpath�r-rrrrr�test_missing_source_legacyus
�z'PycacheTests.test_missing_source_legacycCs<tt�}tj�td�}|�|jtj�	t�
�tj|��dS)Nr)rarr*r�r�r=�
__cached__r<r#r�r]rj)r-rrrrr�test___cached__�szPycacheTests.test___cached__c
Csbtt�t|j�}t�|j�tt�t��tt�}|�	|j
tj�t�
�tjtj�|���dSr))rarrr&r<r%rr*r+r=rar#r�r]rjr^r_rrr�test___cached___legacy_pyc�s
�z'PycacheTests.test___cached___legacy_pycc	Cs�dd�}t�d�|�|�ttj�dd�d��W5QRXttj�dd�d��W5QRXt��td�}tj	�
tj�dd��}|�|jtj�t�
�tj|��tj	�
tj�dd��}|�tjdjtj�t�
�tj|��dS)NcSstd�td�td�dS�N�pep3147�pep3147.foo�rrrrrr�cleanup�sz5PycacheTests.test_package___cached__.<locals>.cleanupre�__init__.pyrM�foo.pyrf)r<r�r�rOr#r�r*r+rar�r�r=rar]rjr r!�r-rhrZinit_pycZfoo_pycrrr�test_package___cached__�s"



� �z$PycacheTests.test_package___cached__c	Csdd�}t�d�|�|�ttj�dd�d��W5QRXttj�dd�d��W5QRXt��td�}t	d�t	d�t��td�}tj
�tj�dd��}|�|j
tj�t��tj|��tj
�tj�dd��}|�tjdj
tj�t��tj|��dS)NcSstd�td�td�dSrdrgrrrrrh�sz>PycacheTests.test_package___cached___from_pyc.<locals>.cleanuprerirMrjrf)r<r�r�rOr#r�r*r+rarr�r�r=rar]rjr r!rkrrr� test_package___cached___from_pyc�s*



� �z-PycacheTests.test_package___cached___from_pycc	CsNtt�tt�t|jd��}td|d�W5QRXtt�}|�|jd�dS)Nrczx = 5r]rL)rarrrOr&r_r=r�)r-rTrrrr�test_recompute_pyc_same_second�sz+PycacheTests.test_recompute_pyc_same_secondN)r�r�r�rSr.r/r�rXr�r�r<r�skipIfr�rYr[r\r`rbrcrlrmrnrrrrrR:s0
	��



rRc@sXeZdZdZedZdd�Zdd�Ze�e	e
d�p>e
��dkd	�ej
jd
d���ZdS)
�TestSymbolicallyLinkedPackageZsamplez-taggedcCs�tj�|j�tj�|j�tjdd�|_t�	|j�|�
tjj|j�tj�|jd�}tj�|�tj�
|�svt�tj|j|jdd�|�
tjj|j�t��|�tj�|j�d�tj�tj�|jd��s�t�dS)NriT)Ztarget_is_directory)r[r�r�tagged�package_namer r#�
orig_sys_pathr<r�r�r�Zcreate_empty_filer�rU�symlinkrr*r+r=�isdir�isfile)r-Z	init_filerrrr.�sz#TestSymbolicallyLinkedPackage.setUpcCs|jtjdd�<dSr))rsr r#r,rrrr/�sz&TestSymbolicallyLinkedPackage.tearDown�getwindowsversion)�rzWindows Vista or later requiredcCsNdgtjdd�<tj�|j�s"t�tj�tj�|jd��s>t�t�|j�dS)N�.ri)	r r#r<r�rrrUr�r*rr,rrr�test_symlinked_dir_importable�sz;TestSymbolicallyLinkedPackage.test_symlinked_dir_importableN)r�r�r�rrrqr.r/r�r�r�r rwr[r�Zskip_unless_symlinkrzrrrrrp�s
�rpc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ImportlibBootstrapTestscCstjd}|�|�dS)N�_frozen_importlib)r r!r�rrrr�test_frozen_importlib
s
z-ImportlibBootstrapTests.test_frozen_importlibcCsXddlm}tjd}|�||�|�|jd�|�|jd�|�|j	�
d�|j	�dS)Nr)�
_bootstrapr|zimportlib._bootstrapr*z
_bootstrap.py)r*r~r r!r�r=r�r<r�r?r�)r-r~rfrrr�"test_frozen_importlib_is_bootstraps
z:ImportlibBootstrapTests.test_frozen_importlib_is_bootstrapcCsXddlm}tjd}|�||�|�|jd�|�|jd�|�|j	�
d�|j	�dS)Nr)�_bootstrap_external�_frozen_importlib_externalzimportlib._bootstrap_externalr*z_bootstrap_external.py)r*r�r r!r�r=r�r<r�r?r�)r-r�rfrrr�4test_frozen_importlib_external_is_bootstrap_externals
zLImportlibBootstrapTests.test_frozen_importlib_external_is_bootstrap_externalcCs*ddlm}tjd}|�|j|j�dS)Nr)�	machineryr|)r*r�r r!r��
ModuleSpec)r-r�rfrrr�test_there_can_be_only_one!s
z2ImportlibBootstrapTests.test_there_can_be_only_oneN)r�r�r�r}rr�r�rrrrr{	sr{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.

    c	Cs@t�d��,}d|_td}td}|�t|�|�W5QRXdS)N�*importlib._bootstrap_external._path_isfileTrr��mockZpatchZreturn_valuerr=r)r-�_path_isfiler#Zexpectrrr�test_get_sourcefile4s
z&GetSourcefileTests.test_get_sourcefilec	Cs8t�d��$}d|_td}|�t|�|�W5QRXdS)Nr�Frr�)r-r�r#rrr�test_get_sourcefile_no_source=sz0GetSourcefileTests.test_get_sourcefile_no_sourcecCstd}|�t|�|�dS)Nz.bad_ext)rr=r)r-r#rrr�test_get_sourcefile_bad_extEsz.GetSourcefileTests.test_get_sourcefile_bad_extN)r�r�r��__doc__r�r�r�rrrrr�*s	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�dSr0)r<r�rr r#�old_pathr$r,rrrr.Ns
zImportTracebackTests.setUpcCs|jtjdd�<tt�dSr))r�r r#rrr,rrrr/SszImportTracebackTests.tearDownrc	CsJtj�t||�}t|d��}|�|�W5QRX|�t|�t�	�|S)NrM)
r<r#r�rrOrPr�rr*r+)r-rf�contentsreZfnamerrrr�
create_moduleWsz"ImportTracebackTests.create_modulecCsrg}|r8|jj}|j}|r&||dkr0|�|�|j}q|�t|�t|�|�t||�D]\}}|�||�qXdS)Nrp)	�tb_frame�f_coder*rv�tb_nextr=�len�ziprJ)r-�tb�filesZ
deduped_filesr,�fnZpatrrr�assert_traceback_s
z%ImportTracebackTests.assert_tracebackc
CsRzddl}Wn(tk
r4}z
|j}W5d}~XYnX|�d�|�|tg�dS)Nr�#ImportError should have been raised)�nonexistent_xyzzyr8�
__traceback__rbr�r?)r-r�r�r�rrr�test_nonexistent_moduleks
z,ImportTracebackTests.test_nonexistent_modulec
Cs`|�dd�zddl}Wn(tk
r@}z
|j}W5d}~XYnX|�d�|�|tdg�dS)Nr�zimport nonexistent_xyzzyrr�rj)r�r�r8r�rbr�r?�r-r�r�r�rrr�test_nonexistent_module_nestedus
z3ImportTracebackTests.test_nonexistent_module_nestedc
Cs`|�dd�zddl}Wn(tk
r@}z
|j}W5d}~XYnX|�d�|�|tdg�dS)Nr��1/0r�)ZeroDivisionError should have been raisedrj�r�r�r�r�rbr�r?r�rrr�test_exec_failures
z&ImportTracebackTests.test_exec_failurec
Csn|�dd�|�dd�zddl}Wn(tk
rL}z
|j}W5d}~XYnX|�d�|�|tddg�dS)	Nr�z
import bar�barr�rr�rj�bar.pyr�r�rrr�test_exec_failure_nested�s
z-ImportTracebackTests.test_exec_failure_nestedc
Cs^|�dd�zddl}Wn(tk
r@}z
|j}W5d}~XYnX|�d�|�|tg�dS)Nr�zinvalid syntax is invalidrz#SyntaxError should have been raised)r�r��SyntaxErrorr�rbr�r?r�rrr�test_syntax_error�s
z&ImportTracebackTests.test_syntax_errorc	Cs�d}|�t|�tj�t|�}t�|�tj�|d�}t|d��}|�|�W5QRXtj�|d�}t|d��}|�|�W5QRXt	�
�||fS)N�_parent_foorirMr�)r�rr<r#r�rr�rOrPr*r+)r-�parentZchildZpkg_nameZpkg_path�	init_pathr�bar_pathrrr�_setup_broken_package�s
z*ImportTracebackTests._setup_broken_packagec
Csd|�dd�\}}zddl}Wn(tk
rD}z
|j}W5d}~XYnX|�d�|�|t|g�dS)Nrr�rr��r�Z_parent_foo.barr�r�rbr�r?�r-r�r�r�r�r�rrr�test_broken_submodule�s
z*ImportTracebackTests.test_broken_submodulec
Csh|�dd�\}}zddlm}Wn(tk
rH}z
|j}W5d}~XYnX|�d�|�|t|g�dS)Nrr�r�r�r��r�r�r�r�r�rbr�r?�r-r�r�r�r�r�rrr�test_broken_from�s
z%ImportTracebackTests.test_broken_fromc
Csd|�dd�\}}zddl}Wn(tk
rD}z
|j}W5d}~XYnX|�d�|�|t|g�dS)Nr�rrr�r�r�rrr�test_broken_parent�s
z'ImportTracebackTests.test_broken_parentc
Csh|�dd�\}}zddlm}Wn(tk
rH}z
|j}W5d}~XYnX|�d�|�|t|g�dS)Nr�rrr�r�r�r�rrr�test_broken_parent_from�s
z,ImportTracebackTests.test_broken_parent_fromc
Cs�|�dd�tjd}dt|j�kr.|jj}nd}zfdd�}||j_zddl}Wn(tk
rx}z
|j}W5d}~XYnX|�	d�|�
|td	tg�W5|dkr�|j`n||j_XdS)
Nr�rr��load_modulecWsdddS)Nr~rr)r�rrr�exec_module�sz9ImportTracebackTests.test_import_bug.<locals>.exec_modulerr�z<frozen importlib)r�r r!�vars�SourceLoaderr�r�r�r�rbr�r?)r-r*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)rrrr�rr�)r-Zpynamerrrr�test_unencodable_filename�s�z.ImportTracebackTests.test_unencodable_filenameN)r)r�r�r�r.r/r�r�r�r�r�r�r�r�r�r�r�r�r
r�r�r�rr�rrrrr�Ls$










r�c@sXeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�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!�keysrl)r-�keyrrrr/s
zCircularImportTests.tearDowncCs0zddl}Wntk
r*|�d�YnXdS)Nrz/circular import through relative imports failed)Z,test.test_import.data.circular_imports.basicr8rb�r-r[rrr�test_directszCircularImportTests.test_directcCs0zddl}Wntk
r*|�d�YnXdS)Nrz@relative import in module contributing to circular import failed)Z/test.test_import.data.circular_imports.indirectr8rbr�rrr�
test_indirectsz!CircularImportTests.test_indirectcCs0zddl}Wntk
r*|�d�YnXdS)Nrz-circular import involving a subpackage failed)Z1test.test_import.data.circular_imports.subpackager8rbr�rrr�test_subpackagesz#CircularImportTests.test_subpackagecCsbz"ddlmmmm}Wntk
r@|�d�YnXddlm}|�	|j|j�dS)Nrz9circular import with rebinding of module attribute failed)r�)
Z0test.test_import.data.circular_imports.rebindingrmr�Zcircular_imports�	rebindingr8rbZ-test.test_import.data.circular_imports.subpkgr�r�)r-r�r�rrr�test_rebindings"z"CircularImportTests.test_rebindingcCs0zddl}Wntk
r*|�d�YnXdS)Nrz9circular import with binding a submodule to a name failed)Z.test.test_import.data.circular_imports.bindingr8rbr�rrr�test_binding#sz CircularImportTests.test_bindingcCsddl}ddl}dSr0)Z*test.test_import.data.circular_imports.use�-test.test_import.data.circular_imports.sourcer�rrr�test_crossreference1)sz(CircularImportTests.test_crossreference1c	Cs\|�t��}ddl}W5QRXt|j�}|�d|�|�d|�|�d|�|�d|�dS)Nrz-test.test_import.data.circular_imports.sourcerzpartially initialized modulezcircular import)r1r�r�rAr>rJ)r-rCr[�errmsgrrr�test_crossreference2-s
z(CircularImportTests.test_crossreference2c	Cs4|�t��}ddl}W5QRX|�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))r1r8Z2test.test_import.data.circular_imports.from_cycle1rJrAr>)r-rCr[rrr�test_circular_from_import6s�z-CircularImportTests.test_circular_from_importN)
r�r�r�r�r/r�r�r�r�r�r�r�r�rrrrr��s	r��__main__)Nr)>r*�importlib.utilZimportlib._bootstrap_externalrrPr"r<rtr`r�r�r�r r�r�r�Z
unittest.mockr�r�r��
contextlibr�r�r[rrrrrrr	r
rrr
rrrrZtest.test_importlib.utilrro�dont_write_bytecoder�r�contextmanagerr'ZTestCaser(r�r
r/r7rIrRrpr{r�r�r�r��mainrrrr�<module>sh@�	?SY5E". !1E