Your IP : 216.73.217.32


Current Path : /opt/alt/python35/lib64/python3.5/test/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/__pycache__/test_venv.cpython-35.opt-2.pyc



���]�E�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	m
Z
mZmZm
Z
ddlZddlZddlZyddlZWnek
r�dZYnXyddlZWnek
rdZYnXyddlZWnek
r,dZYnXejejejkd�Zejj�dkrlejZndd�ZGdd�dej�ZGd	d
�d
e�ZeGdd�de��Z e!d
kr�ej"�dS)�N)�captured_stdout�captured_stderr�can_symlink�EnvironmentVarGuard�rmtreezTest not appropriate in a venvZnulcCs|S)N�)�frr�./opt/alt/python35/lib64/python3.5/test_venv.py�failsOnWindows.sr
c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�BaseTestcCs�tjjtj��|_tjdkrHd|_d
|_d|_	n2d|_ddt
jdd�f|_d	|_	t
jd
kr�dtj
kr�tj
d}n	t
j}tjj|�d|_dS)N�nt�Scripts�Lib�Include�bin�libzpython%s��include�darwin�__PYVENV_LAUNCHER__�)r���)�os�path�realpath�tempfile�mkdtemp�env_dir�name�bindirrr�sys�version�platform�environ�
executable�split�exe)�selfr$rrr	�setUp4s			 		zBaseTest.setUpcCst|j�dS)N)rr)r'rrr	�tearDownDszBaseTest.tearDowncOsIt��'}t��}|||�WdQRXWdQRX|j�|j�fS)N)rr�getvalue)r'�func�args�kwargs�output�errorrrr	�run_with_captureGszBaseTest.run_with_capturecGstjj|j|�S)N)rr�joinr)r'r,rrr	�get_env_fileMszBaseTest.get_env_filec	Gs2t|j|�d��}|j�}WdQRX|S)N�r)�openr2�read)r'r,r�resultrrr	�get_text_file_contentsPszBaseTest.get_text_file_contentsN)�__name__�
__module__�__qualname__r(r)r0r2r7rrrr	r1s
rc	@s4eZdZdd�Zdd�Zedd��ZejdkrNd)Z	nFd*d+d,ddej
dd�fddej
dd�dffZ	dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zeje�d�dd ��Zed!d"��Zeje�d�d#d$��ZdS)-�	BasicTestcGs,|j|�}|jtjj|��dS)N)r2�
assertTruerr�isdir)r'r,�fnrrr	r=XszBasicTest.isdircCs�t|j�|jtj|j�|j|j�|j|j�|j|j�|j	d�}t
jd�dko�tj
dko�tjdk}|r�|jtjj|��n|jtjj|��|jd�}tjdkr
dtjkr
tjd}n	tj}tjj|�}|jd||�|j	|j|j�}tjj|�s�|j	|j�}td	|�td
tj|��|jtjj|�d|�dS)N�lib64�P��posixrz
pyvenv.cfgrz	home = %szContents of %r:z    %rzFile %r should exist.)rrr0�venv�creater=rrrr2�struct�calcsizerrr r"r<r�islink�assertFalse�existsr7r#r$�dirname�assertInr&�print�listdir)r'�pZ
conditions�datar$rr>�bdrrr	�
test_defaults\s0
$	zBasicTest.test_defaultscCs'|jtjtj�|jtjtj�t|j�|jt	j
|j�tjj
|j|j|j�}|ddg}x�d|jfd|jfdtjfdtjffD]i\}}d||d<tj|dtjdtj�}|j�\}}|j|j�|j��q�WdS)	Nz-c�prefix�base_prefix�base_exec_prefixzimport sys; print(sys.%s)��stdout�stderr)�assertEqualr rSrRrT�exec_prefixrrr0rCrDrrr1rr&�
subprocess�Popen�PIPE�communicate�strip�encode)r'�envpy�cmdrRZexpectedrN�out�errrrr	�
test_prefixes|s 
!zBasicTest.test_prefixes�win32r
rr�
site-packagesrrrzpython%d.%dNrUc
Csuxn|D]f}tjj|j|�}tj|�tjj||�}t|d��}|jd�WdQRXqWdS)N�wbsStill here?)rrr1r�mkdirr4�write)r'�paths�filename�subdirs�dr>rrrr	�create_contents�s

