Your IP : 216.73.216.213


Current Path : /opt/alt/python38/lib64/python3.8/test/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/test/__pycache__/test_venv.cpython-38.opt-2.pyc

U

i�f�Q�@s$ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
mZmZm
Z
mZmZmZmZddlZddlZddlZzddlZWnek
r�dZYnXe�ejejkp�ejejkd�Zd
dd�ZGdd�dej�ZGdd	�d	e�Z eGd
d�de��Z!e"dk�r e�#�dS)�N)�captured_stdout�captured_stderr�
requires_zlib�can_symlink�EnvironmentVarGuard�rmtree�
import_module�*skip_if_broken_multiprocessing_synchronizez: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/python38/lib64/python3.8/test/test_venv.py�check_output%s��rc@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�BaseTesti�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�setUp4s"


�
�zBaseTest.setUpcCst|j�dS�N)rr*�r6rrr�tearDownGszBaseTest.tearDownc
Os>t��"}t��}|||�W5QRXW5QRX|��|��fSr9)rr�getvalue)r6�func�args�kwargs�output�errorrrr�run_with_captureJszBaseTest.run_with_capturecGstjj|jf|��Sr9)r&r'�joinr*)r6r>rrr�get_env_filePszBaseTest.get_env_filec	Gs(t|j|�d��}|��}W5QRX|S)N�r)�openrD�read)r6r>�f�resultrrr�get_text_file_contentsSszBaseTest.get_text_file_contentsN)	�__name__�
__module__�__qualname__ZmaxDiffr8r;rBrDrJrrrrr0src	@s6eZdZdd�Zdd�Zdd�Zedd��Zej	d	kr<d
Z
n4ddd
ddejdd�fddejdd�dffZ
dd�Zdd�Z
dd�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�ej	d/kd0�d1d2��ZdS)3�	BasicTestcGs |j|�}|�tj�|��dSr9)rD�
assertTruer&r'�isdir)r6r>�fnrrrrP[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)N�lib64�P��posix�darwin�
pyvenv.cfgz	home = %s�Contents of %r:�    %r�File %r should exist.)rr*rB�venv�createrPr,r#r rD�structZcalcsizer&r+r-r2rOr'�islink�assertFalser4rJr/�dirname�assertInr1�print�listdir)r6rZ
conditions�datar7r'rQ�bdrrr�
test_defaults_s,

�
zBasicTest.test_defaultscCs�tj�|j�d}t|j�t��}|�|j|j�|�	|j�}|�
d�}|�|jd|�|�
d|�t|j�tjdd�}|�|j|j�|�	|j�}|�
d�}|�|jd�|�d|�dS)	N�rWz(%s) z	prompt = z	My prompt)�promptz(My prompt) zprompt = 'My prompt'
)r&r'r0r*rr[�
EnvBuilderrBr\Zensure_directoriesrJ�assertEqualrhZassertNotInra)r6Zenv_name�builder�contextrdrrr�test_prompt{s



zBasicTest.test_promptcCs�t|j�|�tj|j�tj�|j|j|j	�}|ddg}d|jfd|jfdt
jfdt
jffD]4\}}d||d<t
|�\}}|�|��|���q^dS)N�-c�prefix�exec_prefix�base_prefix�base_exec_prefixzimport sys; print(sys.%s)r")rr*rBr[r\r&r'rCr,r1r-rqrrrrj�strip�encode)r6�envpyrroZexpectedrrrrr�
test_prefixes�s

�zBasicTest.test_prefixesr%))r)rr)r�
site-packages)r)r#)r r r!Nr"rwc
CsZ|D]P}tjj|jf|��}t�|�tj�||�}t|d��}|�d�W5QRXqdS)N�wb�Still here?)r&r'rCr*�mkdirrF�write)r6�paths�filename�subdirs�drQrHrrr�create_contents�s
zBasicTest.create_contentsc
Cs�|�|jd�t�|j�|jD]T}tjj|jf|d��}|�tj�	|��t
|d��}|�|��d�W5QRXq tj
dd�}|�|j�|jD].}tjj|jf|d��}|�tj�	|��q�dS)N�foo)r��rbryT��clear)r��ENV_SUBDIRSr[r\r*r&r'rCrOr4rFrjrGrir_)r6r~rQrHrkrrr�test_overwrite_existing�s

z!BasicTest.test_overwrite_existingcCsZt�|�D]J}tj�||�}tj�|�s4tj�|�r@t�|�q
tj�|�r
t|�q
dSr9)	r&rcr'rCr^�isfile�removerPr)r6r'rQrrr�clear_directory�szBasicTest.clear_directoryc
Csn|jdd�D]Z}tjj|jf|��}t|d��}|�d�W5QRX|�tt	ft
j|j�|�|j�qdS)N�rx�)
r�r&r'rCr*rFr{ZassertRaises�
ValueError�OSErrorr[r\r�)r6r|rQrHrrr�test_unoverwritable_fails�sz#BasicTest.test_unoverwritable_failscCs�dD]�}tj|d�}|�|j|j�|�|j�|�|j�|j|j�|�	|j|j
�}tj�
|�s�|�	|j�}td|�tdt�|��|�tj�
|�d|�qdS)N�FT)�upgraderXrYrZ)r[rirBr\r*rPr,r#r rDr1r&r'r4rbrcrO)r6r�rkrQrerrr�test_upgrade�szBasicTest.test_upgradecCsFdD]<\}}tjd|d�}|�|j�|�d�}|�d||�qdS)N))T�true)FZfalseT)r��system_site_packagesrWz"include-system-site-packages = %s
)r[rir\r*rJra)r6Zssp�srkrdrrr�test_isolation�s

