Your IP : 216.73.216.196


Current Path : /opt/alt/python310/lib64/python3.10/test/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/test/__pycache__/test_venv.cpython-310.opt-2.pyc

o

0�ii�@s>	ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZm
Z
mZmZddlmZmZmZddlZddlZddlmZzddlZWneybdZYnwe�ejejkppejejkd�Zddd�Z Gdd	�d	ej!�Z"Gd
d�de"�Z#eGdd
�d
e"��Z$e%dkr�e�&�dSdS)�N)�captured_stdout�captured_stderr�
requires_zlib�*skip_if_broken_multiprocessing_synchronize)�can_symlink�EnvironmentVarGuard�rmtree)�patchz:cannot run venv.create from within a venv on this platformcCsBtj|tjtj|d�}|��\}}|jrt�|j|||��||fS)N)�stdout�stderr�encoding)�
subprocess�Popen�PIPEZcommunicate�
returncode�CalledProcessError)�cmdr�p�out�err�r�5/opt/alt/python310/lib64/python3.10/test/test_venv.py�check_output&s�
�rc@sHeZdZ	dZdd�Zdd�Zdd�Zdd	�Zd
d�dd
�Zdd�Z	dS)�BaseTesti�cCs�tj�t���|_tjdkrd|_d|_d|_	nd|_ddt
jdd�f|_d	|_	t
j}tj�
|�d
|_t
jdkrLtj�|�rLtj�|�sLd|_dSd
|_dS)N�nt�Scripts��Lib�Include�bin�lib�python%d.%d��include����win32TF)�os�path�realpath�tempfileZmkdtemp�env_dir�name�bindirr r#�sys�version_info�_base_executable�split�exe�platform�lexists�exists�cannot_link_exe)�self�
executablerrr�setUp5s"


�
�

zBaseTest.setUpcCst|j�dS�N)rr*�r6rrr�tearDownHszBaseTest.tearDownc	Osjt��"}t��}||i|��Wd�n1swYWd�n1s(wY|��|��fSr9)rr�getvalue)r6�func�args�kwargs�output�errorrrr�run_with_captureKs���zBaseTest.run_with_capturecGstjj|jg|�R�Sr9)r&r'�joinr*)r6r>rrr�get_env_fileQszBaseTest.get_env_filezutf-8�rcGsBt|j|�d|d��
}|��}Wd�|S1swY|S)N�rrE)�openrD�read)r6rr>�f�resultrrr�get_text_file_contentsTs

��zBaseTest.get_text_file_contentscCs(|�|�s|�d|�d|���dSdS)NzString z does not end with )�endswith�fail)r6�string�tailrrr�assertEndsWithYs
�zBaseTest.assertEndsWithN)
�__name__�
__module__�__qualname__ZmaxDiffr8r;rBrDrKrPrrrrr1src	@s�eZdZ	dd�Zdd�Zdd�Zdd�Zed	d
��Ze	j
dkr#dZnd
dddde	jdd�fdde	jdd�dffZdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Ze�e�d!�d"d#��Zed$d%��Ze�e�d!�d&d'��Ze�ejd(kd)�d*d+��Ze�ejd(kd)�d,d-��Ze�ejd(kd.�d/d0��Ze�ejd(kd.�d1d2��Zed3d4��Z e�ejd(kd5�d6d7��Z!e�e	j
d8kd9�d:d;��Z"dS)<�	BasicTestcGs |j|�}|�tj�|��dSr9)rD�
assertTruer&r'�isdir)r6r>�fnrrrrV`s
zBasicTest.isdircCs$	t|j�|�tj|j�|�|j�|�|j�|j|j�|�	d�}t
�d�dko5tj
dko5tjdk}|rB|�tj�|��n	|�tj�|��|�d�}tj}tj�|�}|�d||�|�	|j|j�}tj�|�s�|�	|j�}td|�td	t�|��|�tj�|�d
|�dS)NZlib64�P��posix�darwin�
pyvenv.cfgz	home = %s�Contents of %r:�    %r�File %r should exist.)rr*rB�venv�createrVr,r#r rD�structZcalcsizer&r+r-r2rUr'�islink�assertFalser4rKr/�dirname�assertInr1�print�listdir)r6rZ
conditions�datar7r'rW�bdrrr�
test_defaultsds.

