HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.7/test/test_import/__pycache__/__init__.cpython-37.pyc
B

��g���@s(ddlZddlZddlmZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlmZddlZddlZddlZddlZddlmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'ddlm(Z(ddl)m*Z*e�+ej,d�Z-dd�Z.ej/d%d
d��Z0Gdd
�d
ej1�Z2e-Gdd�dej1��Z3Gdd�dej1�Z4Gdd�dej1�Z5Gdd�dej1�Z6Gdd�dej1�Z7Gdd�dej1�Z8Gdd�dej1�Z9e$Gdd�dej1��Z:e$Gdd�dej1��Z;Gd d!�d!ej1�Z<Gd"d#�d#ej1�Z=e>d$k�r$e�?�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 bytecodecCs:x,|d|d|d|dfD]}t|�qWtd�dS)Nz.pyz.pycz.pywz	$py.class�__pycache__)rr	)�name�f�r�5/usr/local/lib/python3.7/test/test_import/__init__.py�remove_files#sr�c
cs�|pd}t��t}t�|||�}tj�|d�}z(tj�d|�||fVtj�|�Wd|dk	rj|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@seZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Ze	d
d��Z
dd�Zdd�Zdd�Z
dd�Zdd�Zd;dd�Zdd�Zdd�Zd d!�Zd"d#�Zed$d%��Zd&d'�Zd(d)�Zed*d+��Zd,d-�Ze	d.d/��Zd0d1�Zd2d3�Zd4d5�Ze	d6d7��Zd8d9�Z d:S)<�ImportTestscCstt�t��dS)N)rr�	importlib�invalidate_caches)�selfrrr�setUpCszImportTests.setUpcCstt�dS)N)rr)r*rrr�tearDownGszImportTests.tearDownc	Cs"|�t��ddl}WdQRXdS)Nr)�assertRaises�ModuleNotFoundError�(something_that_should_not_exist_anywhere)r*r/rrr�&test_import_raises_ModuleNotFoundErrorJsz2ImportTests.test_import_raises_ModuleNotFoundErrorc	Cs&|�t��ddlm}WdQRXdS)Nr)�blah)r-r.r/r1)r*r1rrr�:test_from_import_missing_module_raises_ModuleNotFoundErrorNszFImportTests.test_from_import_missing_module_raises_ModuleNotFoundErrorc	Cs&|�t��ddlm}WdQRXdS)Nr)r/)r-�ImportErrorr(r/)r*r/rrr�0test_from_import_missing_attr_raises_ImportErrorRsz<ImportTests.test_from_import_missing_attr_raises_ImportErrorc	CsZ|�t��}ddlm}WdQRX|�|jjd�|�|jjtj�|�	t
|j�d�dS)Nr)�i_dont_exist�osz7cannot import name 'i_dont_exist' from 'os' \(.*os.py\))r-r3r6r5�assertEqual�	exceptionrr"�__file__�assertRegex�str)r*�cmr5rrr�/test_from_import_missing_attr_has_name_and_pathVs
z;ImportTests.test_from_import_missing_attr_has_name_and_pathc	Csbddl}|�t��}ddlm}WdQRX|�|jjd�|�|jj|j�|�	t
|j�d�dS)Nr)r5�	_testcapizCcannot import name 'i_dont_exist' from '_testcapi' \(.*\.(so|pyd)\))r>r-r3r5r7r8rr"r9r:r;)r*r>r<r5rrr�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}WdQRX|�|jjd�|�|jj�dS)Nr)r5�_warning)	r-r3r@r5r7r8rZassertIsNoner")r*r<r5rrr�&test_from_import_missing_attr_has_namefsz2ImportTests.test_from_import_missing_attr_has_namec	CsF|�t��}ddlm}WdQRX|�|jjddh�|�|j�dS)Nr)r5�	posixpathZntpath)r-r3Zos.pathr5�assertInr8r�assertIsNotNone)r*r<r5rrr�/test_from_import_missing_attr_path_is_canonicalmsz;ImportTests.test_from_import_missing_attr_path_is_canonicalc	Cs"|�t��ddl}WdQRXdS)Nr)r-r3�RAnDoM)r*rFrrr�test_case_sensitivityssz!ImportTests.test_case_sensitivitycCsddlm}dS)Nr)�double_const)�testrH)r*rHrrr�test_double_constyszImportTests.test_double_constcsZ�fdd�}tj�dtj�z.|d�tj�d�rHxdD]}||�q8WWdtjd=XdS)Nc
st|}trtd}ntd}t|d��F}td|d|d�t�d�}t�d�}td||d�td	||d�WdQRXttjkr�tjt=t�	�znyt
t�}Wn4tk
r�}z��d
||f�Wdd}~XYnX��
|j|d|���
|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__r3�failr7�a�brr)�extr%ZpycrrRrS�mod�err)r*rr�test_with_extensions4