zBasicTest.test_isolationzNeeds symlinkscCshdD]^}tjd|d�}|�|j�|�|j|j�}|r|jrP|�t	j
�|��q|�t	j
�|��qdS)Nr�T�r�Zsymlinks)
r[rir\r*rDr,r1r5r_r&r'r^rO)r6ZuslrkrQrrr�test_symlinking�szBasicTest.test_symlinkingcCsbt|j�|�tj|j�tj�tj�|j�|j	|j
�}t|ddg�\}}|�|�
�|���dS)Nrn�!import sys; print(sys.executable))rr*rBr[r\r&r'rCr(r,r1rrjrsrt�r6rurrrrr�test_executables
��
zBasicTest.test_executablecCslt|j�tjddd�}|�|j�tj�tj�|j�|j	|j
�}t|ddg�\}}|�|�
�|���dS)NTr�rnr��rr*r[rir\r&r'rCr(r,r1rrjrsrt�r6rkrurrrrr�test_executable_symlinks$s
��
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)NuϼўТλФЙTr�zactivate.bat�&rnzprint(0)Zoem)r�0)rr*r&r'rCr(r[rir\r,r1rrjrs)r6r*rk�activaterurrrrr�test_unicode_in_batch_file2s

�
z$BasicTest.test_unicode_in_batch_filecCsht�t|j�|�tj|j�tj�tj�	|j�|j
|j�}t|ddg�\}}|�
|��d���dS)Nrnzrfrom multiprocessing import Pool; pool = Pool(1); print(pool.apply_async("Python".lower).get(3)); pool.terminate()�python)r	rr*rBr[r\r&r'rCr(r,r1rrjrsrtr�rrr�test_multiprocessingCs
��
zBasicTest.test_multiprocessingznot relevant on Windowsc	Cs�t�d�}|dkr|�d�t|j�tjdd�}|�|j�tj	�
|j|jd�}tj	�
|jd�}t|d��}|�
d|�d	��W5QRXt||g�\}}|�|d
���|�|d
���dS)N�bashzbash required for this testTr�r�ztest_strict.sh�wzset -euo pipefail
source z
deactivate
�)�shutilZwhichZskipTestrr*r[rir\r&r'rCr,rFr{rrjrt)r6r�rkr�Ztest_scriptrHrrrrr�%test_deactivate_with_strict_bash_optsXs


z/BasicTest.test_deactivate_with_strict_bash_optsrVzonly relevant on macOScCsft|j�t��}|�|j�tj�tj�|j�|j	|j
�}t|ddg�\}}|�|�
�d���dS)Nrnz5import os; print("__PYVENV_LAUNCHER__" in os.environ)�Falser�r�rrr�test_macos_envks
��
zBasicTest.test_macos_env)rKrLrMrPrfrm�requireVenvCreatervr-r2r�r.r�r�r�r�r�r��unittest�
skipUnlessrr�r�r�r&r+r�r�ZskipIfr�r�rrrrrNXsB

�	







rNc@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Ze�	e
d�edd
���ZdS)�
EnsurePipTestcCsdtj�tj�|j�|j|j�}t|ddg�\}}|�d�}|�	|d�|�d�}|�	|�
�d�dS)Nrnz1try:
 import pip
except ImportError:
 print("OK")�latin-1r�ZOK)r&r'rCr(r*r,r1r�decoderjrsr�rrr�assert_pip_not_installedzs��


z&EnsurePipTest.assert_pip_not_installedcCs&t|j�|�tj|j�|��dSr9�rr*rBr[r\r�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_pip�s
z"EnsurePipTest.test_explicit_no_pipc	Cs@ttjd��}|�|��d�W5QRX|�tj�tj��dS)Nr�r�)rFr&�devnullrjrGrOr'r4)r6rHrrr�test_devnull�szEnsurePipTest.test_devnullcCs6t|j�t���}d|d<d|d<t����}||d<d}d}d}|fD]N\}}tj�||�}	t�|	�tj�|	|�}
t	|
d	��}|�
|�W5QRXqFz|jtj
|j|d
d�WnHtjk
r�}z(|jjdd
�}
d}|�|�||
��W5d}~XYnXW5QRXW5QRXtj�tj�|j�|j|j�}t|ddddddg�\}}|�d�}|�|d�|�d�}d�t���}|�|dt|��|�t�|j��d�}|�||�t��}t|dddddg�\}}W5QRX|�d�}tjdd|tj d�}|�|�!�d�|�d�}|�d|�|�d|�|�s2|�"�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	--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)ZTemporaryDirectoryr&r'rCrzrFr{rBr[r\r
rr@r�Zfail�formatr(r,r1rrj�	ensurepip�version�len�fsencodera�re�sub�	MULTILINE�rstripr�)r6r�ZenvvarsZhome_dirZ
bad_configZwin_locationZposix_locationr`Zfname�dirpathZfpathrH�excZdetails�msgrurrZexpected_versionr*rrr�do_test_with_pip�sr


�
8
�


�
�
zEnsurePipTest.do_test_with_pipzpip requires ctypescCs|�d�|�d�dS)NFT)r�r:rrr�
test_with_pip�s
zEnsurePipTest.test_with_pipN)
rKrLrMr�r�r�r�r�r�r��ctypesrr�rrrrr�ws

Z
r��__main__)N)$r�r&Zos.pathr�r�r]r
r-r)Ztest.supportrrrrrrrr	Z	threadingr�r[r��ImportErrorr�rorqr/r7r�rZTestCaserrNr�rK�mainrrrr�<module>s>(

�
(!