Your IP : 216.73.216.213


Current Path : /opt/alt/python36/lib64/python3.6/test/test_import/__pycache__/
Upload File :
Current File : //opt/alt/python36/lib64/python3.6/test/test_import/__pycache__/__init__.cpython-36.pyc

3

� f̱�@s.ddlZddlZddlmZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddljZddlZddlZddlZddlZddlZddlmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(ddlm)Z)ddl*m+Z+ej,ej-d�Z.dd�Z/ej0d%d
d��Z1Gdd
�d
ej2�Z3e.Gdd�dej2��Z4Gdd�dej2�Z5Gdd�dej2�Z6Gdd�dej2�Z7Gdd�dej2�Z8Gdd�dej2�Z9Gdd�dej2�Z:e%Gdd�dej2��Z;e%Gdd�dej2��Z<Gd d!�d!ej2�Z=Gd"d#�d#ej2�Z>e?d$k�r*ej@�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�>/opt/alt/python36/lib64/python3.6/test/test_import/__init__.py�remove_files$sr�ccs�|pd}t��t}tj|||�}tjj|d�}z(tjjd|�||fVtjj|�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@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
d1dd�Zdd�Zdd�Z
dd�Zedd��Zdd�Zdd�Zed d!��Zd"d#�Zed$d%��Zd&d'�Zd(d)�Zd*d+�Zed,d-��Zd.d/�Zd0S)2�ImportTestscCstt�tj�dS)N)rr�	importlib�invalidate_caches)�selfrrr�setUpDszImportTests.setUpcCstt�dS)N)rr)r*rrr�tearDownHszImportTests.tearDownc	Cs"|jt��ddl}WdQRXdS)Nr)�assertRaises�ModuleNotFoundError�(something_that_should_not_exist_anywhere)r*r/rrr�&test_import_raises_ModuleNotFoundErrorKsz2ImportTests.test_import_raises_ModuleNotFoundErrorc	Cs&|jt��ddlm}WdQRXdS)Nr)�blah)r-r.r/r1)r*r1rrr�:test_from_import_missing_module_raises_ModuleNotFoundErrorOszFImportTests.test_from_import_missing_module_raises_ModuleNotFoundErrorc	Cs&|jt��ddlm}WdQRXdS)Nr)r/)r-�ImportErrorr(r/)r*r/rrr�0test_from_import_missing_attr_raises_ImportErrorSsz<ImportTests.test_from_import_missing_attr_raises_ImportErrorc	Cs"|jt��ddl}WdQRXdS)Nr)r-r3�RAnDoM)r*r5rrr�test_case_sensitivityWsz!ImportTests.test_case_sensitivitycCsddlm}dS)Nr)�double_const)�testr7)r*r7rrr�test_double_const]szImportTests.test_double_constcsZ�fdd�}tjjdtj�z.|d�tjjd�rHxdD]}||�q8WWdtjd=XdS)
Nc st|}trtd}ntd}t|d��F}td|d|d�tjd�}tjd�}td||d�td	||d�WdQRXttjkr�tjt=tj	�znyt
t�}Wn4tk
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__r3�fail�assertEqual�a�brr)�extr%ZpycrrBrC�mod�err)r*rr�test_with_extensioncs4



$


z4ImportTests.test_import.<locals>.test_with_extensionrz.py�win�.PY�.Py�.pY�.pyw�.PYW�.pYw)rIrJrKrLrMrN)rr"r#�os�curdir�platform�
startswith)r*rGrDr)r*r�test_importbs"
zImportTests.test_import�longlistc#Cs�|d}t|d��6}|jd�xtd�D]}|jd�q(W|jd�WdQRXztj|�Wdt|�Xtjjd�t	j
�i}zt|�td|d|�Wdtjd=t|d
�t|d�|j
�ytj|=Wntk
r�YnXXdS)
Nz.pyr:zd = [
i�z"",
�]rzimport ��c�o���)r<�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��}td|d�WdQRXtjjdtj�tj	�ttj
krTtj
t=z4x.d
D]&}|jtt
t�|jttj
d	|�q\WWdtjd=tt�XdS)Nz.pyr:za = 1/0)r;rrV��z'damaged module in sys.modules on %i try)rVrgrh)rr<r=rr"r#rOrPr(r)r r-�ZeroDivisionErrorr?�assertNotInr)r*r%rrdrrr�test_failing_import_sticks�s


