Your IP : 216.73.216.213


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

U

i�f�F�	@s�ddlZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
Z
ddlZe���e�
de�ddlZW5QRXddlZdd�ZGdd�de
j�ZGd	d
�d
e
j�ZGdd�de
j�ZGd
d�de
j�ZGdd�de
j�Zedkr�e
��dS)�N)�support)�
script_helper�ignorecCs"t�|�}t�ttd�d�|�S)N�load_dynamiczimp.load_dynamic() required)r�cpython_only�unittest�skipIf�hasattr�imp)Zmeth�r�2/opt/alt/python38/lib64/python3.8/test/test_imp.py�requires_load_dynamics
��r
c@seZdZdd�Zdd�ZdS)�	LockTestscCs|�t��|d|�dS)Nz!expected imp.lock_held() to be %r)�assertEqualr
�	lock_held)�self�expectedrrr�verify_lock_states�zLockTests.verify_lock_statecCs�d}t��}|�|�t|�D]}t��|�d�qt|�D]}t��q>|�|�|s�zt��Wntk
rzYnX|�d�dS)N�2Tz5release_lock() without lock should raise RuntimeError)r
rr�range�acquire_lock�release_lock�RuntimeErrorZfail)rZLOOPSZlock_held_at_start�irrr�testLock s


