HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //proc/thread-self/root/usr/local/lib/python3.7/test/__pycache__/test_venv.cpython-37.pyc
B

��g�O�@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZmZm
Z
mZmZmZddlZddlZddlZyddlZWnek
r�dZYnXe�eed�p�ejejkd�Zddd�ZGdd	�d	ej�ZGd
d�de�ZeGdd
�d
e��Ze dk�re�!�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�_base_executablez: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�*/usr/local/lib/python3.7/test/test_venv.py�check_output#src@s<eZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
S)�BaseTestzBase class for venv tests.i�cCs�tj�t���|_tjdkr0d|_d|_d|_	n$d|_ddt
jdd�f|_d	|_	tt
d
t
j
�}tj�|�d|_t
jdkr�tj�|�r�tj�|�s�d
|_nd|_dS)N�nt�Scripts)�Lib�Include�bin�libzpython%d.%d��includer����win32TF)�os�path�realpath�tempfileZmkdtemp�env_dir�name�bindirrr �sys�version_info�getattr�
executable�split�exe�platform�lexists�exists�cannot_link_exe)�selfr-rrr�setUp2s

zBaseTest.setUpcCst|j�dS)N)rr')r4rrr�tearDownEszBaseTest.tearDownc
Os>t��"}t��}|||�WdQRXWdQRX|��|��fS)N)rr�getvalue)r4�func�args�kwargs�output�errorrrr�run_with_captureHszBaseTest.run_with_capturecGstjj|jf|��S)N)r#r$�joinr')r4r9rrr�get_env_fileNszBaseTest.get_env_filec	Gs(t|j|�d��}|��}WdQRX|S)N�r)�openr?�read)r4r9�f�resultrrr�get_text_file_contentsQszBaseTest.get_text_file_contentsN)
�__name__�
__module__�__qualname__�__doc__ZmaxDiffr5r6r=r?rErrrrr.src	@s:eZdZdZdd�Zdd�Zdd�Zedd	��Ze	j
d
kr@dZn4dd
ddde	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*��Zed+d,��Ze�ejd'kd-�d.d/��Ze�e	j
d0kd1�d2d3��ZdS)4�	BasicTestzTest venv module functionality.cGs |j|�}|�tj�|��dS)N)r?�
assertTruer#r$�isdir)r4r9�fnrrrrLYs
zBasicTest.isdircCs,t|j�|�tj|j�|�|j�|�|j�|j|j�|�	d�}t
�d�dkohtj
dkohtjdk}|r�|�tj�|��n|�tj�|��|�d�}ttdtj�}tj�|�}|�d||�|�	|j|j�}tj�|��s|�	|j�}td	|�td
t�|��|�tj�|�d|�dS)
zB
        Test the create function with default arguments.
        Zlib64�P��posix�darwinz
pyvenv.cfgrz	home = %szContents of %r:z    %rzFile %r should exist.N)rr'r=�venv�createrLr)r rr?�struct�calcsizer#r(r*r0rKr$�islink�assertFalser2rEr,r-�dirname�assertInr/�print�listdir)r4rZ
conditions�datar-r$rM�bdrrr�
test_defaults]s*



zBasicTest.test_defaultscCsbtj�|j�d}t��}|�|j�}|�|jd|�tjdd�}|�|j�}|�|jd�dS)N�z(%s) z	My prompt)�promptz(My prompt) )	r#r$r.r'rR�
EnvBuilderZensure_directories�assertEqualr`)r4Zenv_name�builder�contextrrr�test_promptyszBasicTest.test_promptcCs�t|j�|�tj|j�tj�|j|j|j	�}|ddg}x\d|jfd|jfdt
jfdt
jffD]4\}}d||d<t
|�\}}|�|��|���q`WdS)z>
        Test that the prefix values are as expected.
        z-cN�prefix�base_prefix�base_exec_prefixzimport sys; print(sys.%s)r)rr'r=rRrSr#r$r>r)r/r*rgrhrrb�strip�encode)r4�envpyrrfZexpectedrrrrr�
test_prefixes�s

zBasicTest.test_prefixesr"))r)r)r)rz
site-packages)r)r )rrzpython%d.%dNrz
site-packagesc
Cs^xX|D]P}tjj|jf|��}t�|�tj�||�}t|d��}|�d�WdQRXqWdS)zn
        Create some files in the environment which are unrelated
        to the virtual environment.
        �wbsStill here?N)r#r$r>r'�mkdirrA�write)r4�paths�filename�subdirs�drMrCrrr�create_contents�s