z&ImportTests.test_failing_import_stickscCsRddl}ddl}|j|||j�|jt|jd��ddlj}|j||j|j�dS)Nr�__file__)r8�test.support�assertIs�__name__�
assertTrue�hasattr�support)r*�xr8�yrrr�test_import_name_binding�s
z$ImportTests.test_import_name_bindingcCsttjd}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�pyr:z
a = 1
b=2
rrVz!module has wrong attribute valuesrgza = 10
b=20//0
z$expected module to be in sys.modules�
)rrO�extsepr<rZrr"r#rPr?�assertInr rArBrCrr-rir(�reload�getZassertIsNotNoner)r*r%rrErrr�test_failing_reload�s(zImportTests.test_failing_reloadcCs�td}t|d��}|jd�WdQRXtjjdtj�zftt�}|j	|j
jd��tj|�tj
t=t|�tj�tt�}tjj|j
�\}}|j|d�Wdtjd=tt�ttj
kr�tj
t=XdS)Nz.pyr:ztest = None
rz.pyc)rr<rZrr"r#rOrPr?rprl�endswithr$r rr(r)�splitextrAr)r*r%rrE�baserDrrr�test_file_to_source�s$

zImportTests.test_file_to_sourcecCsjtjjt�}tj�}y|j|�Wn$tk
rF|jdj	|��YnX|j
t��}t|�WdQRXdS)Nzpath is not encodable to {})
rOr"�abspathrr�getfilesystemencoding�encode�UnicodeEncodeError�skipTest�formatr-r3r?)r*r"�encodingrWrrr�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�Wnntk
rj|jd�YnRt
k
r�}z6|jttdd�ttd	d�fkr��|jd
j|��WYdd}~XnXtt�tj|�Wdtjd=tt�XdS)Nrz.pyr:rg�!�z-cannot set modification time to large integerZ	EOVERFLOWZEINVALz2cannot set modification time to large integer ({})l���l���)r�r�)rr"r#rOrPrr(�util�cache_from_sourcer<�utime�
OverflowErrorr��OSError�errno�getattrr�r?�statr)r*r%Zcompiledr�errr�test_timestamp_overflow(s&
"z#ImportTests.test_timestamp_overflowcCs6ytddgd�Wntk
r0|jd�YnXdS)NZhttpr1)�fromlistzfromlist must allow bogus names)r?r3r@)r*rrr�test_bogus_fromlistBszImportTests.test_bogus_fromlistcCs.ddg}tj|�}|j�\}}|jd|�dS)Nz-cz&del __builtins__.__import__; import ossImportError)rZspawn_pythonZcommunicatery)r*�args�popen�stdout�stderrrrr�test_delete_builtins_importHs
z'ImportTests.test_delete_builtins_importc	Cs(|jtd��ddlm}WdQRXdS)Nz^No module named 'bogus'r)�foo)�assertRaisesRegexr3�bogusr�)r*r�rrr�/test_from_import_message_for_nonexistent_moduleOsz;ImportTests.test_from_import_message_for_nonexistent_modulec	Cs(|jtd��ddlm}WdQRXdS)Nz^cannot import name 'bogus'r)r�)r�r3�rer�)r*r�rrr�,test_from_import_message_for_existing_moduleSsz8ImportTests.test_from_import_message_for_existing_modulec	CsPGdd�d�}d}|jt|�|�tj|<|jt��ddlm}WdQRXdS)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)ro�
__module__�__qualname__r�rrrr�AlwaysAttributeErrorZsr��test_from_import_AttributeErrorr)�does_not_exist)�
addCleanuprrr r-r3r�r�)r*r��module_namer�rrrr�Wsz+ImportTests.test_from_import_AttributeErrorcCsZttdd��D|jt��ddlm}WdQRX|jt��tjWdQRXWdQRXdS)Nror)r�)rrOr-r3r�r�)r*r�rrr�test_issue31492ds
zImportTests.test_issue31492cs�tjjdtjjtjjt�d��z�d���fdd��x�td�D]x}tj	���fdd�td�D�}z*t
jj|�j
��tjd�WdQRXWdtjjd	d�tjjd
d�X�dk	r>��q>WWdtjd=XdS)Nr�datacs@�j�yddl}Wn&tk
r:}z
|�WYdd}~XnXdS)Nr)�wait�package�
BaseException)r�r�)�event�excrr�runts
z)ImportTests.test_concurrency.<locals>.runrwcsg|]}tj�d��qS))�target)�	threadingZThread)�.0rs)r�rr�
<listcomp>~sz0ImportTests.test_concurrency.<locals>.<listcomp>rgr�zpackage.submodule)rr"r#rO�join�dirnamerlr[r�ZEventr8rrZ
start_threads�set�timeZsleepr r!)r*rdZthreadsr)r�r�r�r�test_concurrencyps zImportTests.test_concurrencyN)rT)ror�r�r+r,r0r2r4r6r9rSrfrkrur|�skip_if_dont_write_bytecoder�r�r�r�r�rr�r�r�r�r�r�rrrrr'Bs.,
(&

r'c@sbeZdZejejdkd�dd��Zejejdkd�dd��Zejejdkd�dd��Z	d	d
�Z
dS)�FilePermissionTests�posixz%test meaningful only on posix systemscCs�d}t|��Pt��>\}}tjj|�}t|�}tjj|�sD|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�r?rOr"�existsr@r�rA�oct�S_IMODE�st_mode)r*�maskrr"�cached_pathrb�	stat_inforrr�test_creation_mode�s
z&FilePermissionTests.test_creation_modecCs�d}td��\t��J\}}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�rO�chmodr?r"r�r@r�rAr�r�r�)r*�moderr"r�r�rrr�test_cached_mode_issue_2051�s
z/FilePermissionTests.test_cached_mode_issue_2051cCs�d}td��\t��J\}}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�rOr�r?r"r�r@r�rAr�r�r�)r*r�rr"r�r�Zexpectedrrr�test_cached_readonly�s
z(FilePermissionTests.test_cached_readonlycCst���
\}}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)
Nr:zx = 'original'
i�r�Zoriginali�zx = 'rewritten'
Z	rewrittenrW)r&r<rZrOr�r��st_atime�st_mtimer�r?rArsrr(r)r�renamer�r�)r*rr"r�s�mZ
bytecode_onlyrrr�test_pyc_always_writable�s,
z,FilePermissionTests.test_pyc_always_writableN)ror�r��unittest�
skipUnlessrOrr�r�r�r�rrrrr��s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
rvc
Csntjdd�|_tjj|jd�|_tj|j	�t
|jd��}|j|j
�WdQRXtjjd|j	�tj�dS)Nr:r)rr"�sys_pathr r!r��orig_modulerO�mkdir�dir_namer<�	file_namerZ�
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)�globalsr?r�rr )r*�nsrrr�
import_moduleszPycRewritingTests.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�rA�module_filenamer��
code_filename�
func_filenamerr r�)r*rErrr�test_basics
s
zPycRewritingTests.test_basicscCsLtj|jdd�|j�}|j|j|j�|j|j|j�|j|j|j�dS)Nzanother_module.py)�dfile)r\r]r�r�rAr�r�r�)r*rErrr�test_incorrect_code_names
z*PycRewritingTests.test_incorrect_code_namecCshd}tj|j|d�tj|j�t|j�}tj�|j�}|j	|j
|�|j	|j|�|j	|j|�dS)Nzanother_module.py)r�)
r\r]r�rOr$rr(r)r�rAr�r�r�)r*r��pyc_filerErrr�test_module_without_sources
z,PycRewritingTests.test_module_without_sourcecCs�tj|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�rV�wb)"r\r]r�r<r��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_cellvarsrZ�dumprAZconstant)r*r�header�codeZ	constantsZforeign_code�posrErrr�test_foreign_code's&