zBasicTest.create_contentscCs
|j|jd�tj|j�xu|jD]j}tjj|j|d�}|jtjj	|��t
|d��}|j|j�d�WdQRXq-Wtj
dd�}|j|j�xF|jD];}tjj|j|d�}|jtjj	|��q�WdS)N�foo�rbsStill here?�clearT)ro)ro)rn�ENV_SUBDIRSrCrDrrrr1r<rIr4rXr5�
EnvBuilderrH)r'rlr>r�builderrrr	�test_overwrite_existing�s!z!BasicTest.test_overwrite_existingcCs�x|tj|�D]k}tjj||�}tjj|�sOtjj|�r_tj|�qtjj|�rt|�qWdS)N)	rrMrr1rG�isfile�remover=r)r'rr>rrr	�clear_directory�s$zBasicTest.clear_directorycCs�x�|jdd�D]s}tjj|j|�}t|d��}|jd�WdQRX|jtt	ft
j|j�|j|j�qWdS)Nrrg�)
rrrrr1rr4riZassertRaises�
ValueError�OSErrorrCrDrx)r'rjr>rrrr	�test_unoverwritable_fails�sz#BasicTest.test_unoverwritable_failscCs�x�dD]�}tjd|�}|j|j|j�|j|j�|j|j�|j|j�|j	|j|j
�}tjj
|�s�|j	|j�}td|�tdtj|��|jtjj
|�d|�qWdS)NFT�upgradezContents of %r:z    %rzFile %r should exist.)FT)rCrsr0rDrr=rrrr2r&rrrIrLrMr<)r'r}rtr>rPrrr	�test_upgrade�s
zBasicTest.test_upgradecCsfx_dD]W\}}tjddd|�}|j|j�|jd�}|jd||�qWdS)NT�trueF�falserq�system_site_packagesz
pyvenv.cfgz"include-system-site-packages = %s
�Tr�Fr�)r�r�)rCrsrDrr7rK)r'Zssp�srtrOrrr	�test_isolation�s
zBasicTest.test_isolationzNeeds symlinkscCstxmdD]e}tjddd|�}|j|j�|j|j|j�}|r|jtj	j
|��qWdS)NFTrq�symlinks)FT)rCrsrDrr2rr&r<rrrG)r'Zuslrtr>rrr	�test_symlinking�s
zBasicTest.test_symlinkingcCs�t|j�|jtj|j�tjjtjj|j�|j	|j
�}|ddg}tj|dtj
dtj
�}|j�\}}|j|j�|j��dS)Nz-cz!import sys; print(sys.executable)rVrW)rrr0rCrDrrr1rrr&rZr[r\r]rXr^r_)r'r`rarNrbrcrrr	�test_executables
-zBasicTest.test_executablecCs�t|j�tjdddd�}|j|j�tjjtjj|j�|j	|j
�}|ddg}tj|dtj
dtj
�}|j�\}}|j|j�|j��dS)NrqTr�z-cz!import sys; print(sys.executable)rVrW)rrrCrsrDrrr1rrr&rZr[r\r]rXr^r_)r'rtr`rarNrbrcrrr	�test_executable_symlinkss
-z"BasicTest.test_executable_symlinks�r
�r�r�rrf)r�r�r�r�)r)r)r)r8r9r:r=rQ�
skipInVenvrdr r"rr�version_infornrurxr|r~r��unittest�
skipUnlessrr�r�r�rrrr	r;Us, 	#	
!r;c@s�eZdZdd�Zdd�Zdd�Zedd��Zd	d
�Ze	j
edkej
�e	jed�e	jed
�dd����ZdS)�
EnsurePipTestcCs�tjjtjj|j�|j|j�}d}|d|g}tj|dtj	dtj	�}|j
�\}}|jd�}|j|d�|jd�}|j|j
�d�dS)Nz1try:
 import pip