�
zBasicTest.test_defaultscCs0tj�|j�d}t|j�t��}|�|j|j�|�	|j�}|�
d�}|�|jd|�|�
d|�t|j�tjdd�}|�|j|j�|�	|j�}|�
d�}|�|jd�|�d|�t|j�tjd	d�}tj�t���}|�|j|j�|�	|j�}|�
d�}|�|jd|�|�d
||�dS)N�r\z(%s) z	prompt = z	My prompt)�promptz(My prompt) zprompt = 'My prompt'
�.zprompt = '%s'
)r&r'r0r*rr`�
EnvBuilderrBra�ensure_directoriesrK�assertEqualrmZassertNotInrf�basename�getcwd)r6�env_name�builder�contextri�cwdrrr�test_prompt�s.





zBasicTest.test_promptc	s�t��}tjdkrdnd}tj�tj�d}t�	��R}tj�
tj�|||���tjdkr6tj�
tj�������fdd�}|�
|�}td|��
|�|�Wd�n1sWwYWd�dSWd�dS1sowYdS)Nr%rrrlc
s2tj�|d�|d<��|�ddddddg�dS)Nr�-m�pipZinstallz	--upgradeZ
setuptools)r&r'�normcaserq)rr?�Z
expect_exer6rr�pip_cmd_checker�s��z<BasicTest.test_upgrade_dependencies.<locals>.pip_cmd_checkerzvenv.subprocess.check_output)r`ror-r2r&r'r0r7r)�TemporaryDirectoryr{rCr(rpr	Zupgrade_dependencies)r6ruZbin_pathZ
python_exeZfake_env_dirr}Zfake_contextrr|r�test_upgrade_dependencies�s"
�

��"�z#BasicTest.test_upgrade_dependenciescCs�	t|j�|�tj|j�tj�|j|j|j	�}|ddg}d|jfd|jfdt
jfdt
jffD]\}}d||d<t
|�\}}|�|��|���q0dS)N�-c�prefix�exec_prefix�base_prefix�base_exec_prefixzimport sys; print(sys.%s)r")rr*rBr`rar&r'rCr,r1r-r�r�rrq�strip�encode)r6�envpyrr�Zexpectedrrrrr�
test_prefixes�s

��zBasicTest.test_prefixesr%))r)rr)r�
site-packages)r)r#)r r r!Nr"r�c	Csr	|D]3}tjj|jg|�R�}t�|�tj�||�}t|d��
}|�d�Wd�n1s1wYqdS)N�wb�Still here?)r&r'rCr*�mkdirrG�write)r6�paths�filename�subdirs�drWrIrrr�create_contents�s
���zBasicTest.create_contentsc	Cs�	|�|jd�t�|j�|jD]5}tjj|jg|d�R�}|�tj�	|��t
|d��}|�|��d�Wd�n1sAwYqtj
dd�}|�|j�|jD]}tjj|jg|d�R�}|�tj�	|��qVdS)N�foo)r��rbr�T��clear)r��ENV_SUBDIRSr`rar*r&r'rCrUr4rGrqrHrord)r6r�rWrIrurrr�test_overwrite_existing�s 
��
�z!BasicTest.test_overwrite_existingcCsZt�|�D]%}tj�||�}tj�|�stj�|�r t�|�qtj�|�r*t|�qdSr9)	r&rhr'rCrc�isfile�removerVr)r6r'rWrrr�clear_directory�s��zBasicTest.clear_directoryc	Cs�|jdd�D]8}tjj|jg|�R�}t|d��
}|�d�Wd�n1s)wY|�tt	ft
j|j�|�|j�qdS)N�r��)
r�r&r'rCr*rGr�ZassertRaises�
ValueError�OSErrorr`rar�)r6r�rWrIrrr�test_unoverwritable_failss��z#BasicTest.test_unoverwritable_failscCs�	dD]Q}tj|d�}|�|j|j�|�|j�|�|j�|j|j�|�	|j|j
�}tj�
|�sH|�	|j�}td|�tdt�|��|�tj�
|�d|�qdS)N�FT)�upgrader]r^r_)r`rorBrar*rVr,r#r rDr1r&r'r4rgrhrU)r6r�rurWrjrrr�test_upgrades�zBasicTest.test_upgradecCsH	dD]\}}tjd|d�}|�|j�|�d�}|�d||�qdS)N))T�true)FZfalseT)r��system_site_packagesr\z"include-system-site-packages = %s
)r`rorar*rKrf)r6Zssp�srurirrr�test_isolation!s
�zBasicTest.test_isolationzNeeds symlinkscCsj	dD]/}tjd|d�}|�|j�|�|j|j�}|r2|jr)|�t	j
�|��q|�t	j
�|��qdS)Nr�T�r�Zsymlinks)
r`rorar*rDr,r1r5rdr&r'rcrU)r6ZuslrurWrrr�test_symlinking+s��zBasicTest.test_symlinkingcCsd	t|j�|�tj|j�tj�tj�|j�|j	|j
�}t|ddg�\}}|�|�
�|���dS)Nr��!import sys; print(sys.executable))rr*rBr`rar&r'rCr(r,r1rrqr�r��r6r�rrrrr�test_executableCs
�
�zBasicTest.test_executablecCsn	t|j�tjddd�}|�|j�tj�tj�|j�|j	|j
�}t|ddg�\}}|�|�
�|���dS)NTr�r�r��rr*r`rorar&r'rCr(r,r1rrqr�r��r6rur�rrrrr�test_executable_symlinksPs
�
�z"BasicTest.test_executable_symlinksrz&contains invalid characters on WindowscCs	t|j�t�d�}|dur|�d�d}tj�tj�|j�|�}t	j
dd�}|�|�tj�||jd�}tj�|jd�}t
|d��}|�d	t�|��d
��Wd�n1sZwYt||g�\}}	|��}
|�|��|
dv�|�|
d|���dS)
N�bash�bash required for this test�
"';&&$e|'"Tr��activateztest_special_chars.sh�w�source �r
python -c 'import sys; print(sys.executable)'
python -c 'import os; print(os.environ["VIRTUAL_ENV"])'
deactivate
rrl�rr*�shutil�which�skipTestr&r'rCr(r`rorar,rGr��shlexZquoter�
splitlinesrUr�rP)r6r�rtr*rur��test_scriptrIrr�linesrrr�test_special_chars_bash_s$