zLockTests.testLockN)�__name__�
__module__�__qualname__rrrrrrrsrc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
edd��Zedd��Z
edd��Zedd��Zedd��Ze�ejd�dd��Zdd�Zd d!�Zejd"d#��Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,S)-�ImportTestscCst�d�}|j|_|j|_dS)Nztest.encoded_modules)�	importlib�
import_module�test_strings�__path__�	test_path)r�modrrr�setUp<s
zImportTests.setUpcCs2|jD]&\}}}t�d|�}|�||j�qdS)Nztest.encoded_modules.module_)r!rr r�test)r�modname�encodingZteststrr$rrr�test_import_encoded_moduleAs
�z&ImportTests.test_import_encoded_modulec
Csv|jD]:\}}}t�d||j�d�}|�|j|�W5QRXqtj�t	�g}|�
t��t�d|�W5QRXdS)N�module_r�badsyntax_pep3120)r!r
�find_moduler#rr(�os�path�dirname�__file__�assertRaises�SyntaxError)rr$r(�_�fdr.rrr�test_find_module_encodingGsz%ImportTests.test_find_module_encodingc
Cs�|jD]p\}}}t�d||j�\}}}|�D|�|d�|�|j|�|�|��d�|�|��d|�W5QRXqt�d�\}}}|�@|�|d�|�|jd�|�|��d�|�|��d�W5QRXdS)Nr*rz# test %s encoding
�tokenize�utf-8z*"""Tokenization help for Python programs.
)	r!r
r,r#ZassertNotEqualrr(�tell�readline)rr$r(r3�fp�filename�inforrr�test_issue1267Ps&
�
�
�zImportTests.test_issue1267c
Cs�d}tj�dd�zNt|dd��}|�d�W5QRXt�|�\}}}|�	�|�
|jd�W5tjd=t�|d�t�|d�XdS)	NZtest_imp_helperr�.�.py�.pyc�wz%# coding: cp1252
u = 'test.test_imp'
�cp1252)�sysr.�insertr�unlink�open�writer
r,�closerr()r�
temp_mod_name�filer;r<rrr�test_issue3594cszImportTests.test_issue3594cCs�t��}ddddddddddd�
}tjdkr>|�|d�d	}n
|�|�}|sZ|�d
|�|�|�}d|}d|}tj�	|d
�}�z�tj�
dtj�t|dd��}	|	�d�W5QRXt�|�\}	}
}|	�x|�|	�|�|
dd��|��|�|dd�|�|dd�|�|dtj�t�||	|
|�}|�|jd�W5QRXt��� t�d�t�||d�}W5QRX|�|jd�t���.t�d�tj�s�t�|t�|d��}W5QRX|�|jd�tj� |��s�t�!|�t|d��}	|	�d�W5QRXt���t�d�t�"||�}
W5QRX|�|
j#d�W5tjd=dD]"}t
�||�t
�||��qRt
�|�t
�d�XdS)Ns�������)
r7�cp1250�cp1251rB�cp1253�cp1254�cp1255�cp1256�cp1257�cp1258�darwinr7säz2can't run this test with %s as filesystem encodingZtest_imp_helper_Ztest_imp_helper_package_z__init__.pyr)r?r@�__pycache__r?rAza = 1
�����r�rzb = 2
)$rC�getfilesystemencoding�platformr�get�skipTest�decoder-r.�joinrrEZrmtreerD�curdirrFrGr
r,ZassertIsNotNoneZ
assertTrue�endswithZ	PY_SOURCE�load_module�a�warnings�catch_warnings�simplefilter�load_source�dont_write_bytecodeZ
load_compiled�cache_from_source�exists�mkdirZload_package�b)rZfs_encodingZ
known_localesZspecial_charZdecoded_charrIZtest_package_nameZinit_file_nameZextrJr;r<r$�packagerrr�test_issue5604qs~�

�





�



zImportTests.test_issue5604cCs$tj�t�}|�ttjd|g�dS)Nr+)r-r.r/r0r1r2r
r,)rr.rrr�test_issue9319�s�zImportTests.test_issue9319c	Csttj}tj}t���Vt�d�}|�|dj�tj	d|��}|�
t|�|�
||j�|�||j�W5QRXdS)Nr-r)r-)r-r.�getenvr�EnvironmentVarGuardr
r,�
addCleanuprHrf�assertIsZassertIsNot)r�	orig_pathZorig_getenv�xZnew_osrrr�test_load_from_source�s	

z!ImportTests.test_load_from_sourcecCsLd}t�|�}|d}|dk	r*|�|j�tj|f|��}|�|j|�dS)N�_heapqr)r
r,rvrHrfrr)rZexampleryZfile_r$rrr�test_issue15828_load_extensions�s
z+ImportTests.test_issue15828_load_extensionsc	Cs�d}t�|�\}}}|��t�||�}t�d|�}t�d|�}|�|j|�|�|jd�|�|jd�|�t��t�d|�W5QRXdS)N�_testimportmultipleZ_testimportmultiple_fooZ_testimportmultiple_barZnonexistent)r
r,rHrrrr1�ImportError)r�mZfileobj�pathname�descriptionZmod0Zmod1Zmod2rrr�+test_issue16421_multiple_modules_in_one_dll�sz7ImportTests.test_issue16421_multiple_modules_in_one_dllc	CsNd}d}|�t��}t�||�W5QRX|�||jj�|�||jj�dS)Nzbogus file path�	extension)	r1r~r
rZassertInZ	exceptionr.r�name)rr.r��errrrr�"test_load_dynamic_ImportError_path�sz.ImportTests.test_load_dynamic_ImportError_pathcCs`d}t�|�}|ddk	r&|d��|ddtjkrB|�d�tj|df|dd���dS)Nr}rr]z/found module doesn't appear to be a C extensionr[)r
r,rHZC_EXTENSIONrarf)rr��foundrrr�'test_load_module_extension_file_is_Nones

z3ImportTests.test_load_module_extension_file_is_NonecCs�d}ztj|=Wntk
r$YnXz�t�|�}tj�d�}t�||j	�}|�
|j|�|�
|jj
|�|�
|jj	|j	�|�tt|d�|�
|jd�|�tj||�W5ztj|=Wntk
r�YnXXdS)Nztest.imp_dummyZ_testmultiphaseZ
dummy_namei�)rC�modules�KeyErrorrr �util�	find_specr
r�originrr�__spec__r�r1�AttributeError�getattrZ	int_constrw)rr��module�specrrr�3test_issue24748_load_module_skips_sys_modules_checks&
z?ImportTests.test_issue24748_load_module_skips_sys_modules_checkz*test meaningful only when writing bytecodec	CsDt���2tjd}t�|�|�tdtjtjdg�W5QRXdS)Nr?z
^No moduler>)	r�temp_cwdZTESTFNr-ro�assertRaisesRegexr~r
r,)r�sourcerrr�test_bug7732+s


�zImportTests.test_bug7732cCs2t�dtjttj��}|�tj�|�tj�dS)Nr
)r
Z_LoadSourceCompatibilityr0rF�get_data)r�loaderrrr�test_multiple_calls_to_get_data4s

�z+ImportTests.test_multiple_calls_to_get_datac
Csddt��}ttjt�|�}t�tj||��.|�td��t�	|t
d�W5QRXW5QRXdS)NZtmpz
embedded null�)r�typerCr�rZ	swap_itemr��
ValueErrorr
rkr0)rr'r$rrr�test_load_source;s

zImportTests.test_load_sourcec	Cs>t�td�}Gdd�d�}|�t��||��W5QRXdS)N�create_dynamicc@seZdZdZdZdS)z,ImportTests.test_issue31315.<locals>.BadSpecN�foo)rrrr�r�rrrr�BadSpecIsr�)rZ
get_attributer
r1�	TypeError)rr�r�rrr�test_issue31315DszImportTests.test_issue31315cCs4ddl}|�|jjd�ddl}|�|jjd�dS)Nr�frozen)�_frozen_importlib_externalrr�r��_frozen_importlib)rr�r�rrr�test_issue_35321OszImportTests.test_issue_35321cCs,|�t�dd�d�|�t�dd�d�dS)N�*shis��Z
:}��+s��65���9)r�_imp�source_hash)rrrr�test_source_hashZszImportTests.test_source_hashcCshgdfddgdfddgdfddgdfg}|D]6\}}|ddg}tj|�}|�|j���d�|�q,dS)N�defaultz--check-hash-based-pycs�always�neverz-cz.import _imp; print(_imp.check_hash_based_pycs)r7)rZassert_python_okr�out�striprb)rZcasesZinterp_argsr�args�resrrr�'test_pyc_invalidation_mode_from_cmdline^s


��
z3ImportTests.test_pyc_invalidation_mode_from_cmdlinec
Cs�t���`tdd��}|�d�W5QRXtjddtjjd�tj	ddgd�\}}}t�
d|||�}W5QRX|�|jd	�dS)
Nzmymod.py�wbsx = 42
T)�doraise�invalidation_modeZmymodr>)r.r�)
rr�rFrG�
py_compile�compile�PycInvalidationMode�CHECKED_HASHr
r,rfrry)rr:rJr.r�r$rrr�test_find_and_load_checked_pycms
�z*ImportTests.test_find_and_load_checked_pycN)rrrr%r)r5r=rKrrrsrzr
r|r�r�r�r�rrrCrlr�r�r�rrr�r�r�r�r�rrrrr;s<	W




�
	

rc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ReloadTestsc	Cs*t���ddl}t�|�W5QRXdS)Nr)rrur-r
�reload)rr-rrr�test_source�s
zReloadTests.test_sourcec	Cs,t�d��ddl}t�|�W5QRXdS)N�timer)r�CleanImportr�r
r�)rr�rrr�test_extension�szReloadTests.test_extensionc	Cs,t�d��ddl}t�|�W5QRXdS)N�marshalr)rr�r�r
r�)rr�rrr�test_builtin�szReloadTests.test_builtinc	sTddlm}tj�d���fdd�}|�|�|�td��t�	|�W5QRXdS)Nr)�parser�htmlcs�tjd<dS)Nr�)rCr�r�r�rr�cleanup�sz5ReloadTests.test_with_deleted_parent.<locals>.cleanup)
r�r�rCr��poprvr�r~r
r�)rr�r�rr�r�test_with_deleted_parent�s
z$ReloadTests.test_with_deleted_parentN)rrrr�r�r�r�rrrrr�|sr�c@sLeZdZe��Ze�ej	j
dk	d�dd��Ze�ej	j
dk	d�dd��ZdS)�PEP3147TestsNz1requires sys.implementation.cache_tag not be Nonec	CsFtj�dddd�}tj�ddddd�|j��}|�t�|d�|�dS)Nr��bar�baz�qux.pyrY�
qux.{}.pycT)r-r.rc�format�tagrr
rm�rr.Zexpectrrr�test_cache_from_source�s

�z#PEP3147Tests.test_cache_from_sourcez4requires sys.implementation.cache_tag to not be Nonec	CsDtj�ddddd�|j��}tj�dddd�}|�t�|�|�dS)Nr�r�r�rYr�r�)r-r.rcr�r�rr
�source_from_cacher�rrr�test_source_from_cache�s

�z#PEP3147Tests.test_source_from_cache)
rrrr
Zget_tagr�rZ
skipUnlessrC�implementation�	cache_tagr�r�rrrrr��s�
�r�c@s&eZdZe�ejdkd�dd��ZdS)�NullImporterTestsNzNeed an undecodeable filenamec	Cs6tj}t�|�z|�ttj|�W5t�|�XdS)N)	r�TESTFN_UNENCODABLEr-ro�rmdirr1r~r
ZNullImporter)rr�rrr�test_unencodeable�s

z#NullImporterTests.test_unencodeable)rrrrrrr�r�rrrrr��s�r��__main__)r�importlib.utilr-Zos.pathr�rCr&rZtest.supportrrrhrirj�DeprecationWarningr
r�r
ZTestCaserrr�r�r�r�mainrrrr�<module>s.
"C&