zBasicTest.create_contentsc
Cs�|�|jd�t�|j�x^|jD]T}tjj|jf|d��}|�tj�	|��t
|d��}|�|��d�WdQRXq"Wtj
dd�}|�|j�x8|jD].}tjj|jf|d��}|�tj�	|��q�WdS)zE
        Test creating environment in an existing directory.
        �foo)ru�rbsStill here?NT)�clear)rt�ENV_SUBDIRSrRrSr'r#r$r>rKr2rArbrBrarW)r4rrrMrCrcrrr�test_overwrite_existing�sz!BasicTest.test_overwrite_existingcCs^xXt�|�D]J}tj�||�}tj�|�s6tj�|�rBt�|�qtj�|�rt|�qWdS)N)	r#r[r$r>rV�isfile�removerLr)r4r$rMrrr�clear_directory�szBasicTest.clear_directoryc
Csrxl|jdd�D]Z}tjj|jf|��}t|d��}|�d�WdQRX|�tt	ft
j|j�|�|j�qWdS)N�rm�)
rxr#r$r>r'rAroZassertRaises�
ValueError�OSErrorrRrSr|)r4rprMrCrrr�test_unoverwritable_fails�sz#BasicTest.test_unoverwritable_failscCs�x�dD]�}tj|d�}|�|j|j�|�|j�|�|j�|j|j�|�	|j|j
�}tj�
|�s�|�	|j�}td|�tdt�|��|�tj�
|�d|�qWdS)zC
        Test upgrading an existing environment directory.
        )FT)�upgradezContents of %r:z    %rzFile %r should exist.N)rRrar=rSr'rLr)r rr?r/r#r$r2rZr[rK)r4r�rcrMr]rrr�test_upgrade�s
zBasicTest.test_upgradecCsJxDdD]<\}}tjd|d�}|�|j�|�d�}|�d||�qWdS)z:
        Test isolation from system site-packages
        ))T�true)FZfalseT)rw�system_site_packagesz
pyvenv.cfgz"include-system-site-packages = %s
N)rRrarSr'rErY)r4Zssp�srcr\rrr�test_isolation�s

zBasicTest.test_isolationzNeeds symlinkscCslxfdD]^}tjd|d�}|�|j�|�|j|j�}|r|jrR|�t	j
�|��q|�t	j
�|��qWdS)z3
        Test symlinking works as expected
        )FTT)rw�symlinksN)
rRrarSr'r?r)r/r3rWr#r$rVrK)r4ZuslrcrMrrr�test_symlinking�s
zBasicTest.test_symlinkingcCsbt|j�|�tj|j�tj�tj�|j�|j	|j
�}t|ddg�\}}|�|�
�|���dS)zD
        Test that the sys.executable value is as expected.
        z-cz!import sys; print(sys.executable)N)rr'r=rRrSr#r$r>r%r)r/rrbrirj)r4rkrrrrr�test_executable
s
zBasicTest.test_executablecCslt|j�tjddd�}|�|j�tj�tj�|j�|j	|j
�}t|ddg�\}}|�|�
�|���dS)zD
        Test that the sys.executable value is as expected.
        T)rwr�z-cz!import sys; print(sys.executable)N)rr'rRrarSr#r$r>r%r)r/rrbrirj)r4rcrkrrrrr�test_executable_symlinkss
z"BasicTest.test_executable_symlinksrzonly relevant on 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ϼўТλФЙT)rwzactivate.bat�&z-czprint(0)Zoem)r�0N)rr'r#r$r>r%rRrarSr)r/rrbri)r4r'rc�activaterkrrrrr�test_unicode_in_batch_file(s

z$BasicTest.test_unicode_in_batch_filecCsbt|j�|�tj|j�tj�tj�|j�|j	|j
�}t|ddg�\}}|�|�
�d���dS)zA
        Test that the multiprocessing is able to spawn.
        z-czrfrom multiprocessing import Pool; pool = Pool(1); print(pool.apply_async("Python".lower).get(3)); pool.terminate()ZpythonN)rr'r=rRrSr#r$r>r%r)r/rrbrirj)r4rkrrrrr�test_multiprocessing9s