�z!BasicTest.test_special_chars_bashcCs	t|j�t�d�pt�d�}|dur|�d�d}tj�tj�|j�|�}t	j
dd�}|�|�tj�||jd�}tj�|jd�}t
|d	��}|�d
t�|��d��Wd�n1s_wYt||g�\}}	|��}
|�|��|
dv�|�|
d
|���dS)NZtcsh�cshzcsh required for this testr�Tr�zactivate.cshztest_special_chars.cshr�r�r�rrlr�)r6r�rtr*rur�r�rIrrr�rrr�test_special_chars_cshys$


�z BasicTest.test_special_chars_cshzonly relevant on Windowsc

Cs�	t|j�d}tj�tj�|j�|�}tjdd�}|�|�tj�||j	d�}tj�|jd�}t
|d��}|�d|�d|j�d	|j�d
��Wd�n1sQwYt
|g�\}}|��}	|�|��|	dv�|�|	d|���dS)
Nz'&&^$eTr��activate.batztest_special_chars.batr�z@echo off
"z" & z* -c "import sys; print(sys.executable)" & z> -c "import os; print(os.environ['VIRTUAL_ENV'])" & deactivaterrl)rr*r&r'rCr(r`rorar,rGr�r1rr�rUr�rP)
r6rtr*rur�Z
test_batchrIrrr�rrr�test_special_chars_windows�s*

����z$BasicTest.test_special_chars_windowscCs�	t|j�tj�tj�|j�d�}tjdd�}|�|�tj�||j	d�}tj�||j	|j
�}t|d|j
ddgdd	�\}}|�|�
�d
�dS)NuϼўТλФЙTr�r��&r�zprint(0)ZoemrE�0)rr*r&r'rCr(r`rorar,r1rrqr�)r6r*rur�r�rrrrr�test_unicode_in_batch_file�s


�z$BasicTest.test_unicode_in_batch_filecCsj	t�t|j�|�tj|j�tj�tj�	|j�|j
|j�}t|ddg�\}}|�
|��d���dS)Nr�zrfrom multiprocessing import Pool; pool = Pool(1); print(pool.apply_async("Python".lower).get(3)); pool.terminate()Zpython)rrr*rBr`rar&r'rCr(r,r1rrqr�r�r�rrr�test_multiprocessing�s
�
�zBasicTest.test_multiprocessingznot relevant on WindowscCs�t�d�}|dur|�d�t|j�tjdd�}|�|j�tj	�
|j|jd�}tj	�
|jd�}t|d��}|�
d|�d	��Wd�n1sJwYt||g�\}}|�|d
���|�|d
���dS)Nr�r�Tr�r�ztest_strict.shr�zset -euo pipefail
source z
deactivate
�)r�r�r�rr*r`rorar&r'rCr,rGr�rrqr�)r6r�rur�r�rIrrrrr�%test_deactivate_with_strict_bash_opts�s 