z#PycRewritingTests.test_foreign_codeN)ror�r�r�r�rOr"r�rr�r�rxr�r(r�r�r�r+r,r�r�r�r�rrrrrr��s		
r�c@sFeZdZdZeZdd�Zdd�Zd	d
�Ze	j
ejdkd�d
d��Z
dS)�
PathsTestsr8�testäöüß�testéè�
test°³²cCs tj|j�tjdd�|_dS)N)rOr�r"r�syspath)r*rrrr+BszPathsTests.setUpcCst|j�|jtjdd�<dS)N)r	r"rr)r*rrrr,Fs
zPathsTests.tearDownc
Cs`ttjj|jd�d��}|jd�WdQRXtjj|jd�td�}|j|j	d�t
d�dS)Nztest_trailing_slash.pyr:z testdata = 'test_trailing_slash'�/�test_trailing_slash)r<rOr"r�rZrr^r?rA�testdatar)r*rrErrrrKszPathsTests.test_trailing_slashZwin32zWindows-specificc	&CsRttjj|jd�d��}|jd�WdQRXtj�tjj|j�}ddl}|j	�}|d}d||f}||dd�7}ytj
|�WnJtk
r�}z.|jtj
tjtjfkr�|jd|f��WYdd}~XnXtjjd|�ytd�}Wn6tk
�r }z|jd	||f�WYdd}~XnX|j|jd�|j|jj|�|j�td�dS)
Nztest_unc_path.pyr:ztestdata = 'test_unc_path'rz\\%s\%s$rgz%cannot access administrative share %rZ
test_unc_pathz,could not import 'test_unc_path' from %r: %r)r<rOr"r�rZr(r)r��socketZgethostname�listdirr�r�ZEPERMZEACCES�ENOENTr�rr#r?r3r@rArrprlrRr)	r*rr"rZhnZdriveZuncr�rErrr�
test_UNC_pathTs0zPathsTests.test_UNC_pathN)r8rrr)ror�r�ZSAMPLESrr"r+r,rr�r�rrQrrrrrr=s	rc@s@eZdZdd�ZeZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
S)�RelativeImportTestscCstd�dS)Nztest.relimport)r)r*rrrr,tszRelativeImportTests.tearDowncCs ddlm}|jt|d��dS)Nrg)�	relimportr)rrrprq)r*rrrr�test_relimport_starxsz'RelativeImportTests.test_relimport_starcs|�fdd�}tddd��|�tddd��|�tddd��|jt|�tddd��|jt|�tt�d��|jt|�dS)	Ncstd��dS)Nzfrom . import relimport)r_r)r�rr�check_relative�sz:RelativeImportTests.test_issue3221.<locals>.check_relativer8ztest.notarealmodule)�__package__roznotarealpkg.notarealmoduler�)r)�dictr-r.�object�	TypeError)r*rr)r�r�test_issue3221}sz"RelativeImportTests.test_issue3221c	Cs0|jt��ddlm}|jd�WdQRXdS)NrV)�sepz>explicit relative import triggered an implicit absolute import)r-r3rOr$r@)r*r$rrr�#test_absolute_import_without_future�sz7RelativeImportTests.test_absolute_import_without_futurecCs�tjjtjjt�dd�}tdd��Tt|��@|jt��ddl	}WdQRX|j
dtj�|j
dtj�WdQRXWdQRXdS)Nr��package2�
submodule1�
submodule2r)
rOr"r�r�rlrrr-r3r'rjrr )r*r"r'rrr�test_import_from_non_package�sz0RelativeImportTests.test_import_from_non_packagecCsRtddd��<ttjjtjjt�d���ddl}|jj	WdQRXWdQRXdS)Nr&zpackage2.submodule1zpackage2.submodule2r�r)
rrrOr"r�r�rlZpackage2.submodule1r'r()r*r&rrr�!test_import_from_unloaded_package�sz5RelativeImportTests.test_import_from_unloaded_packageN)
ror�r�r,r+rr#r%r)r*rrrrrrs	rc@seZdZdd�ZdS)�OverridingImportBuiltinTestscCsxddl}dd�}|j|�|�ttddd���|j|�d�WdQRXtt�ddd���|j|�|�WdQRXdS)	NrcSsddl}|S)Nr)rO)rOrrrr��sz?OverridingImportBuiltinTests.test_override_builtin.<locals>.foor?cWsdS)Nr�r)rsrrr�<lambda>�szDOverridingImportBuiltinTests.test_override_builtin.<locals>.<lambda>r�cWsdS)Nr�r)rsrrrr,�s)rOrAr�builtinsrr�)r*rOr�rrr�test_override_builtin�sz2OverridingImportBuiltinTests.test_override_builtinN)ror�r�r.rrrrr+�sr+c@s�eZdZdd�Zdd�Zdd�Zedd��Zej	e
jd	kd
�eje
e
d�oTe
j�dkd
�edd����Zedd��Zedd��Zdd�Zedd��Zedd��Zdd�Zdd�ZdS)�PycacheTestscCstt�td�t|j�dS)Nr)rrr	rr%)r*rrr�_clean�szPycacheTests._cleancCsRtd|_|j�t|jd��}td|d�WdQRXtjjdtj	�t
j�dS)Nz.pyr:z/# This is a test file written by test_import.py)r;r)rr%r0r<r=rr"r#rOrPr(r))r*�fprrrr+�s
zPycacheTests.setUpcCs,tjdtjkstd��tjd=|j�dS)NrzUnexpected sys.path[0])rr"rOrP�AssertionErrorr0)r*rrrr,�szPycacheTests.tearDowncCsZ|jtjjd��tt�|jtjjd��tjj	|j
�}|jtjj|�dj|t��dS)Nrz*bytecode file {!r} for {!r} does not exist)�assertFalserOr"r�r?rrpr(r�r�r%r�)r*�pyc_pathrrr�test_import_pyc_path�sz!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|jtjjd��tjj	|j
�}|jtjj|�dj|t��dS)N�rz"bytecode file {!r} for {!r} exists)
r
r?rrprOr"r�r(r�r�r%r3r�)r*r4rrr�test_unwritable_directory�s
z&PycacheTests.test_unwritable_directorycCsVtt�tjj|j�}|jtjj	|��tj
|j�tt�tj�|j
ttt�dS)N)r?rr(r�r�r%rprOr"r�r$rr)r-r3)r*r�rrr�test_missing_source�sz PycacheTests.test_missing_sourcecCsntt�t|j�}tj|j�tt�tj�tt�}z&|j	|j
tjjtj
tjj|���Wdtj|�XdS)N)r?rrr%rOr$rr(r)rArlr"r�rP�relpath)r*r�r�rrr�test_missing_source_legacys
z'PycacheTests.test_missing_source_legacycCs6tt�}tjjtd�}|j|jtjj	tj
|��dS)Nz.py)r?rr(r�r�rA�
__cached__rOr"r�rP)r*r�r�rrr�test___cached__szPycacheTests.test___cached__cCs\tt�t|j�}tj|j�tt�tj�tt�}|j	|j
tjjtj
tjj|���dS)N)r?rrr%rOr$rr(r)rAr<r"r�rPr:)r*r�r�rrr�test___cached___legacy_pycs
z'PycacheTests.test___cached___legacy_pyccCs�dd�}tjd�|j|�ttjjdd�d��WdQRXttjjdd�d��WdQRXtj�td�}tj	j
tjjdd��}|j|jtjjtj
|��tj	j
tjjdd��}|jtjdjtjjtj
|��dS)NcSstd�td�td�dS)N�pep3147zpep3147.foo)r	rrrrr�cleanup-sz5PycacheTests.test_package___cached__.<locals>.cleanupr?z__init__.pyr:zfoo.pyzpep3147.foo)rOr�r�r<r"r�r(r)r?r�r�rAr<rPrr )r*r@r��init_pyc�foo_pycrrr�test_package___cached__*s



z$PycacheTests.test_package___cached__cCs�dd�}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)NcSstd�td�td�dS)Nr?zpep3147.foo)r	rrrrrr@Dsz>PycacheTests.test_package___cached___from_pyc.<locals>.cleanupr?z__init__.pyr:zfoo.pyzpep3147.foo)rOr�r�r<r"r�r(r)r?rr�r�rAr<rPrr )r*r@r�rArBrrr� test_package___cached___from_pycAs&



z-PycacheTests.test_package___cached___from_pyccCsNtt�tt�t|jd��}td|d�WdQRXtt�}|j|jd�dS)NrBzx = 5)r;r�)r?rrr<r%r=rArs)r*r1r�rrr�test_recompute_pyc_same_second\sz+PycacheTests.test_recompute_pyc_same_secondN)ror�r�r0r+r,r�r5r�r�rOr�skipIfrqr6r8r9r;r=r>rCrDrErrrrr/�s 
r/c@sXeZdZdZedZdd�Zdd�Zeje	e
d�p>e
j�dkd
�ej
jdd���Zd
S)�TestSymbolicallyLinkedPackageZsamplez-taggedcCs�tjj|j�tjj|j�tjdd�|_tj	|j�|j
tjj|j�tjj|jd�}tjj|�tjj
|�svt�tj|j|jdd�|j
tjj|j�tj�|jtjj|j�d�tjjtjj|jd��s�t�dS)Nz__init__.pyT)Ztarget_is_directory)r8rrr	�tagged�package_namerr"�
orig_sys_pathrOr�r�r�rr�r2�symlinkrr(r)rA�isdir�isfile)r*Z	init_filerrrr+ksz#TestSymbolicallyLinkedPackage.setUpcCs|jtjdd�<dS)N)rJrr")r*rrrr,�sz&TestSymbolicallyLinkedPackage.tearDown�getwindowsversion�rzWindows Vista or later requiredcCsNdgtjdd�<tjj|j�s"t�tjjtjj|jd��s>t�tj|j�dS)N�.z__init__.py)	rr"rOr�rIr2r�r(r�)r*rrr�test_symlinked_dir_importable�sz;TestSymbolicallyLinkedPackage.test_symlinked_dir_importableN)rOr)ror�r�rIrHr+r,r�r�rqrrNr8rrZskip_unless_symlinkrQrrrrrGgs
rGc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ImportlibBootstrapTestscCstjd}|j|�dS)N�_frozen_importlib)rr rp)r*rErrr�test_frozen_importlib�s
z-ImportlibBootstrapTests.test_frozen_importlibcCsXddlm}tjd}|j||�|j|jd�|j|jd�|j|j	j
d�|j	�dS)Nr)�
_bootstraprSzimportlib._bootstrapr(z
_bootstrap.py)r(rUrr rnrArorrprlr})r*rUrErrr�"test_frozen_importlib_is_bootstrap�s
z:ImportlibBootstrapTests.test_frozen_importlib_is_bootstrapcCsXddlm}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(rWrr rnrArorrprlr})r*rWrErrr�4test_frozen_importlib_external_is_bootstrap_external�s
zLImportlibBootstrapTests.test_frozen_importlib_external_is_bootstrap_externalcCs*ddlm}tjd}|j|j|j�dS)Nr)�	machineryrS)r(rZrr rn�
ModuleSpec)r*rZrErrr�test_there_can_be_only_one�s
z2ImportlibBootstrapTests.test_there_can_be_only_oneN)ror�r�rTrVrYr\rrrrrR�srRc@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@tjd��,}d|_td}td}|jt|�|�WdQRXdS)Nz*importlib._bootstrap_external._path_isfileTz.pycz.py)�mock�patch�return_valuerrAr)r*�_path_isfiler"Zexpectrrr�test_get_sourcefile�s
z&GetSourcefileTests.test_get_sourcefilec
Cs8tjd��$}d|_td}|jt|�|�WdQRXdS)Nz*importlib._bootstrap_external._path_isfileFz.pyc)r^r_r`rrAr)r*rar"rrr�test_get_sourcefile_no_source�sz0GetSourcefileTests.test_get_sourcefile_no_sourcecCstd}|jt|�|�dS)Nz.bad_ext)rrAr)r*r"rrr�test_get_sourcefile_bad_ext�sz.GetSourcefileTests.test_get_sourcefile_bad_extN)ror�r��__doc__rbrcrdrrrrr]�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��Zejed �d!d"��Zd#S)%�ImportTracebackTestscCs,tjt�tjdd�|_tjjdt�dS)Nr)rOr�rrr"�old_pathr#)r*rrrr+�s
zImportTracebackTests.setUpcCs|jtjdd�<tt�dS)N)rgrr"r	r)r*rrrr,�szImportTracebackTests.tearDown�.pyc
CsJtjjt||�}t|d��}|j|�WdQRX|jt|�tj	�|S)Nr:)
rOr"r�rr<rZr�rr(r))r*rE�contentsrDZfnamerrrr�
create_module�sz"ImportTracebackTests.create_modulecCs|g}x8|r<|jj}|j}|s*||dkr4|j|�|j}qW|jt|�t|�|�x"t||�D]\}}|j||�q`WdS)NrVrY)	�tb_frame�f_coderr^�tb_nextrA�len�zipry)r*�tb�filesZ
deduped_filesr�fnZpatrrr�assert_traceback�s

z%ImportTracebackTests.assert_tracebackcCsRyddl}Wn(tk
r4}z|j}WYdd}~XnX|jd�|j|tg�dS)Nrz#ImportError should have been raised)�nonexistent_xyzzyr3�
__traceback__r@rsrl)r*rtr�rprrr�test_nonexistent_module�s
z,ImportTracebackTests.test_nonexistent_modulecCs`|jdd�yddl}Wn(tk
r@}z|j}WYdd}~XnX|jd�|j|tdg�dS)Nr�zimport nonexistent_xyzzyrz#ImportError should have been raisedzfoo.py)rjr�r3rur@rsrl)r*r�r�rprrr�test_nonexistent_module_nesteds
z3ImportTracebackTests.test_nonexistent_module_nestedcCs`|jdd�yddl}Wn(tk
r@}z|j}WYdd}~XnX|jd�|j|tdg�dS)Nr�z1/0rz)ZeroDivisionError should have been raisedzfoo.py)rjr�rirur@rsrl)r*r�r�rprrr�test_exec_failures
z&ImportTracebackTests.test_exec_failurecCsn|jdd�|jdd�yddl}Wn(tk
rL}z|j}WYdd}~XnX|jd�|j|tddg�dS)	Nr�z
import bar�barz1/0rz)ZeroDivisionError should have been raisedzfoo.pyzbar.py)rjr�rirur@rsrl)r*r�r�rprrr�test_exec_failure_nesteds
z-ImportTracebackTests.test_exec_failure_nestedcCs^|jdd�yddl}Wn(tk
r@}z|j}WYdd}~XnX|jd�|j|tg�dS)Nr�zinvalid syntax is invalidrz#SyntaxError should have been raised)rjr��SyntaxErrorrur@rsrl)r*r�r�rprrr�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__.pyr:zbar.py)r�rrOr"r�rr�r<rZr(r))r*�parentZchildZpkg_nameZpkg_path�	init_pathr�bar_pathrrr�_setup_broken_package+s
z*ImportTracebackTests._setup_broken_packagecCsd|jdd�\}}yddl}Wn(tk
rD}z|j}WYdd}~XnX|jd�|j|t|g�dS)Nrz1/0rz)ZeroDivisionError should have been raised)r��_parent_foo.barrirur@rsrl)r*rr�r}r�rprrr�test_broken_submodule:s
z*ImportTracebackTests.test_broken_submodulecCsh|jdd�\}}yddlm}Wn(tk
rH}z|j}WYdd}~XnX|jd�|j|t|g�dS)Nrz1/0r)ryz#ImportError should have been raised)r�r}ryrirur@rsrl)r*rr�ryr�rprrr�test_broken_fromDs
z%ImportTracebackTests.test_broken_fromcCsd|jdd�\}}yddl}Wn(tk
rD}z|j}WYdd}~XnX|jd�|j|t|g�dS)Nz1/0rrz)ZeroDivisionError should have been raised)r�r�rirur@rsrl)r*rr�r}r�rprrr�test_broken_parentNs
z'ImportTracebackTests.test_broken_parentcCsh|jdd�\}}yddlm}Wn(tk
rH}z|j}WYdd}~XnX|jd�|j|t|g�dS)Nz1/0rr)ryz)ZeroDivisionError should have been raised)r�r}ryrirur@rsrl)r*rr�ryr�rprrr�test_broken_parent_fromXs
z,ImportTracebackTests.test_broken_parent_fromcCs�|jdd�tjd}dt|j�kr.|jj}nd}zfdd�}||j_yddl}Wn(tk
rx}z|j}WYdd}~XnX|j	d�|j
|td	tg�Wd|dkr�|j`n||j_XdS)
Nr�rrX�load_modulecWsdddS)NrVrr)r�rrr�exec_modulemsz9ImportTracebackTests.test_import_bug.<locals>.exec_modulerz)ZeroDivisionError should have been raisedz<frozen importlib)rjrr �vars�SourceLoaderr�r�rirur@rsrl)r*r(Zold_exec_moduler�r�r�rprrr�test_import_bugbs"


z$ImportTracebackTests.test_import_bugzneed TESTFN_UNENCODABLEcCs>tjdtd�}|jt|�|dd�}tjdd|dd�dS)	Nr�passrhz-czmod = __import__(%a)F)Z
__isolated���)rrrr�rr�)r*Zpynamerrrr�test_unencodable_filename}s
z.ImportTracebackTests.test_unencodable_filenameN)rh)ror�r�r+r,rjrsrvrwrxrzr|r�r�r�r�r�rr�r�r�rr�rrrrrf�s 








