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_venv.cpython-39.opt-1.pyc

a

XC?h�f�@s2dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZm
Z
mZmZmZmZmZmZddlZddlZddlmZzddlZWney�dZYn0e�ejejkp�ejejkd�Zddd�Z Gdd	�d	ej!�Z"Gd
d�de"�Z#eGdd
�d
e"��Z$e%dk�r.e�&�dS)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�can_symlink�EnvironmentVarGuard�rmtree�
import_module�*skip_if_broken_multiprocessing_synchronize)�patchz:cannot run venv.create from within a venv on this platformcCsBtj|tjtj|d�}|��\}}|jr:t�|j|||��||fS)N)�stdout�stderr�encoding)�
subprocess�Popen�PIPEZcommunicate�
returncode�CalledProcessError)�cmdr
�p�out�err�r�3/opt/alt/python39/lib64/python3.9/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���|_tjdkr0d|_d|_d|_	n$d|_ddt
jdd�f|_d	|_	t
j}tj�
|�d
|_t
jdkr�tj�|�r�tj�|�s�d|_nd
|_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+�r7rrr�tearDownHszBaseTest.tearDownc	Osjt��D}t��}||i|��Wd�n1s20YWd�n1sP0Y|��|��fSr:)rr�getvalue)r7�func�args�kwargs�output�errorrrr�run_with_captureKsJzBaseTest.run_with_capturecGstjj|jg|�R�Sr:)r'r(�joinr+)r7r?rrr�get_env_fileQszBaseTest.get_env_filezutf-8�r
cGs@t|j|�d|d��}|��}Wd�n1s20Y|S)N�rrF)�openrE�read)r7r
r?�f�resultrrr�get_text_file_contentsTs&zBaseTest.get_text_file_contentscCs$|�|�s |�d|�d|���dS)NzString z does not end with )�endswith�fail)r7�string�tailrrr�assertEndsWithYs
zBaseTest.assertEndsWithN)�__name__�
__module__�__qualname__�__doc__ZmaxDiffr9r<rCrErLrQrrrrr1src	@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zed
d��Z	e
jdkrHd
Zn4ddddde
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�|��dSr:)rE�
assertTruer'r(�isdir)r7r?�fnrrrrX`s
zBasicTest.isdircCs$t|j�|�tj|j�|�|j�|�|j�|j|j�|�	d�}t
�d�dkohtj
dkohtjdk}|r�|�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+rC�venv�createrXr-r$r!rE�structZcalcsizer'r,r.r3rWr(�islink�assertFalser5rLr0�dirname�assertInr2�print�listdir)r7rZ
conditions�datar8r(rY�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(r1r+rrb�
EnvBuilderrCrc�ensure_directoriesrL�assertEqualroZassertNotInrh�basename�getcwd)r7�env_name�builder�contextrk�cwdrrr�test_prompt�s.





zBasicTest.test_promptc	s�t��}tjdkrdnd}tj�tj�d}t�	���}tj�
tj�|||���tjdkrltj�
tj�������fdd�}|�
|�}td|��|�|�Wd�n1s�0YWd�n1s�0YdS)Nr&rr rnc
s2tj�|d�|d<��|�ddddddg�dS)Nr�-m�pipZinstallz	--upgradeZ
setuptools)r'r(�normcasers)r�Z
expect_exer7rr�pip_cmd_checker�s��z<BasicTest.test_upgrade_dependencies.<locals>.pip_cmd_checkerzvenv.subprocess.check_call)rbrqr.r3r'r(r1r8r*�TemporaryDirectoryr}rDr)rrr
Zupgrade_dependencies)r7rwZbin_pathZ
python_exeZfake_env_dirrZ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]4\}}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+rCrbrcr'r(rDr-r2r.r�r�rrs�strip�encode)r7�envpyrr�Zexpectedrrrrr�
test_prefixes�s

�zBasicTest.test_prefixesr&))r)rr)r�
site-packages)r )r$)r!r!r"Nr#r�c	Csp|D]f}tjj|jg|�R�}t�|�tj�||�}t|d��}|�d�Wd�q1s`0YqdS)zn
        Create some files in the environment which are unrelated
        to the virtual environment.
        �wb�Still here?N)r'r(rDr+�mkdirrH�write)r7�paths�filename�subdirs�drYrJrrr�create_contents�s
zBasicTest.create_contentsc	Cs�|�|jd�t�|j�|jD]j}tjj|jg|d�R�}|�tj�	|��t
|d�� }|�|��d�Wd�q 1s�0Yq tj
dd�}|�|j�|jD]0}tjj|jg|d�R�}|�tj�	|��q�dS)zE
        Test creating environment in an existing directory.
        �foo)r��rbr�NT��clear)r��ENV_SUBDIRSrbrcr+r'r(rDrWr5rHrsrIrqrf)r7r�rYrJrwrrr�test_overwrite_existing�s