except ImportError:
 print("OK")z-crVrWzlatin-1�ZOK)rrr1rrrr&rZr[r\r]�decoderXr^)r'r`Z
try_importrarNrbrcrrr	�assert_pip_not_installed'sz&EnsurePipTest.assert_pip_not_installedcCs1t|j�|jtj|j�|j�dS)N)rrr0rCrDr�)r'rrr	�test_no_pip_by_default7s
z$EnsurePipTest.test_no_pip_by_defaultcCs7t|j�|jtj|jdd�|j�dS)N�with_pipF)rrr0rCrDr�)r'rrr	�test_explicit_no_pip<s
z"EnsurePipTest.test_explicit_no_pipc
CsR|jtjjtj��ttjd��}|j|j�d�WdQRXdS)Nrpry)r<rrrI�devnullr4rXr5)r'rrrr	� test_devnull_exists_and_is_emptyAsz.EnsurePipTest.test_devnull_exists_and_is_emptyc)Cs=t|j�t��I}d|d<d|d<tj��}||d<d}d}d}xt|fD]i\}}tjj||�}	tj|	�tjj|	|�}
t	|
d��}|j
|�WdQRXqbWy&|jtj
|jd|d
d�Wn\tjk
rS}z9|jjdd�}
d}|j|j||
��WYdd}~XnXWdQRXWdQRXtjjtjj|j�|j|j�}|dddg}tj|dtjdtj�}|j�\}}|jd�}|j|d�|jd�}djtj��}|j|dt|��|�tj|j�jd�}|j||�|ddg}t��:}tj|dtjdtj�}|j�\}}WdQRX|jd�}t j!dd|dt j"�}|j|j#�d�|jd�}|jd|�|jd|�|s9|j$�dS) N�eZPYTHONWARNINGS�1ZPIP_NO_INSTALL�HOMEz[global]
no-install=1�pip�pip.ini�.pip�pip.conf�wr�r�T�errors�replacez{}

**Subprocess Output**
{}z-Imz	--versionrVrWzlatin-1r�zpip {}zensurepip._uninstallzN^The directory .* or its parent directory is not owned by the current user .*$�flagszSuccessfully uninstalled pipz#Successfully uninstalled setuptools)r�r�)r�r�)%rrrr�TemporaryDirectoryrrr1rhr4rir0rCrDrZ�CalledProcessErrorr.r�Zfail�formatrrr&r[r\r]rX�	ensurepipr!�len�fsencoderK�re�sub�	MULTILINE�rstripr�)r'r��envvarsZhome_dirZ
bad_configZwin_locationZposix_locationrJZfname�dirpathZfpathr�excZdetails�msgr`rarNrbrcZexpected_versionrrrr	�do_test_with_pipKsb




:- 	zEnsurePipTest.do_test_with_pipNz@some dependencies of pip import threading module unconditionallyzpip requires ctypescCs|jd�|jd�dS)NFT)r�)r'rrr	�
test_with_pip�s
zEnsurePipTest.test_with_pip)r8r9r:r�r�r�r
r�r�r��skipIf�sslr�Z_MISSING_SSL_MESSAGEr��	threading�ctypesr�rrrr	r�$s
[r��__main__)#r�rZos.pathr�rErZr rZtest.supportrrrrr�textwrapr�rCr��ImportErrorr�r�r�rRrSr�r��lowerZexpectedFailurer
ZTestCaserr;r�r8�mainrrrr	�<module>sD(


	$��