zBasicTest.test_multiprocessingznot relevant on Windowsc	Cs�t�d�}|dkr|�d�t|j�tjdd�}|�|j�tj	�
|j|jd�}tj	�
|jd�}t|d��}|�
d|�d	��WdQRXt||g�\}}|�|d
���|�|d
���dS)N�bashzbash required for this testT)rwr�ztest_strict.sh�wzset -euo pipefail
source z
deactivate
�)�shutilZwhichZskipTestrr'rRrarSr#r$r>r)rArorrbrj)r4r�rcr�Ztest_scriptrCrrrrr�%test_deactivate_with_strict_bash_optsIs


z/BasicTest.test_deactivate_with_strict_bash_optsrQzonly relevant on macOScCsft|j�t��}|�|j�tj�tj�|j�|j	|j
�}t|ddg�\}}|�|�
�d���dS)Nz-cz5import os; print("__PYVENV_LAUNCHER__" in os.environ)�False)rr'rRrarSr#r$r>r%r)r/rrbrirj)r4rcrkrrrrr�test_macos_env\s
zBasicTest.test_macos_env) rFrGrHrIrLr^re�requireVenvCreaterlr*r0rxr+rtryr|r�r�r��unittest�
skipUnlessrr�r�r�r#r(r�r�ZskipIfr�r�rrrrrJVs2
	

rJc@sPeZdZdZdd�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)Nz-cz1try:
 import pip
except ImportError:
 print("OK")zlatin-1r�ZOK)r#r$r>r%r'r)r/r�decoderbri)r4rkrrrrr�assert_pip_not_installedks

z&EnsurePipTest.assert_pip_not_installedcCs&t|j�|�tj|j�|��dS)N)rr'r=rRrSr�)r4rrr�test_no_pip_by_defaultxs
z$EnsurePipTest.test_no_pip_by_defaultcCs*t|j�|jtj|jdd�|��dS)NF)�with_pip)rr'r=rRrSr�)r4rrr�test_explicit_no_pip}s
z"EnsurePipTest.test_explicit_no_pipc	Csdttjd��}|�|��d�WdQRXtj��dkrL|�tj�tj��n|�	tj�tj��dS)Nrvr~Znul)
rAr#�devnullrbrB�lowerrWr$r2rK)r4rCrrr�test_devnull�s
zEnsurePipTest.test_devnullcCs:t|j�t���}d|d<d|d<t����}||d<d}d}d}xX|fD]N\}}tj�||�}	t�|	�tj�|	|�}
t	|
d	��}|�
|�WdQRXqHWy|jtj
|j|d
d�WnHtjk
r�}z(|jjdd
�}
d}|�|�||
��Wdd}~XYnXWdQRXWdQRXtj�tj�|j�|j|j�}t|ddddddg�\}}|�d�}|�|d�|�d�}d�t���}|�|dt|��|�t�|j��d�}|�||�t��}t|dddddg�\}}WdQRX|�d�}tjdd|tj d�}|�|�!�d�|�d�}|�d|�|�d|�|�s6|�"�dS)N�eZPYTHONWARNINGS�1ZPIP_NO_INSTALL�HOMEz[global]
no-install=1)�pipzpip.ini)z.pipzpip.confr�T)r�r��replace)�errorsz{}

**Subprocess Output**
{}z-Wzignore::DeprecationWarningz-Iz-mr�z	--versionzlatin-1r�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&ZTemporaryDirectoryr#r$r>rnrAror=rRrSrrr;r�Zfail�formatr%r)r/rrb�	ensurepip�version�len�fsencoderY�re�sub�	MULTILINE�rstripr�)r4r��envvarsZhome_dirZ
bad_configZwin_locationZposix_locationrXZfname�dirpathZfpathrC�excZdetails�msgrkrrZexpected_versionr'rrr�do_test_with_pip�s^


8




zEnsurePipTest.do_test_with_pipzpip requires ctypescCs|�d�|�d�dS)NFT)r�)r4rrr�
test_with_pip�s
zEnsurePipTest.test_with_pipN)rFrGrHrIr�r�r�r�r�r�r��ctypesrr�rrrrr�hs
Z
r��__main__)N)"rIr�r#Zos.pathr�r�rTrr*r&Ztest.supportrrrrrrZ	threadingr�rRr��ImportErrorr��hasattrrfrgr�rZTestCaserrJr�rF�mainrrrr�<module>s> 



(