$


z4ImportTests.test_import.<locals>.test_with_extensionrz.py�win)z.PYz.Pyz.pYz.pywz.PYWz.pYw)rr"r#r6�curdir�platform�
startswith)r*rWrTr)r*r�test_import~s"
zImportTests.test_import�longlistcCs�|d}t|d��6}|�d�xtd�D]}|�d�q(W|�d�WdQRXzt�|�Wdt|�Xtj�d�t	�
�i}zt|�td|d|�Wdtjd	=t|d
�t|d�|�
�ytj|=Wntk
r�YnXXdS)Nz.pyrKzd = [
i�z"",
�]rzimport ����c�o)rM�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_stackc	Cs�td}t|d��}td|d�WdQRXtj�dtj�t�	�ttj
krTtj
t=z4x.dD]&}|�tt
t�|�ttj
d|�q\WWdtjd=tt�XdS)Nz.pyrKza = 1/0)rLr)���z'damaged module in sys.modules on %i try)rrMrNrr"r#r6rYr(r)r r-�ZeroDivisionErrorrP�assertNotInr)r*r%rrlrrr�test_failing_import_sticks�s


z&ImportTests.test_failing_import_stickscCsTddl}ddl}|�|||j�|�t|jd��ddlm}|�||j|j�dS)Nrr9)rI�test.support�assertIs�__name__�
assertTrue�hasattr�support)r*�xrI�yrrr�test_import_name_binding�sz$ImportTests.test_import_name_bindingcCsrzd}Wdddlmm}Xd}x&|dkrHddlmm}|d7}q$Wx"td�D]}ddlmm}qTWdS)N.r�
rorp)Ztest.support.script_helperrzrrc)r*r{rlrrr�test_issue31286�s
zImportTests.test_issue31286c	Csttjd}t|d��}|�d�WdQRXtj�dtj�z�t	t�}|�
ttj�|�|j
dd�|�|jdd�tt�t|d��}|�d�WdQRX|�ttj|�tj�t�}|�|d	�|�|j
d
d�|�|jdd�Wdtjd=tt�tt�XdS)N�pyrKz
a = 1
b=2
rroz!module has wrong attribute valuesrpza = 10
b=20//0
z$expected module to be in sys.modulesr~)rr6�extseprMrbrr"r#rYrPrCr r7rRrSrr-rrr(�reload�getrDr)r*r%rrUrrr�test_failing_reloads(zImportTests.test_failing_reloadc	Cs�td}t|d��}|�d�WdQRXtj�dtj�zftt�}|�	|j
�d��t�|�tj
t=t|�t��tt�}tj�|j
�\}}|�|d�Wdtjd=tt�ttj
kr�tj
t=XdS)Nz.pyrKztest = None
rz.pyc)rrMrbrr"r#r6rYrPrxr9�endswithr$r rr(r)�splitextr7r)r*r%rrU�baserTrrr�test_file_to_source(s$

