Your IP : 216.73.216.147


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

U

i�f�Q�@s(dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZmZm
Z
mZmZmZmZmZddlZddlZddlZzddlZWnek
r�dZYnXe�ejejkp�ejejkd�Zddd�ZGdd�dej�Z Gd	d
�d
e �Z!eGdd�de ��Z"e#d
k�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_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@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
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__�__doc__ZmaxDiffr8r;rBrDrJrrrrr0src	@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�|��dSr9)rD�
assertTruer&r'�isdir)r6r>�fnrrrrQ[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.
        �lib64�P��posix�darwin�
pyvenv.cfgz	home = %s�Contents of %r:�    %r�File %r should exist.N)rr*rB�venv�createrQr,r#r rD�structZcalcsizer&r+r-r2rPr'�islink�assertFalser4rJr/�dirname�assertInr1�print�listdir)r6rZ
conditions�datar7r'rR�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�rXz(%s) z	prompt = z	My prompt)�promptz(My prompt) zprompt = 'My prompt'
)r&r'r0r*rr\�
EnvBuilderrBr]Zensure_directoriesrJ�assertEqualriZassertNotInrb)r6Zenv_name�builder�contextrerrr�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)	z>
        Test that the prefix values are as expected.
        �-cN�prefix�exec_prefix�base_prefix�base_exec_prefixzimport sys; print(sys.%s)r")rr*rBr\r]r&r'rCr,r1r-rrrsrrk�strip�encode)r6�envpyrrpZexpectedrrrrr�
test_prefixes�s

�zBasicTest.test_prefixesr%))r)rr)r�
site-packages)r)r#)r r r!Nr"rxc
CsZ|D]P}tjj|jf|��}t�|�tj�||�}t|d��}|�d�W5QRXqdS)zn
        Create some files in the environment which are unrelated
        to the virtual environment.
        �wb�Still here?N)r&r'rCr*�mkdirrF�write)r6�paths�filename�subdirs�drRrHrrr�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)zE
        Test creating environment in an existing directory.
        �foo)r��rbrzT��clearN)r��ENV_SUBDIRSr\r]r*r&r'rCrPr4rFrkrGrjr`)r6rrRrHrlrrr�test_overwrite_existing�s

z!BasicTest.test_overwrite_existingcCsZt�|�D]J}tj�||�}tj�|�s4tj�|�r@t�|�q
tj�|�r
t|�q
dSr9)	r&rdr'rCr_�isfile�removerQr)r6r'rRrrr�clear_directory�szBasicTest.clear_directoryc
Csn|jdd�D]Z}tjj|jf|��}t|d��}|�d�W5QRX|�tt	ft
j|j�|�|j�qdS)N�ry�)
r�r&r'rCr*rFr|ZassertRaises�
ValueError�OSErrorr\r]r�)r6r}rRrHrrr�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)zC
        Test upgrading an existing environment directory.
        �FT)�upgraderYrZr[N)r\rjrBr]r*rQr,r#r rDr1r&r'r4rcrdrP)r6r�rlrRrfrrr�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_packagesrXz"include-system-site-packages = %s
N)r\rjr]r*rJrb)r6Zssp�srlrerrr�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)
r\rjr]r*rDr,r1r5r`r&r'r_rP)r6ZuslrlrRrrr�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.
        ro�!import sys; print(sys.executable)N)rr*rBr\r]r&r'rCr(r,r1rrkrtru�r6rvrrrrr�test_executables
��
zBasicTest.test_executablecCslt|j�tjddd�}|�|j�tj�tj�|j�|j	|j
�}t|ddg�\}}|�|�
�|���dS)r�Tr�ror�N�rr*r\rjr]r&r'rCr(r,r1rrkrtru�r6rlrvrrrrr�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)z0
        Test handling of Unicode paths
        uϼўТλФЙTr�zactivate.bat�&rozprint(0)Zoem)r�0N)rr*r&r'rCr(r\rjr]r,r1rrkrt)r6r*rl�activatervrrrrr�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)zA
        Test that the multiprocessing is able to spawn.
        rozrfrom multiprocessing import Pool; pool = Pool(1); print(pool.apply_async("Python".lower).get(3)); pool.terminate()�pythonN)r	rr*rBr\r]r&r'rCr(r,r1rrkrtrur�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\rjr]r&r'rCr,rFr|rrkru)r6r�rlr�Ztest_scriptrHrrrrr�%test_deactivate_with_strict_bash_optsXs


z/BasicTest.test_deactivate_with_strict_bash_optsrWzonly relevant on macOScCsft|j�t��}|�|j�tj�tj�|j�|j	|j
�}t|ddg�\}}|�|�
�d���dS)Nroz5import os; print("__PYVENV_LAUNCHER__" in os.environ)�Falser�r�rrr�test_macos_envks
��
zBasicTest.test_macos_env) rKrLrMrNrQrgrn�requireVenvCreaterwr-r2r�r.r�r�r�r�r�r��unittest�
skipUnlessrr�r�r�r&r+r�r�ZskipIfr�r�rrrrrOXsD

�	







rOc@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)Nroz1try:
 import pip
except ImportError:
 print("OK")�latin-1r�ZOK)r&r'rCr(r*r,r1r�decoderkrtr�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&�devnullrkrGrPr'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'rCr{rFr|rBr\r]r
rr@r�Zfail�formatr(r,r1rrk�	ensurepip�version�len�fsencoderb�re�sub�	MULTILINE�rstripr�)r6r�ZenvvarsZhome_dirZ
bad_configZwin_locationZposix_locationraZfname�dirpathZfpathrH�excZdetails�msgrvrrZexpected_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)rKrLrMrNr�r�r�r�r�r�r��ctypesrr�rrrrr�ws

Z
r��__main__)N)%rNr�r&Zos.pathr�r�r^r
r-r)Ztest.supportrrrrrrrr	Z	threadingr�r\r��ImportErrorr�rprrr/r7r�rZTestCaserrOr�rK�mainrrrr�<module>s@(

�
(!