Your IP : 216.73.216.85


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.pyc

o

0�ii�@s@dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
mZmZmZddlmZmZmZddlZddlZddlmZzddlZWneycdZYnwe�e	je	jkpqe	je	jkd�Z ddd�Z!Gd	d
�d
ej"�Z#Gdd�de#�Z$e Gd
d�de#��Z%e&dkr�e�'�dSdS)z|
Test harness for the venv module.

Copyright (C) 2011-2012 Vinay Sajip.
Licensed to the PSF under a contributor agreement.
�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@sJeZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�d
d�Z	dd�Z
dS)�BaseTestzBase class for venv tests.i�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__�__doc__ZmaxDiffr8r;rBrDrKrPrrrrr1src	@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zed
d��Z	e
jdkr$d
Znddddde
j
dd�fdde
j
dd�dffZdd�Zdd�Zdd�Zdd�Zdd�Zd d!�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/�d0d1��Ze�ejd)kd/�d2d3��Z ed4d5��Z!e�ejd)kd6�d7d8��Z"e�e
jd9kd:�d;d<��Z#dS)=�	BasicTestzTest venv module functionality.cGs |j|�}|�tj�|��dSr9)rD�
assertTruer&r'�isdir)r6r>�fnrrrrW`s
zBasicTest.isdircCs"t|j�|�tj|j�|�|j�|�|j�|j|j�|�	d�}t
�d�dko4tj
dko4tjdk}|rA|�tj�|��n	|�tj�|��|�d�}tj}tj�|�}|�d||�|�	|j|j�}tj�|�s�|�	|j�}td|�td	t�|��|�tj�|�d
|�dS)zB
        Test the create function with default arguments.
        Zlib64�P��posix�darwin�
pyvenv.cfgz	home = %s�Contents of %r:�    %r�File %r should exist.N)rr*rB�venv�createrWr,r#r rD�structZcalcsizer&r+r-r2rVr'�islink�assertFalser4rKr/�dirname�assertInr1�print�listdir)r6rZ
conditions�datar7r'rX�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*rra�
EnvBuilderrBrb�ensure_directoriesrK�assertEqualrnZassertNotInrg�basename�getcwd)r6�env_name�builder�contextrj�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%rrrmc
s2tj�|d�|d<��|�ddddddg�dS)Nr�-m�pipZinstallz	--upgradeZ
setuptools)r&r'�normcaserr)rr?�Z
expect_exer6rr�pip_cmd_checker�s��z<BasicTest.test_upgrade_dependencies.<locals>.pip_cmd_checkerzvenv.subprocess.check_output)rarpr-r2r&r'r0r7r)�TemporaryDirectoryr|rCr(rqr	Zupgrade_dependencies)r6rvZbin_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
|�\}}|�|��|���q/dS)	z>
        Test that the prefix values are as expected.
        �-cN�prefix�exec_prefix�base_prefix�base_exec_prefixzimport sys; print(sys.%s)r")rr*rBrarbr&r'rCr,r1r-r�r�rrr�strip�encode)r6�envpyrr�Zexpectedrrrrr�
test_prefixes�s

��zBasicTest.test_prefixesr%))r)rr)r�
site-packages)r)r#)r r r!Nr"r�c	Csp|D]3}tjj|jg|�R�}t�|�tj�||�}t|d��
}|�d�Wd�n1s0wYqdS)zn
        Create some files in the environment which are unrelated
        to the virtual environment.
        �wb�Still here?N)r&r'rCr*�mkdirrG�write)r6�paths�filename�subdirs�drXrIrrr�create_contents�s
���zBasicTest.create_contentsc	Cs�|�|jd�t�|j�|jD]5}tjj|jg|d�R�}|�tj�	|��t
|d��}|�|��d�Wd�n1s@wYqtj
dd�}|�|j�|jD]}tjj|jg|d�R�}|�tj�	|��qUdS)zE
        Test creating environment in an existing directory.
        �foo)r��rbr�NT��clear)r��ENV_SUBDIRSrarbr*r&r'rCrVr4rGrrrHrpre)r6r�rXrIrvrrr�test_overwrite_existing�s