zImportTests.test_file_to_sourcec	Csjtj�t�}t��}y|�|�Wn$tk
rF|�d�	|��YnX|�
t��}t|�WdQRXdS)Nzpath is not encodable to {})
r6r"�abspathrr�getfilesystemencoding�encode�UnicodeEncodeError�skipTest�formatr-r3rP)r*r"�encodingr`rrr�test_import_by_filename@s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_crashJsz-ImportTests.test_import_in_del_does_not_crashc
Cs�tj�dtj�z�td}tj�|�}t	|d��}WdQRXyt�
|d�Wnntk
rj|�d�YnRt
k
r�}z4|jttdd�ttdd�fkr��|�d�|��Wdd}~XYnXtt�t�|�Wdtjd=tt�XdS)	Nrz.pyrK)l��l��z-cannot set modification time to large integerZ	EOVERFLOWZEINVALz2cannot set modification time to large integer ({}))rr"r#r6rYrr(�util�cache_from_sourcerM�utime�
OverflowErrorr��OSError�errno�getattrr�rP�statr)r*r%Zcompiledr�errr�test_timestamp_overflowUs&
"z#ImportTests.test_timestamp_overflowcCs6ytddgd�Wntk
r0|�d�YnXdS)NZhttpr1)�fromlistzfromlist must allow bogus names)rPr3rQ)r*rrr�test_bogus_fromlistoszImportTests.test_bogus_fromlistcCs.ddg}tj|�}|��\}}|�d|�dS)Nz-cz&del __builtins__.__import__; import ossImportError)rZspawn_pythonZcommunicaterC)r*�args�popen�stdout�stderrrrr�test_delete_builtins_importus
z'ImportTests.test_delete_builtins_importc	Cs(|�td��ddlm}WdQRXdS)Nz^No module named 'bogus'r)�foo)�assertRaisesRegexr3�bogusr�)r*r�rrr�/test_from_import_message_for_nonexistent_module|sz;ImportTests.test_from_import_message_for_nonexistent_modulec	Cs(|�td��ddlm}WdQRXdS)Nz^cannot import name 'bogus'r)r�)r�r3�rer�)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}WdQRX|�t	|j
�d�dS)Nc@seZdZdd�ZdS)zIImportTests.test_from_import_AttributeError.<locals>.AlwaysAttributeErrorcSst�dS)N)�AttributeError)r*�_rrr�__getattr__�szUImportTests.test_from_import_AttributeError.<locals>.AlwaysAttributeError.__getattr__N)rw�
__module__�__qualname__r�rrrr�AlwaysAttributeError�sr��test_from_import_AttributeErrorr)�does_not_existzScannot import name 'does_not_exist' from '<unknown module name>' (unknown location))�
addCleanuprrr r-r3r�r�r7r;r8)r*r��module_namer<r�rrrr��sz+ImportTests.test_from_import_AttributeErrorc
CsZttdd��D|�t��ddlm}WdQRX|�t��tjWdQRXWdQRXdS)Nrwr)r�)rr6r-r3r�r�)r*r�rrr�test_issue31492�s
zImportTests.test_issue31492cs�tj�dtj�tj�t�d��z�d���fdd��x�td�D]x}t�	���fdd�td�D�}z*t
j�|�j
��t�d�WdQRXWdtj�d	d�tj�d
d�X�dk	r>��q>WWdtjd=XdS)Nr�datac
s@���yddl}Wn&tk
r:}z|�Wdd}~XYnXdS)Nr)�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>rpr�zpackage.submodule)rr"r#r6�join�dirnamer9rcr�ZEventrIrzZ
start_threads�set�timeZsleepr r!)r*rlZthreadsr)r�r�r�r�test_concurrency�s zImportTests.test_concurrencyN)r])!rwr�r�r+r,r0r2r4r=rr?rArErGrJr\rnrtr}rr��skip_if_dont_write_bytecoder�r�r�r�r�r�r�r�r�r�r�rrrrr'As8	,
(&
r'c@sbeZdZe�ejdkd�dd��Ze�ejdkd�dd��Ze�ejdkd�dd��Z	d	d
�Z
dS)�FilePermissionTests�posixz%test meaningful only on posix systemsc
Cs�d}t|��Pt��>\}}tj�|�}t|�}tj�|�sD|�	d�t�
|�}WdQRXWdQRX|�tt
�
|j��td|@��dS)N�z4__import__ did not result in creation of a .pyc filei�)r
r&r(r�r�rPr6r"�existsrQr�r7�oct�S_IMODE�st_mode)r*�maskrr"�cached_pathrj�	stat_inforrr�test_creation_mode�s
z&FilePermissionTests.test_creation_modec
Cs�d}td��\t��J\}}tj�|�}t�||�t|�tj�	|�sP|�
d�t�|�}WdQRXWdQRX|�t
t�|j��t
|��dS)Ni�r�z4__import__ did not result in creation of a .pyc file)r
r&r(r�r�r6�chmodrPr"r�rQr�r7r�r�r�)r*�moderr"r�r�rrr�test_cached_mode_issue_2051�s
z/FilePermissionTests.test_cached_mode_issue_2051c
Cs�d}td��\t��J\}}tj�|�}t�||�t|�tj�	|�sP|�
d�t�|�}WdQRXWdQRX|dB}|�t
t�|j��t
|��dS)N�r�z4__import__ did not result in creation of a .pyc file�)r
r&r(r�r�r6r�rPr"r�rQr�r7r�r�r�)r*r�rr"r�r�Zexpectedrrr�test_cached_readonly�s
z(FilePermissionTests.test_cached_readonlyc
Cst���
\}}t|d��}|�d�WdQRXt�|�}t�||j|jdf�t�|d�t	|�}|�
|jd�t�|d�t|d��}|�d�WdQRXt|�t
��t	|�}|�
|jd�t|�t|�t
��|d	}t�t
j�|�|�t	|�}|�
|jd�WdQRXdS)
NrKzx = 'original'
i�r�Zoriginali�zx = 'rewritten'
Z	rewrittenr`)r&rMrbr6r�r��st_atime�st_mtimer�rPr7r{rr(r)r�renamer�r�)r*rr"r�s�mZ
bytecode_onlyrrr�test_pyc_always_writable�s,
z,FilePermissionTests.test_pyc_always_writableN)rwr�r��unittest�
skipUnlessr6rr�r�r�r�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
�WdQRXtj�d|j	�t��dS)NrKr)rr"�sys_pathr r!r��orig_moduler6�mkdir�dir_namerM�	file_namerb�
module_sourcer#r(r))r*rrrrr+"szPycRewritingTests.setUpcCsV|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)�globalsrPr�rr )r*�nsrrr�
import_module5szPycRewritingTests.import_modulecCs~|��}|�|j|j�|�|j|j�|�|j|j�tj|j=|��}|�|j|j�|�|j|j�|�|j|j�dS)N)	r�r7�module_filenamer��
code_filename�
func_filenamerr r�)r*rUrrr�test_basics:s
zPycRewritingTests.test_basicscCsLtj|jdd�|��}|�|j|j�|�|j|j�|�|j|j�dS)Nzanother_module.py)�dfile)rdrer�r�r7r�r�r�)r*rUrrr�test_incorrect_code_nameEs
z*PycRewritingTests.test_incorrect_code_namecCshd}tj|j|d�t�|j�t|j�}t��|��}|�	|j
|�|�	|j|�|�	|j|�dS)Nzanother_module.py)r�)
rdrer�r6r$rr(r)r�r7r�r�r�)r*r��pyc_filerUrrr�test_module_without_sourceLs
z,PycRewritingTests.test_module_without_sourcecCs�t�|j�t|jd��}|�d�}t�|�}WdQRXt|j	�}t
jj}|�
d�}|||<t|�|j|j|j|j|j|jt|�|j|j|j|j|j|j|j|j�}t|jd��}|�|�t�||�WdQRX|��}|� |j!j|j�dS)N�rb�ro�wb)"rdrer�rMr��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_cellvarsrb�dumpr7Zconstant)r*r�header�codeZ	constantsZforeign_code�posrUrrr�test_foreign_codeWs&



