Your IP : 216.73.216.85


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

a

�Shk+�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZdd�Zdd�ZGdd	�d	ee
j��ZGd
d�d�ZGdd
�d
ee
jedd�ZGdd�dee
jedd�ZGdd�de
j�Zedkr�e
��dS)�N)�support)�
script_helpercst����fdd��}|S)NcsNt���2}|�d�|�d��|i|��Wd�S1s@0YdS)N�SOURCE_DATE_EPOCH�RPM_BUILD_ROOT�rZEnvironmentVarGuardZunset��args�kwargs�env��fxn��9/opt/alt/python39/lib64/python3.9/test/test_py_compile.py�wrappers


z*without_source_date_epoch.<locals>.wrapper��	functools�wraps�rrr
rr�without_source_date_epochsrcst����fdd��}|S)NcsLt���0}d|d<|�d��|i|��Wd�S1s>0YdS)NZ	123456789rrrrrr
rrs

z'with_source_date_epoch.<locals>.wrapperrrr
rr�with_source_date_epochsrcseZdZ�fdd�Z�ZS)�SourceDateEpochTestMetac	sZt��||||�}t|�D]:}|�d�rt||�}|r@t|�}nt|�}t|||�q|S)NZtest_)�super�__new__�dir�
startswith�getattrrr�setattr)	�mcls�name�basesZdct�source_date_epoch�cls�attrZmethr��	__class__r
rr(s


zSourceDateEpochTestMeta.__new__)�__name__�
__module__�__qualname__r�
__classcell__r
r
r#rr'src@s�eZdZdd�Zdd�Zdd�Zdd�Ze�e	j
�e	j�pHe	j
�
e	j�d	�d
d��Zdd
�Zdd�Zdd�Ze�ee	d�o�e	��dkd�e�e	jdkd�dd���Zdd�Zdd�Ze�ejjdkd�dd��Zd d!�Zd"d#�Zd$d%�Zd&S)'�PyCompileTestsBasecCs�tjt��d�|_tj�|jd�|_|jd|_t	j
�|j�|_tj�
t���d|_tj�
|j�d}|rvt�|�t|jd��}|�d�Wd�n1s�0YdS)N)r�_test.py�cr�w�x = 123
)�tempfile�mkdtemp�os�getcwd�	directory�path�join�source_path�pyc_path�	importlib�util�cache_from_source�
cache_path�
splitdrive�	cwd_drive�chdir�open�write)�selfZdrive�filer
r
r�setUp9s
zPyCompileTestsBase.setUpcCs"t�|j�|jrt�|j�dS�N)�shutil�rmtreer2r<r0r=�r@r
r
r�tearDownIszPyCompileTestsBase.tearDowncCs<t�|j|j�|�tj�|j��|�tj�|j	��dSrC)
�
py_compile�compiler5r6�
assertTruer0r3�exists�assertFalser:rFr
r
r�test_absolute_pathNsz%PyCompileTestsBase.test_absolute_pathc	Csxzt�|jd|j�Wn ttfy8|�d�Yn<0|�t�� t�	|j
|j�Wd�n1sj0YdS)Nz.actualz.need to be able to create a symlink for a file)r0�symlinkr6�NotImplementedError�OSErrorZskipTest�assertRaises�FileExistsErrorrHrIr5rFr
r
r�test_do_not_overwrite_symlinksSsz1PyCompileTestsBase.test_do_not_overwrite_symlinksz7requires os.devnull and for it to be a non-regular filecCs>|�t�� t�|jtj�Wd�n1s00YdSrC)rQrRrHrIr5r0�devnullrFr
r
r�&test_do_not_overwrite_nonregular_files_sz9PyCompileTestsBase.test_do_not_overwrite_nonregular_filescCs$t�|j�|�tj�|j��dSrC)rHrIr5rJr0r3rKr:rFr
r
r�test_cache_pathgsz"PyCompileTestsBase.test_cache_pathcCsxt�|j��0t�tj�|j�tj�|j	��Wd�n1sB0Y|�
tj�|j	��|�tj�|j
��dSrC)rZ
change_cwdr2rHrIr0r3�basenamer5r6rJrKrLr:rFr
r
r�test_cwdks�"zPyCompileTestsBase.test_cwdcCsLt�tj�|j�tj�|j��|�tj�|j��|�	tj�|j
��dSrC)rHrIr0r3�relpathr5r6rJrKrLr:rFr
r
r�test_relative_pathrs
�z%PyCompileTestsBase.test_relative_path�geteuidrznon-root user required�ntz/cannot control directory permissions on Windowsc
Cs�t�|j�}t�|jtj�zN|�t�� t�|j	|j
�Wd�n1sN0YWt�|j|j�nt�|j|j�0dSrC)r0�statr2�chmod�S_IREADrQ�IOErrorrHrIr5r6�st_mode)r@�moder
r
r�test_exceptions_propagatexs0z,PyCompileTestsBase.test_exceptions_propagatecCsptj�tj�t�d�}t���$|�tj	|dd��Wd�n1sH0Y|�
tj�tj
�|���dS)N�bad_coding2.pyF)�doraise)r0r3r4�dirname�__file__r�captured_stderr�assertIsNonerHrIrLrKr7r8r9)r@�
bad_codingr
r
r�test_bad_coding�s
2