��
�z!BasicTest.test_overwrite_existingcCsZt�|�D]%}tj�||�}tj�|�stj�|�r t�|�qtj�|�r*t|�qdSr9)	r&rir'rCrd�isfile�removerWr)r6r'rXrrr�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�OSErrorrarbr�)r6r�rXrIrrr�test_unoverwritable_failss��z#BasicTest.test_unoverwritable_failscCs�dD]Q}tj|d�}|�|j|j�|�|j�|�|j�|j|j�|�	|j|j
�}tj�
|�sG|�	|j�}td|�tdt�|��|�tj�
|�d|�qdS)zC
        Test upgrading an existing environment directory.
        �FT)�upgrader^r_r`N)rarprBrbr*rWr,r#r rDr1r&r'r4rhrirV)r6r�rvrXrkrrr�test_upgrades�zBasicTest.test_upgradecCsFdD]\}}tjd|d�}|�|j�|�d�}|�d||�qdS)z:
        Test isolation from system site-packages
        ))T�true)FZfalseT)r��system_site_packagesr]z"include-system-site-packages = %s
N)rarprbr*rKrg)r6Zssp�srvrjrrr�test_isolation!s
�zBasicTest.test_isolationzNeeds symlinkscCshdD]/}tjd|d�}|�|j�|�|j|j�}|r1|jr(|�t	j
�|��q|�t	j
�|��qdS)z3
        Test symlinking works as expected
        r�T�r�ZsymlinksN)
rarprbr*rDr,r1r5rer&r'rdrV)r6ZuslrvrXrrr�test_symlinking+s��zBasicTest.test_symlinkingcCsbt|j�|�tj|j�tj�tj�|j�|j	|j
�}t|ddg�\}}|�|�
�|���dS)�D
        Test that the sys.executable value is as expected.
        r��!import sys; print(sys.executable)N)rr*rBrarbr&r'rCr(r,r1rrrr�r��r6r�rrrrr�test_executableCs
�
�zBasicTest.test_executablecCslt|j�tjddd�}|�|j�tj�tj�|j�|j	|j
�}t|ddg�\}}|�|�
�|���dS)r�Tr�r�r�N�rr*rarprbr&r'rCr(r,r1rrrr�r��r6rvr�rrrrr�test_executable_symlinksPs
�
�z"BasicTest.test_executable_symlinksrz&contains invalid characters on WindowscCst|j�t�d�}|dur|�d�d}tj�tj�|j�|�}t	j
dd�}|�|�tj�||jd�}tj�|jd�}t
|d	��}|�d
t�|��d��Wd�n1sYwYt||g�\}}	|��}
|�|��|
dv�|�|
d
|���dS)zK
        Test that the template strings are quoted properly (bash)
        �bashN�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
rrm�rr*�shutil�which�skipTestr&r'rCr(rarprbr,rGr��shlexZquoter�
splitlinesrVr�rP)r6r�rur*rvr��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
��}|�dt�|��d��Wd�n1s^wYt||g�\}}	|��}
|�|��|
d
v�|�|
d|���dS)zJ
        Test that the template strings are quoted properly (csh)
        Ztcsh�cshNzcsh required for this testr�Tr�zactivate.cshztest_special_chars.cshr�r�r�rrmr�)r6r�rur*rvr�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�n1sPwYt
|g�\}}|��}	|�|��|	dv�|�|	d
|���dS)zO
        Test that the template strings are quoted properly on Windows
        z'&&^$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'])" & deactivateNrrm)rr*r&r'rCr(rarprbr,rGr�r1rr�rVr�rP)
r6rur*rvr�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)z0
        Test handling of Unicode paths
        uϼўТλФЙTr�r��&r�zprint(0)ZoemrE�0N)rr*r&r'rCr(rarprbr,r1rrrr�)r6r*rvr�r�rrrrr�test_unicode_in_batch_file�s


�z$BasicTest.test_unicode_in_batch_filecCsht�t|j�|�tj|j�tj�tj�	|j�|j
|j�}t|ddg�\}}|�
|��d���dS)zA
        Test that the multiprocessing is able to spawn.
        r�zrfrom multiprocessing import Pool; pool = Pool(1); print(pool.apply_async("Python".lower).get(3)); pool.terminate()ZpythonN)rrr*rBrarbr&r'rCr(r,r1rrrr�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*rarprbr&r'rCr,rGr�rrrr�)r6r�rvr�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)$rQrRrSrTrWrlryr��requireVenvCreater�r-r2r�r.r�r�r�r�r�r��unittest�
skipUnlessrr�r�r�ZskipIfr&r+r�r�r�r�r�r�r�rrrrrU]sT

�	









rUc@s`eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Ze	j
dd
��Ze�
ed�e�dd���ZdS)�
EnsurePipTestz%Test venv module installation of pip.cCsdtj�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�decoderrr�r�rrr�assert_pip_not_installed�s�
�

z&EnsurePipTest.assert_pip_not_installedcCs&t|j�|�tj|j�|��dSr9�rr*rBrarbr�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&�devnullrrrHrVr'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)r{zpip.ini)z.pipzpip.confr�T)r�r�z-Wzignore::DeprecationWarningzignore::ImportWarningz-Irzr{z	--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)rr&r'rCr�rGr��nicer_errorrBrarbr(r,r1rr�rr�format�	ensurepip�version�len�fsencoderg�re�sub�	MULTILINE�rstripr�)r6r�ZenvvarsZhome_dirZ
bad_configZwin_locationZposix_locationrfZfname�dirpathZfpathrIr�rrZexpected_versionr*rrr�do_test_with_pips|


��
������#
�


����
�
�zEnsurePipTest.do_test_with_pipc
csv�zdVWdStjy:}z&|jpdjdd�}|jpdjdd�}|�|�d|�d|���WYd}~dSd}~ww)z�
        Capture output from a failed subprocess for easier debugging.

        The output this handler produces can be a little hard to read,
        but at least it has all the details.
        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)rQrRrSrTr�r�r�r�r��
contextlib�contextmanagerr�r�r��ctypesrr�rrrrr��s

Y

r��__main__r9)(rTr�r�r&Zos.pathr�r�rcr
r-r)r�Ztest.supportrrrrZtest.support.os_helperrrrr�raZ
unittest.mockr	r��ImportErrorr�r�r�r/r7r�rZTestCaserrUr�rQ�mainrrrr�<module>sN�
�
,