rfc@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�CircularImportTestszQSee the docstrings of the modules being imported for the purpose of the
    test.cCs.x(ttjj��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 �keysrR)r*�keyrrrr,�s
zCircularImportTests.tearDowncCs0yddl}Wntk
r*|jd�YnXdS)Nrz/circular import through relative imports failed)Z,test.test_import.data.circular_imports.basicr3r@)r*r8rrr�test_direct�szCircularImportTests.test_directcCs0yddl}Wntk
r*|jd�YnXdS)Nrz@relative import in module contributing to circular import failed)Z/test.test_import.data.circular_imports.indirectr3r@)r*r8rrr�
test_indirect�sz!CircularImportTests.test_indirectcCs0yddl}Wntk
r*|jd�YnXdS)Nrz-circular import involving a subpackage failed)Z1test.test_import.data.circular_imports.subpackager3r@)r*r8rrr�test_subpackage�sz#CircularImportTests.test_subpackagecCsTyddljjjj}Wntk
r2|jd�YnXddlm}|j	|j|j�dS)Nrz9circular import with rebinding of module attribute failed)r�)
Z0test.test_import.data.circular_imports.rebindingrSr�Zcircular_imports�	rebindingr3r@Z-test.test_import.data.circular_imports.subpkgr�rn)r*r�r�rrr�test_rebinding�sz"CircularImportTests.test_rebindingN)	ror�r�rer,r�r�r�r�rrrrr��sr��__main__)Nr)Ar(�importlib.utilZimportlib._bootstrap_externalrr-r�rOrQr\r>r�rr�r�r�Z
unittest.mockr^r�r�Zshutil�
contextlibrmr8rrrrrrr	r
rrr
rrrrrrrrZtest.test_importlib.utilrrF�dont_write_bytecoder�r�contextmanagerr&ZTestCaser'r�r�rrr+r/rGrRr]rfr�ro�mainrrrr�<module>sb
P	K
S^5@".
 
!1(