�z"PyCompileTestsBase.test_bad_codingcCs�t�|j|j�|�tj�|j��|�tj�|j	��t
|jd��$}tj�
|��di�}Wd�n1sn0Ytj�d�r�d}nd}|�||�dS)N�rb�testr�r)rHrIr5r6rJr0r3rKrLr:r>r7�_bootstrap_external�
_classify_pyc�read�environ�get�assertEqual)r@�fp�flagsZexpected_flagsr
r
r�test_source_date_epoch�s
�"z)PyCompileTestsBase.test_source_date_epochztest does not work with -Oc	Cs�tj�|jd�}tj�|�}|d}tj�|�\}}tj�|�}|�	tj�||�tj�dd�
tjj
���t|d��}|�d�Wd�n1s�0Yt�|�|�tj�|��|�tj�|��dS)Nz
foo.bar.pyr+�__pycache__zfoo.bar.{}.pycr,r-)r0r3r4r2r7r8r9�splitrWrt�format�sys�implementation�	cache_tagr>r?rHrIrJrKrL)r@Z
weird_pathr:r6�head�tailZpenultimate_tailrAr
r
r�test_double_dot_no_clobber�s"��(
z-PyCompileTestsBase.test_double_dot_no_clobbercCs|�dtj|jdd��dS)Nzopt-2�)�optimize)�assertInrHrIr5rFr
r
r�test_optimization_path�sz)PyCompileTestsBase.test_optimization_pathcCs�tj|jtjjd�t|jd��$}tj�	|�
�di�}Wd�n1sJ0Y|�|d�tj|jtjjd�t|jd��$}tj�	|�
�di�}Wd�n1s�0Y|�|d�dS)N)�invalidation_moderlrmrn�)
rHrIr5�PycInvalidationMode�CHECKED_HASHr>r:r7rorprqrt�UNCHECKED_HASH)r@rurvr
r
r�test_invalidation_mode�s$�
�"�
�"z)PyCompileTestsBase.test_invalidation_modec	Cs�tj�tj�t�d�}t����}|�tj	|ddd��|�tj	|ddd��|�
|��d�|�tj
�� tj	|ddd�Wd�n1s�0YWd�n1s�0YdS)NrdFr�)re�quietT�r�)r0r3r4rfrgrrhrirHrIrt�getvaluerQ�PyCompileError)r@rj�stderrr
r
r�
test_quiet�s
zPyCompileTestsBase.test_quietN)r%r&r'rBrGrMrS�unittestZskipIfr0r3rKrT�isfilerUrVrXrZ�hasattrr[rrcrkrwr{rvr�r�r�r�r�r
r
r
rr)7s2 �
��
r)c@seZdZdS)�PyCompileTestsWithSourceEpochN�r%r&r'r
r
r
rr��sr�T)�	metaclassr c@seZdZdS)� PyCompileTestsWithoutSourceEpochNr�r
r
r
rr��sr�Fc@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�PyCompileCLITestCasecCsft��|_tj�|jd�|_tj�	|j�|_
t|jd��}|�d�Wd�n1sX0YdS)Nr*r,r-)
r.r/r2r0r3r4r5r7r8r9r:r>r?)r@rAr
r
rrB�s

zPyCompileCLITestCase.setUpcCst�|j�dSrC)rrEr2rFr
r
rrG�szPyCompileCLITestCase.tearDowncOsT|r:|ddkr:d|vr:tjtjdddg|d��dd�Stjddg|�Ri|��S)Nr�-�input�-mrHT)r�Zcapture_output)�
subprocess�runr{�
executable�encoderZassert_python_ok)r@rr	r
r
r�pycompilecmd�s
�z!PyCompileCLITestCase.pycompilecmdcGstjddg|�R�S)Nr�rH)rZassert_python_failure)r@rr
r
r�pycompilecmd_failure�sz)PyCompileCLITestCase.pycompilecmd_failurecCsR|jd|jd�}|�|jd�|�|jd�|�|jd�|�tj�	|j
��dS)Nr�)r�r�)r�r5rt�
returncode�stdoutr�rJr0r3rKr:)r@�resultr
r
r�
test_stdin�s
zPyCompileCLITestCase.test_stdincCsR|�|j|j�\}}}|�|d�|�|d�|�|d�|�tj�|j��dS)Nrr�)r�r5rtrJr0r3rKr:)r@�rcr�r�r
r
r�test_with_files�s
z$PyCompileCLITestCase.test_with_filescCsNtj�tj�t�d�}|�|�\}}}|�|d�|�|d�|�d|�dS)Nzbadsyntax_3131.pyr�r�sSyntaxError)r0r3r4rfrgr�rtr�)r@Z
bad_syntaxr�r�r�r
r
r�test_bad_syntaxs
z$PyCompileCLITestCase.test_bad_syntaxcCsRtj�tj�t�d�}|�|j|�\}}}|�|d�|�|d�|�d|�dS)Nzshould_not_exists.pyr�r�sNo such file or directory)	r0r3r4rfrgr�r5rtr�)r@Zshould_not_existsr�r�r�r
r
r�test_file_not_exists
s
z)PyCompileCLITestCase.test_file_not_existsN)r%r&r'rBrGr�r�r�r�r�r�r
r
r
rr��s
r��__main__)r�importlib.utilr7r0rHrDr]r�r{r.r�rmrZtest.supportrrr�typeZTestCaserr)r�r�r�r%�mainr
r
r
r�<module>s:��6