0
z!BasicTest.test_overwrite_existingcCsZt�|�D]J}tj�||�}tj�|�s4tj�|�r@t�|�q
tj�|�r
t|�q
dSr:)	r'rjr(rDre�isfile�removerXr)r7r(rYrrr�clear_directory�szBasicTest.clear_directoryc	Cs�|jdd�D]p}tjj|jg|�R�}t|d��}|�d�Wd�n1sR0Y|�tt	ft
j|j�|�|j�qdS)N�r��)
r�r'r(rDr+rHr�ZassertRaises�
ValueError�OSErrorrbrcr�)r7r�rYrJrrr�test_unoverwritable_failss(z#BasicTest.test_unoverwritable_failscCs�dD]�}tj|d�}|�|j|j�|�|j�|�|j�|j|j�|�	|j|j
�}tj�
|�s�|�	|j�}td|�tdt�|��|�tj�
|�d|�qdS)zC
        Test upgrading an existing environment directory.
        �FT)�upgrader_r`raN)rbrqrCrcr+rXr-r$r!rEr2r'r(r5rirjrW)r7r�rwrYrlrrr�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)rbrqrcr+rLrh)r7Zssp�srwrkrrr�test_isolation!s

zBasicTest.test_isolationzNeeds symlinkscCshdD]^}tjd|d�}|�|j�|�|j|j�}|r|jrP|�t	j
�|��q|�t	j
�|��qdS)z3
        Test symlinking works as expected
        r�T�r�ZsymlinksN)
rbrqrcr+rEr-r2r6rfr'r(rerW)r7ZuslrwrYrrr�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+rCrbrcr'r(rDr)r-r2rrsr�r��r7r�rrrrr�test_executableCs
��
zBasicTest.test_executablecCslt|j�tjddd�}|�|j�tj�tj�|j�|j	|j
�}t|ddg�\}}|�|�
�|���dS)r�Tr�r�r�N�rr+rbrqrcr'r(rDr)r-r2rrsr�r��r7rwr�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�n1s�0Yt||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
rrn�rr+�shutil�which�skipTestr'r(rDr)rbrqrcr-rHr��shlexZquoter�
splitlinesrWr�rQ)r7r�rvr+rwr��test_scriptrJrr�linesrrr�test_special_chars_bash_s 



6z!BasicTest.test_special_chars_bashcCst|j�t�d�pt�d�}|dur0|�d�d}tj�tj�|j�|�}t	j
dd�}|�|�tj�||jd�}tj�|jd	�}t
|d
��(}|�dt�|��d��Wd�n1s�0Yt||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�rrnr�)r7r�rvr+rwr�r�rJrrr�rrr�test_special_chars_cshys 


6z BasicTest.test_special_chars_cshzonly relevant on Windowsc

Cs�t|j�d}tj�tj�|j�|�}tjdd�}|�|�tj�||j	d�}tj�|jd�}t
|d��2}|�d|�d|j�d	|j�d
��Wd�n1s�0Yt
|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'])" & deactivateNrrn)rr+r'r(rDr)rbrqrcr-rHr�r2rr�rWr�rQ)
r7rvr+rwr�Z
test_batchrJrrr�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)ZoemrF�0N)rr+r'r(rDr)rbrqrcr-r2rrsr�)r7r+rwr�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)r	rr+rCrbrcr'r(rDr)r-r2rrsr�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�n1s�0Yt||g�\}}|�|d
���|�|d
���dS)Nr�r�Tr�r�ztest_strict.shr�zset -euo pipefail
source z
deactivate
�)r�r�r�rr+rbrqrcr'r(rDr-rHr�rrsr�)r7r�rwr�r�rJrrrrr�%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)$rRrSrTrUrXrmrzr��requireVenvCreater�r.r3r�r/r�r�r�r�r�r��unittest�
skipUnlessrr�r�r�ZskipIfr'r,r�r�r�r�r�r�r�rrrrrV]sR

�	









rVc@sReZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Ze	�
ed�e�d
d���Z
dS)�
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(rDr)r+r-r2r�decodersr�r�rrr�assert_pip_not_installed�s��


z&EnsurePipTest.assert_pip_not_installedcCs&t|j�|�tj|j�|��dSr:�rr+rCrbrcr�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�n1s20Y|�tj�tj��dS)Nr�r�)rHr'�devnullrsrIrWr(r5)r7rJrrr�test_devnull	s.zEnsurePipTest.test_devnullcCs�t|j�t���0}d|d<d|d<t����}||d<d}d}d}|fD]b\}}tj�||�}	t�|	�tj�|	|�}
t	|
d	��}|�
|�Wd�qH1s�0YqHz|jtj
|j|d
d�WnLtj�y}z0|jjdd
�}
d}|�|�||
��WYd}~n
d}~00Wd�n1�s*0YWd�n1�sJ0Ytj�tj�|j�|j|j�}t|ddddddg�\}}|�d�}|�|d�|�d�}d�t���}|�|dt|��|�t�|j��d�}|�||�t��(}t|dddddg�\}}Wd�n1�s&0Y|�d�}tjdd|tj d�}|�|�!�d�|�d�}|�d|�|�d|�|�s�|�"�dS)N�eZPYTHONWARNINGS�1ZPIP_NO_INSTALL�HOMEz[global]
no-install=1)r|zpip.ini)z.pipzpip.confr�T)r�r��replace)�errorsz{}

**Subprocess Output**
{}z-Wzignore::DeprecationWarningz-Ir{r|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*r�r'r(rDr�rHr�rCrbrcrrrAr�rN�formatr)r-r2rrs�	ensurepip�version�len�fsencoderh�re�sub�	MULTILINE�rstripr�)r7r�ZenvvarsZhome_dirZ
bad_configZwin_locationZposix_locationrgZfname�dirpathZfpathrJ�excZdetails�msgr�rrZexpected_versionr+rrr�do_test_with_pipsf



*�
h
�


�*
�
zEnsurePipTest.do_test_with_pipzpip requires ctypescCs|�d�|�d�dS)NFT)r�r;rrr�
test_with_pipms
zEnsurePipTest.test_with_pipN)rRrSrTrUr�r�r�r�r�r�r��ctypesrr�rrrrr��s

Z
r��__main__)N)'rUr�r'Zos.pathr�r�rdrr.r*r�Ztest.supportrrrrrrrr	r�rbZ
unittest.mockr
r��ImportErrorr�r�r�r0r8r�rZTestCaserrVr�rR�mainrrrr�<module>sD(

�
,