��z/BasicTest.test_deactivate_with_strict_bash_optsr[zonly relevant on macOScCsft|j�t��}|�|j�tj�tj�|j�|j	|j
�}t|ddg�\}}|�|�
�d���dS)Nr�z5import os; print("__PYVENV_LAUNCHER__" in os.environ)�Falser�r�rrr�test_macos_env�s
�
�zBasicTest.test_macos_env)#rQrRrSrVrkrxr�requireVenvCreater�r-r2r�r.r�r�r�r�r�r��unittest�
skipUnlessrr�r�r�ZskipIfr&r+r�r�r�r�r�r�r�rrrrrT]sT

�	









rTc@s^eZdZ	dd�Zdd�Zdd�Zdd�Zd	d
�Zej	dd��Z
e�e
d
�e�dd���ZdS)�
EnsurePipTestcCsdtj�tj�|j�|j|j�}t|ddg�\}}|�d�}|�	|d�|�d�}|�	|�
�d�dS)Nr�z1try:
 import pip
except ImportError:
 print("OK")�latin-1r�ZOK)r&r'rCr(r*r,r1r�decoderqr�r�rrr�assert_pip_not_installed�s�
�

z&EnsurePipTest.assert_pip_not_installedcCs&t|j�|�tj|j�|��dSr9�rr*rBr`rar�r:rrr�test_no_pip_by_default�s
z$EnsurePipTest.test_no_pip_by_defaultcCs*t|j�|jtj|jdd�|��dS)NF)�with_pipr�r:rrr�test_explicit_no_pips
z"EnsurePipTest.test_explicit_no_pipcCsTttjd��}|�|��d�Wd�n1swY|�tj�tj��dS)Nr�r�)rGr&�devnullrqrHrUr'r4)r6rIrrr�test_devnull	s�zEnsurePipTest.test_devnullcCs�t|j�t���}d|d<d|d<t���f}||d<d}d}d}|fD]1\}}tj�||�}	t�|	�tj�|	|�}
t	|
d	��
}|�
|�Wd�n1sOwYq#|���|jt
j|j|d
d�Wd�n1sowYWd�n1s~wYWd�n1s�wYtj�tj�|j�|j|j�}t|dd
ddddddg	�\}
}|�d�}|�|d�|
�d�}
d�t���}|�|
dt|��|�t�|j��d�}|�||
�t��/}|���d|d<t|dd
dddddg�\}
}Wd�n	1�swYWd�n	1�swY|�d�}tjdd|tjd�}|�|��d�|
�d�}
|�d|
�|�d|
�|�sN|��dSdS)N�ignoreZPYTHONWARNINGS�1ZPIP_NO_INSTALL�HOMEz[global]
no-install=1)rzzpip.ini)z.pipzpip.confr�T)r�r�z-Wzignore::DeprecationWarningzignore::ImportWarningz-Iryrzz	--versionr�r�zpip {}zensurepip._uninstallzl^(WARNING: )?The directory .* or its parent directory is not owned or is not writable by the current user.*$)�flagszSuccessfully uninstalled pipz#Successfully uninstalled setuptools) rr*rr)r~r&r'rCr�rGr��nicer_errorrBr`rar(r,r1rr�rq�format�	ensurepip�version�len�fsencoderf�re�sub�	MULTILINE�rstripr�)r6r�ZenvvarsZhome_dirZ
bad_configZwin_locationZposix_locationreZfname�dirpathZfpathrIr�rrZexpected_versionr*rrr�do_test_with_pips|


��
������#
�


����
�
�zEnsurePipTest.do_test_with_pipc
csx�	zdVWdStjy;}z&|jpdjdd�}|jpdjdd�}|�|�d|�d|���WYd}~dSd}~ww)Nr��replace)�errorsz

**Subprocess Output**
z

**Subprocess Error**
)r
rr@r�rrM)r6�excrrrrrr�ls ������zEnsurePipTest.nicer_errorzpip requires ctypescCs|�d�|�d�dS)NFT)r�r:rrr�
test_with_pip�s
zEnsurePipTest.test_with_pipN)rQrRrSr�r�r�r�r��
contextlib�contextmanagerr�r�r��ctypesrr�rrrrr��s

Y

r��__main__r9)'r�r�r&Zos.pathr�r�rbr
r-r)r�Ztest.supportrrrrZtest.support.os_helperrrrr�r`Z
unittest.mockr	r��ImportErrorr�r�r�r/r7r�rZTestCaserrTr�rQ�mainrrrr�<module>sN�
�
,