Your IP : 216.73.216.213


Current Path : /opt/alt/python39/lib64/python3.9/test/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/test/__pycache__/test_imp.cpython-39.opt-2.pyc

a

XC?h�F�@sddlZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
Z
ddlZe���$e�
de�ddlZWd�n1s�0YddlZdd�ZGdd�de
j�ZGd	d
�d
e
j�ZGdd�de
j�ZGd
d�de
j�ZGdd�de
j�Zedk�re
��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/python39/lib64/python3.9/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��WntyxYn0|�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	Cs�|jD]N\}}}t�d||j�d�}|�|j|�Wd�q1sJ0Yqtj�t	�g}|�
t��t�d|�Wd�n1s�0YdS)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]�\}}}t�d||j�\}}}|�N|�|d�|�|j|�|�|��d�|�|��d|�Wd�q1s�0Yqt�d�\}}}|�J|�|d�|�|jd�|�|��d�|�|��d�Wd�n1s�0YdS)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�z�t|dd��}|�d�Wd�n1sB0Yt�|�\}}}|��|�|j	d�Wtjd=t
�|d�t
�|d�n&tjd=t
�|d�t
�|d�0dS)	NZtest_imp_helperr�.�.py�wz%# coding: cp1252
u = 'test.test_imp'
�cp1252�.pyc)�sysr.�insert�open�writer
r,�closerr(r�unlink)r�
temp_mod_name�filer;r<rrr�test_issue3594cs(�zImportTests.test_issue3594cCsVt��}ddddddddddd�
}tjdkr>|�|d�d	}n
|�|�}|sZ|�d
|�|�|�}d|}d|}tj�	|d
�}�z�tj�
dtj�t|dd��}|�
d�Wd�n1s�0Yt�|�\}}	}
|��|�|�|�|	dd��|��|�|
dd�|�|
dd�|�|
dtj�t�|||	|
�}|�|jd�Wd�n1�sl0Yt���*t�d�t�||d�}Wd�n1�s�0Y|�|jd�t���8t�d�tj�s�t�|t�|d��}Wd�n1�s0Y|�|jd�tj�|��s@t�|�t|d��}|�
d�Wd�n1�sl0Yt���&t�d�t�||�}Wd�n1�s�0Y|�|j d�Wtjd=dD]"}
t!�"||
�t!�"||
��q�t!�#|�t!�#d�nFtjd=dD]"}
t!�"||
�t!�"||
��qt!�#|�t!�#d�0dS)Ns�������)
r7�cp1250�cp1251rA�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__.pyrr?r@za = 1
�����r�rzb = 2
)r?rB�__pycache__)$rC�getfilesystemencoding�platformr�get�skipTest�decoder-r.�joinrD�curdirrErFr
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�brrHZrmtree)rZfs_encodingZ
known_localesZspecial_charZdecoded_charrIZtest_package_nameZinit_file_namerJr;r<r$�packageZextrrr�test_issue5604qs��

�
(
.

0

�$
*

,
�
zImportTests.test_issue5604cCs$tj�t�}|�ttjd|g�dS)Nr+)r-r.r/r0r1r2r
r,)rr.rrr�test_issue9319�s
�zImportTests.test_issue9319cCs�tj}tj}t���dt�d�}|�|dj�tj	dg|�R�}|�
t|�|�
||j�|�||j�Wd�n1s~0YdS)Nr-r)r-r.�getenvr�EnvironmentVarGuardr
r,�
addCleanuprGrf�assertIsZassertIsNot)r�	orig_pathZorig_getenv�xZnew_osrrr�test_load_from_source�s	

z!ImportTests.test_load_from_sourcecCsNd}t�|�}|d}|dur*|�|j�tj|g|�R�}|�|j|�dS)N�_heapqr)r
r,rvrGrfrr)rZexampleryZfile_r$rrr�test_issue15828_load_extensions�s
z+ImportTests.test_issue15828_load_extensionscCs�d}t�|�\}}}|��t�||�}t�d|�}t�d|�}|�|j|�|�|jd�|�|jd�|�t��t�d|�Wd�n1s�0YdS)N�_testimportmultipleZ_testimportmultiple_fooZ_testimportmultiple_barZnonexistent)r
r,rGrrrr1�ImportError)r�mZfileobj�pathname�descriptionZmod0Zmod1Zmod2rrr�+test_issue16421_multiple_modules_in_one_dll�sz7ImportTests.test_issue16421_multiple_modules_in_one_dllcCsbd}d}|�t��}t�||�Wd�n1s40Y|�||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_pathcCsbd}t�|�}|ddur&|d��|ddtjkrB|�d�tj|dg|dd��R�dS)Nr}rr\z/found module doesn't appear to be a C extensionrZ)r
r,rGZC_EXTENSIONrarf)rr��foundrrr�'test_load_module_extension_file_is_Nones

z3ImportTests.test_load_module_extension_file_is_NonecCs�d}ztj|=Wnty"Yn0z�t�|�}tj�d�}t�||j	�}|�
|j|�|�
|jj
|�|�
|jj	|j	�|�tt|d�|�
|jd�|�tj||�Wztj|=Wq�ty�Yq�0n"ztj|=Wnty�Yn00dS)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 bytecodecCsXt���<tjd}t�|�|�tdtjtjdg�Wd�n1sJ0YdS)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_LoadSourceCompatibilityr0rE�get_data)r�loaderrrr�test_multiple_calls_to_get_data4s

�z+ImportTests.test_multiple_calls_to_get_datac	Cs�dt��}ttjt�|�}t�tj||��L|�td�� t�	|t
d�Wd�n1s`0YWd�n1s~0YdS)N�tmpz
embedded null�)r�typerCr�rZ	swap_itemr��
ValueErrorr
rkr0)rr'r$rrr�test_load_source;s

zImportTests.test_load_sourcecCsRt�td�}Gdd�d�}|�t��||��Wd�n1sD0YdS)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�Wd�n1s40Ytjddtjjd�tj	ddgd�\}}}t�
d|||�}Wd�n1s�0Y|�|jd	�dS)
Nzmymod.py�wbsx = 42
T)�doraise�invalidation_modeZmymodr>)r.r�)
rr�rErF�
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)
�ReloadTestscCs>t���"ddl}t�|�Wd�n1s00YdS)Nr)rrur-r
�reload)rr-rrr�test_source�s
zReloadTests.test_sourcecCs@t�d��"ddl}t�|�Wd�n1s20YdS)N�timer)r�CleanImportr�r
r�)rr�rrr�test_extension�szReloadTests.test_extensioncCs@t�d��"ddl}t�|�Wd�n1s20YdS)N�marshalr)rr�r�r
r�)rr�rrr�test_builtin�szReloadTests.test_builtincshddlm}tj�d���fdd�}|�|�|�td��t�	|�Wd�n1sZ0YdS)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
dud�dd��Ze�ej	j
dud�dd��ZdS)�PEP3147TestsNz1requires sys.implementation.cache_tag not be Nonec	CsFtj�dddd�}tj�ddddd�|j��}|�t�|d�|�dS)Nr��bar�baz�qux.pyr]�
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�r]r�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�ejdud�dd��ZdS)�NullImporterTestsNzNeed an undecodeable filenamec	Cs@tj}t�|�z|�ttj|�Wt�|�nt�|�0dS)N)	r�TESTFN_UNENCODABLEr-ror1r~r
ZNullImporter�rmdir)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&