z#PycRewritingTests.test_foreign_codeN)rwr�r�r�r�r6r"r�rr�r�r�r�r(r�r�r�r+r,r�r�r�r�rrrrrr�s		
r�c@sFeZdZdZeZdd�Zdd�Zdd�Ze	�
ejdkd	�d
d��Z
dS)
�
PathsTests)rIutestäöüßutestéèu
test°³²cCs t�|j�tjdd�|_dS)N)r6r�r"r�syspath)r*rrrr+rszPathsTests.setUpcCst|j�|jtjdd�<dS)N)r	r"rr)r*rrrr,vs
zPathsTests.tearDownc	Cs`ttj�|jd�d��}|�d�WdQRXtj�|jd�td�}|�|j	d�t
d�dS)Nztest_trailing_slash.pyrKz testdata = 'test_trailing_slash'�/�test_trailing_slash)rMr6r"r�rbrrfrPr7�testdatar)r*rrUrrrr{szPathsTests.test_trailing_slash�win32zWindows-specificc	
CsRttj�|jd�d��}|�d�WdQRXt��tj�|j�}ddl}|�	�}|d}d||f}||dd�7}yt�
|�WnJtk
r�}z,|jtj
tjtjfkr�|�d|f��Wdd}~XYnXtj�d|�ytd�}Wn6tk
�r }z|�d	||f�Wdd}~XYnX|�|jd�|�|j�|�|j�td�dS)
Nztest_unc_path.pyrKztestdata = 'test_unc_path'rz\\%s\%s$rpz%cannot access administrative share %rZ
test_unc_pathz,could not import 'test_unc_path' from %r: %r)rMr6r"r�rbr(r)r��socketZgethostname�listdirr�r�ZEPERMZEACCES�ENOENTr�rr#rPr3rQr7rrxr9r[r)	r*rr"rZhnZdriveZuncr�rUrrr�
test_UNC_path�s0zPathsTests.test_UNC_pathN)rwr�r�ZSAMPLESrr"r+r,rr�r�rrZrrrrrrms	rc@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)Nrp)�	relimportr)rrrxry)r*rrrr�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)rgr)r�rr�check_relative�sz:RelativeImportTests.test_issue3221.<locals>.check_relativerIztest.notarealmodule)�__package__rwznotarealpkg.notarealmoduler�)r!)�dictr-r.�object�	TypeError)r*r r)r�r�test_issue3221�sz"RelativeImportTests.test_issue3221cCst�dddd�dS)Nz-W�ignorez-czfoo = 1; from . import foo)rZassert_python_failure)r*rrr�)test_parentless_import_shadowed_by_global�s
z=RelativeImportTests.test_parentless_import_shadowed_by_globalc	Cs0|�t��ddlm}|�d�WdQRXdS)Nro)�sepz>explicit relative import triggered an implicit absolute import)r-r3r6r(rQ)r*r(rrr�#test_absolute_import_without_future�sz7RelativeImportTests.test_absolute_import_without_futurecCs�tj�tj�t�dd�}tdd��Tt|��@|�t��ddl	}WdQRX|�
dtj�|�
dtj�WdQRXWdQRXdS)Nr��package2�
submodule1�
submodule2r)
r6r"r�r�r9rrr-r3r+rsrr )r*r"r+rrr�test_import_from_non_package�sz0RelativeImportTests.test_import_from_non_packagec
CsRtddd��<ttj�tj�t�d���ddl}|jj	WdQRXWdQRXdS)Nr*zpackage2.submodule1zpackage2.submodule2r�r)
rrr6r"r�r�r9Zpackage2.submodule1r+r,)r*r*rrr�!test_import_from_unloaded_package�sz5RelativeImportTests.test_import_from_unloaded_packageN)rwr�r�r,r+rr%r'r)r-r.rrrrr�s	rc@seZdZdd�ZdS)�OverridingImportBuiltinTestsc	Csxddl}dd�}|�|�|�ttddd���|�|�d�WdQRXtt�ddd���|�|�|�WdQRXdS)	NrcSsddl}|S)Nr)r6)r6rrrr��sz?OverridingImportBuiltinTests.test_override_builtin.<locals>.foorPcWsdS)N�r)r{rrr�<lambda>��zDOverridingImportBuiltinTests.test_override_builtin.<locals>.<lambda>r0cWsdS)Nr0r)r{rrrr1�r2)r6r7r�builtinsrr�)r*r6r�rrr�test_override_builtin�sz2OverridingImportBuiltinTests.test_override_builtinN)rwr�r�r4rrrrr/�sr/c@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)rrr	rr%)r*rrr�_clean�szPycacheTests._cleanc	CsRtd|_|��t|jd��}td|d�WdQRXtj�dtj	�t
��dS)Nz.pyrKz/# This is a test file written by test_import.py)rLr)rr%r6rMrNrr"r#r6rYr(r))r*�fprrrr+s
zPycacheTests.setUpcCs,tjdtjkstd��tjd=|��dS)NrzUnexpected sys.path[0])rr"r6rY�AssertionErrorr6)r*rrrr,szPycacheTests.tearDowncCsZ|�tj�d��tt�|�tj�d��tj�	|j
�}|�tj�|�d�|t��dS)Nrz*bytecode file {!r} for {!r} does not exist)�assertFalser6r"r�rPrrxr(r�r�r%r�)r*�pyc_pathrrr�test_import_pyc_pathsz!PycacheTests.test_import_pyc_pathr�z%test meaningful only on posix systems�geteuidrz=due to varying filesystem permission semantics (issue #11956)c	Cs\td��tt�WdQRX|�tj�d��tj�	|j
�}|�tj�|�d�|t��dS)N�rz"bytecode file {!r} for {!r} exists)
r
rPrrxr6r"r�r(r�r�r%r9r�)r*r:rrr�test_unwritable_directorys
z&PycacheTests.test_unwritable_directorycCsVtt�tj�|j�}|�tj�	|��t�
|j�tt�t��|�
ttt�dS)N)rPrr(r�r�r%rxr6r"r�r$rr)r-r3)r*r�rrr�test_missing_source*sz PycacheTests.test_missing_sourcec	Csntt�t|j�}t�|j�tt�t��tt�}z&|�	|j
tj�tj
tj�|���Wdt�|�XdS)N)rPrrr%r6r$rr(r)r7r9r"r�rY�relpath)r*r�r�rrr�test_missing_source_legacy6s
z'PycacheTests.test_missing_source_legacycCs6tt�}tj�td�}|�|jtj�	tj
|��dS)Nz.py)rPrr(r�r�r7�
__cached__r6r"r�rY)r*r�r�rrr�test___cached__IszPycacheTests.test___cached__c	Cs\tt�t|j�}t�|j�tt�t��tt�}|�	|j
tj�tj
tj�|���dS)N)rPrrr%r6r$rr(r)r7rBr"r�rYr@)r*r�r�rrr�test___cached___legacy_pycOs
z'PycacheTests.test___cached___legacy_pycc	Cs�dd�}t�d�|�|�ttj�dd�d��WdQRXttj�dd�d��WdQRXt��td�}tj	�
tj�dd��}|�|jtj�tj
|��tj	�
tj�dd��}|�tjdjtj�tj
|��dS)NcSstd�td�td�dS)N�pep3147zpep3147.foo)r	rrrrr�cleanupbsz5PycacheTests.test_package___cached__.<locals>.cleanuprEz__init__.pyrKzfoo.pyzpep3147.foo)r6r�r�rMr"r�r(r)rPr�r�r7rBrYrr )r*rFr��init_pyc�foo_pycrrr�test_package___cached___s



z$PycacheTests.test_package___cached__c	Cs�dd�}t�d�|�|�ttj�dd�d��WdQRXttj�dd�d��WdQRXt��td�}t	d�t	d�t��td�}tj
�tj�dd��}|�|j
tj�tj|��tj
�tj�dd��}|�tjdj
tj�tj|��dS)NcSstd�td�td�dS)NrEzpep3147.foo)r	rrrrrrFysz>PycacheTests.test_package___cached___from_pyc.<locals>.cleanuprEz__init__.pyrKzfoo.pyzpep3147.foo)r6r�r�rMr"r�r(r)rPrr�r�r7rBrYrr )r*rFr�rGrHrrr� test_package___cached___from_pycvs&



z-PycacheTests.test_package___cached___from_pycc	CsNtt�tt�t|jd��}td|d�WdQRXtt�}|�|jd�dS)NrRzx = 5)rLr0)rPrrrMr%rNr7r{)r*r7r�rrr�test_recompute_pyc_same_second�sz+PycacheTests.test_recompute_pyc_same_secondN)rwr�r�r6r+r,r�r;r�r�r6r�skipIfryr<r>r?rArCrDrIrJrKrrrrr5�s 
r5c@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)Nz__init__.pyT)Ztarget_is_directory)rIrzr	�tagged�package_namerr"�
orig_sys_pathr6r�r�r�rr�r8�symlinkrr(r)r7�isdir�isfile)r*Z	init_filerrrr+�sz#TestSymbolicallyLinkedPackage.setUpcCs|jtjdd�<dS)N)rPrr")r*rrrr,�sz&TestSymbolicallyLinkedPackage.tearDown�getwindowsversion)�rzWindows Vista or later requiredcCsNdgtjdd�<tj�|j�s"t�tj�tj�|jd��s>t�t�|j�dS)N�.z__init__.py)	rr"r6r�rOr8r�r(r�)r*rrr�test_symlinked_dir_importable�sz;TestSymbolicallyLinkedPackage.test_symlinked_dir_importableN)rwr�r�rOrNr+r,r�r�ryrrTrIrzZskip_unless_symlinkrWrrrrrM�s
rMc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ImportlibBootstrapTestscCstjd}|�|�dS)N�_frozen_importlib)rr rx)r*rUrrr�test_frozen_importlib�s
z-ImportlibBootstrapTests.test_frozen_importlibcCsXddlm}tjd}|�||�|�|jd�|�|jd�|�|j	�
d�|j	�dS)Nr)�
_bootstraprYzimportlib._bootstrapr(z
_bootstrap.py)r(r[rr rvr7rwr!rxr9r�)r*r[rUrrr�"test_frozen_importlib_is_bootstrap�s
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]rr rvr7rwr!rxr9r�)r*r]rUrrr�4test_frozen_importlib_external_is_bootstrap_external�s
zLImportlibBootstrapTests.test_frozen_importlib_external_is_bootstrap_externalcCs*ddlm}tjd}|�|j|j�dS)Nr)�	machineryrY)r(r`rr rv�
ModuleSpec)r*r`rUrrr�test_there_can_be_only_one�s
z2ImportlibBootstrapTests.test_there_can_be_only_oneN)rwr�r�rZr\r_rbrrrrrX�srXc@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|�|�WdQRXdS)Nz*importlib._bootstrap_external._path_isfileTz.pycz.py)�mock�patch�return_valuerr7r)r*�_path_isfiler"�expectrrr�test_get_sourcefile�s
z&GetSourcefileTests.test_get_sourcefilec	Cs8t�d��$}d|_td}|�t|�|�WdQRXdS)Nz*importlib._bootstrap_external._path_isfileFz.pyc)rdrerfrr7r)r*rgr"rrr�test_get_sourcefile_no_source�sz0GetSourcefileTests.test_get_sourcefile_no_sourcecCstd}|�t|�|�dS)Nz.bad_ext)rr7r)r*r"rrr�test_get_sourcefile_bad_extsz.GetSourcefileTests.test_get_sourcefile_bad_extN)rwr�r��__doc__rirjrkrrrrrc�s	rcc@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�dS)Nr)r6r�rrr"�old_pathr#)r*rrrr+s
zImportTracebackTests.setUpcCs|jtjdd�<tt�dS)N)rnrr"r	r)r*rrrr,szImportTracebackTests.tearDown�.pyc	CsJtj�t||�}t|d��}|�|�WdQRX|�t|�t�	�|S)NrK)
r6r"r�rrMrbr�rr(r))r*rU�contentsrTZfnamerrrr�
create_modulesz"ImportTracebackTests.create_modulecCszg}x6|r:|jj}|j}|r(||dkr2|�|�|j}qW|�t|�t|�|�x"t||�D]\}}|�||�q^WdS)Nr_)	�tb_frame�f_coderrf�tb_nextr7�len�ziprC)r*�tb�filesZ
deduped_filesr�fnZpatrrr�assert_traceback s

z%ImportTracebackTests.assert_tracebackc
CsRyddl}Wn(tk
r4}z
|j}Wdd}~XYnX|�d�|�|tg�dS)Nrz#ImportError should have been raised)�nonexistent_xyzzyr3�
__traceback__rQrzr9)r*r{r�rwrrr�test_nonexistent_module,s
z,ImportTracebackTests.test_nonexistent_modulec
Cs`|�dd�yddl}Wn(tk
r@}z
|j}Wdd}~XYnX|�d�|�|tdg�dS)Nr�zimport nonexistent_xyzzyrz#ImportError should have been raisedzfoo.py)rqr�r3r|rQrzr9)r*r�r�rwrrr�test_nonexistent_module_nested6s
z3ImportTracebackTests.test_nonexistent_module_nestedc
Cs`|�dd�yddl}Wn(tk
r@}z
|j}Wdd}~XYnX|�d�|�|tdg�dS)Nr�z1/0rz)ZeroDivisionError should have been raisedzfoo.py)rqr�rrr|rQrzr9)r*r�r�rwrrr�test_exec_failure@s
z&ImportTracebackTests.test_exec_failurec
Csn|�dd�|�dd�yddl}Wn(tk
rL}z
|j}Wdd}~XYnX|�d�|�|tddg�dS)	Nr�z
import bar�barz1/0rz)ZeroDivisionError should have been raisedzfoo.pyzbar.py)rqr�rrr|rQrzr9)r*r�r�rwrrr�test_exec_failure_nestedJs
z-ImportTracebackTests.test_exec_failure_nestedc
Cs^|�dd�yddl}Wn(tk
r@}z
|j}Wdd}~XYnX|�d�|�|tg�dS)Nr�zinvalid syntax is invalidrz#SyntaxError should have been raised)rqr��SyntaxErrorr|rQrzr9)r*r�r�rwrrr�test_syntax_errorVs
z&ImportTracebackTests.test_syntax_errorc	Cs�d}|�t|�tj�t|�}t�|�tj�|d�}t|d��}|�|�WdQRXtj�|d�}t|d��}|�|�WdQRXt	�
�||fS)N�_parent_fooz__init__.pyrKzbar.py)r�rr6r"r�rr�rMrbr(r))r*�parentZchildZpkg_nameZpkg_path�	init_pathr�bar_pathrrr�_setup_broken_package`s
z*ImportTracebackTests._setup_broken_packagec
Csd|�dd�\}}yddl}Wn(tk
rD}z
|j}Wdd}~XYnX|�d�|�|t|g�dS)Nrz1/0rz)ZeroDivisionError should have been raised)r��_parent_foo.barrrr|rQrzr9)r*r�r�r�r�rwrrr�test_broken_submoduleos
z*ImportTracebackTests.test_broken_submodulec
Csh|�dd�\}}yddlm}Wn(tk
rH}z
|j}Wdd}~XYnX|�d�|�|t|g�dS)Nrz1/0r)r�z#ImportError should have been raised)r�r�r�rrr|rQrzr9)r*r�r�r�r�rwrrr�test_broken_fromys
z%ImportTracebackTests.test_broken_fromc
Csd|�dd�\}}yddl}Wn(tk
rD}z
|j}Wdd}~XYnX|�d�|�|t|g�dS)Nz1/0rrz)ZeroDivisionError should have been raised)r�r�rrr|rQrzr9)r*r�r�r�r�rwrrr�test_broken_parent�s
z'ImportTracebackTests.test_broken_parentc
Csh|�dd�\}}yddlm}Wn(tk
rH}z
|j}Wdd}~XYnX|�d�|�|t|g�dS)Nz1/0rr)r�z)ZeroDivisionError should have been raised)r�r�r�rrr|rQrzr9)r*r�r�r�r�rwrrr�test_broken_parent_from�s
z,ImportTracebackTests.test_broken_parent_fromc
Cs�|�dd�tjd}dt|j�kr.|jj}nd}zfdd�}||j_yddl}Wn(tk
rx}z
|j}Wdd}~XYnX|�	d�|�
|td	tg�Wd|dkr�|j`n||j_XdS)
Nr�rr^�load_modulecWsdddS)Nrorr)r�rrr�exec_module�sz9ImportTracebackTests.test_import_bug.<locals>.exec_modulerz)ZeroDivisionError should have been raisedz<frozen importlib)rqrr �vars�SourceLoaderr�r�rrr|rQrzr9)r*r(Zold_exec_moduler�r�r�rwrrr�test_import_bug�s"


z$ImportTracebackTests.test_import_bugzneed TESTFN_UNENCODABLEcCs>t�dtd�}|�t|�|dd�}tjdd|dd�dS)Nr�pass���z-czmod = __import__(%a)F)Z
__isolated)rrrr�rr�)r*Zpynamerrrr�test_unencodable_filename�s
z.ImportTracebackTests.test_unencodable_filenameN)ro)rwr�r�r+r,rqrzr}r~rr�r�r�r�r�r�r�rr�r�r�rr�rrrrrm
s 








rmc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�CircularImportTestszQSee the docstrings of the modules being imported for the purpose of the
    test.cCs.x(ttj���D]}|�d�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 �keysr[)r*�keyrrrr,�s
zCircularImportTests.tearDowncCs0yddl}Wntk
r*|�d�YnXdS)Nrz/circular import through relative imports failed)Z,test.test_import.data.circular_imports.basicr3rQ)r*rIrrr�test_direct�szCircularImportTests.test_directcCs0yddl}Wntk
r*|�d�YnXdS)Nrz@relative import in module contributing to circular import failed)Z/test.test_import.data.circular_imports.indirectr3rQ)r*rIrrr�
test_indirect�sz!CircularImportTests.test_indirectcCs0yddl}Wntk
r*|�d�YnXdS)Nrz-circular import involving a subpackage failed)Z1test.test_import.data.circular_imports.subpackager3rQ)r*rIrrr�test_subpackage�sz#CircularImportTests.test_subpackagecCsby"ddlmmmm}Wntk
r@|�d�YnXddlm}|�	|j|j�dS)Nrz9circular import with rebinding of module attribute failed)r�)
Z0test.test_import.data.circular_imports.rebindingr\r�Zcircular_imports�	rebindingr3rQZ-test.test_import.data.circular_imports.subpkgr�rv)r*r�r�rrr�test_rebinding�s"z"CircularImportTests.test_rebindingcCs0yddl}Wntk
r*|�d�YnXdS)Nrz9circular import with binding a submodule to a name failed)Z.test.test_import.data.circular_imports.bindingr3rQ)r*rIrrr�test_binding�sz CircularImportTests.test_bindingN)
rwr�r�rlr,r�r�r�r�r�rrrrr��sr��__main__)Nr)@r(�importlib.utilZimportlib._bootstrap_externalrr3r�r6rZrdrOr�rr�r�r�Z
unittest.mockrdr�r��
contextlibrurIrrrrrrr	r
rrr
rrrrrrrrZtest.test_importlib.utilrrL�dont_write_bytecoder�r�contextmanagerr&ZTestCaser'r�r�rrr/r5rMrXrcrmr�rw�mainrrrr�<module>s`P	|
S^5E".
 
!1.