Your IP : 216.73.216.213


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



��Yf�E�@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
mZmZm
Z
mZddlZddlZddlZyddlZWnek
r�dZYnXyddlZWnek
rdZYnXyddlZWnek
r2dZYnXejejejkd�Zejj�dkrrejZndd�ZGdd	�d	ej�ZGd
d�de�Z eGdd
�d
e��Z!e"dkr�ej#�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�can_symlink�EnvironmentVarGuard�rmtreezTest not appropriate in a venvZnulcCs|S)N�)�frr�3/opt/alt/python35/lib64/python3.5/test/test_venv.py�failsOnWindows.sr
c@sReZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�BaseTestzBase class for venv tests.cCs�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�tempfileZmkdtemp�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)�openr1�read)r&r+r�resultrrr	�get_text_file_contentsPszBaseTest.get_text_file_contentsN)	�__name__�
__module__�__qualname__�__doc__r'r(r/r1r6rrrr	r1src	@s:eZdZdZdd�Zdd�Zedd��Zej	dkrTd*Z
nFd+d,d-ddejdd�fddejdd�dffZ
dd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zeje�d�d d!��Zed"d#��Zeje�d�d$d%��ZdS).�	BasicTestzTest venv module functionality.cGs,|j|�}|jtjj|��dS)N)r1�
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|�dS)
zB
        Test the create function with default arguments.
        �lib64�P��posixrz
pyvenv.cfgrz	home = %szContents of %r:z    %rzFile %r should exist.N)rrr/�venv�creater=rrrr1�structZcalcsizerrrr!r<r�islink�assertFalse�existsr6r"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|dtjd	tj�}|j�\}}|j|j�|j��q�WdS)
z>
        Test that the prefix values are as expected.
        z-cN�prefix�base_prefix�base_exec_prefixzimport sys; print(sys.%s)��stdout�stderr)�assertEqualrrRrQrS�exec_prefixrrr/rCrDrrr0rr%�
subprocess�Popen�PIPE�communicate�strip�encode)r&�envpy�cmdrQZexpectedrM�out�errrrr	�
test_prefixes|s 
!zBasicTest.test_prefixes�win32r
rr�
site-packagesrrrzpython%d.%dNrTc
Csuxn|D]f}tjj|j|�}tj|�tjj||�}t|d��}|jd�WdQRXqWdS)zn
        Create some files in the environment which are unrelated
        to the virtual environment.
        �wbsStill here?N)rrr0r�mkdirr3�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)	zE
        Test creating environment in an existing directory.
        �foo�rbsStill here?N�clearT)rn)rn)rm�ENV_SUBDIRSrCrDrrrr0r<rHr3rWr4�
EnvBuilderrG)r&rkr>r�builderrrr	�test_overwrite_existing�s!z!BasicTest.test_overwrite_existingcCs�x|tj|�D]k}tjj||�}tjj|�sOtjj|�r_tj|�qtjj|�rt|�qWdS)N)	rrLrr0rF�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)Nrrf�)
rqrrr0rr3rhZassertRaises�
ValueError�OSErrorrCrDrw)r&rir>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)	zC
        Test upgrading an existing environment directory.
        FT�upgradezContents of %r:z    %rzFile %r should exist.N)FT)rCrrr/rDrr=rrrr1r%rrrHrKrLr<)r&r|rsr>rOrrr	�test_upgrade�s
zBasicTest.test_upgradecCsfx_dD]W\}}tjddd|�}|j|j�|jd�}|jd||�qWd	S)
z:
        Test isolation from system site-packages
        T�trueF�falserp�system_site_packagesz
pyvenv.cfgz"include-system-site-packages = %s
N�Tr~�Fr)r�r�)rCrrrDrr6rJ)r&Zssp�srsrNrrr	�test_isolation�s
zBasicTest.test_isolationzNeeds symlinkscCstxmdD]e}tjddd|�}|j|j�|j|j|j�}|r|jtj	j
|��qWdS)z3
        Test symlinking works as expected
        FTrp�symlinksN)FT)rCrrrDrr1rr%r<rrrF)r&Zuslrsr>rrr	�test_symlinking�s
zBasicTest.test_symlinkingcCs�t|j�|jtj|j�tjjtjj|j�|j	|j
�}|ddg}tj|dtj
dtj
�}|j�\}}|j|j�|j��dS)zD
        Test that the sys.executable value is as expected.
        z-cz!import sys; print(sys.executable)rUrVN)rrr/rCrDrrr0rrr%rYrZr[r\rWr]r^)r&r_r`rMrarbrrr	�test_executables
-zBasicTest.test_executablecCs�t|j�tjdddd�}|j|j�tjjtjj|j�|j	|j
�}|ddg}tj|dtj
dtj
�}|j�\}}|j|j�|j��dS)	zD
        Test that the sys.executable value is as expected.
        rpTr�z-cz!import sys; print(sys.executable)rUrVN)rrrCrrrDrrr0rrr%rYrZr[r\rWr]r^)r&rsr_r`rMrarbrrr	�test_executable_symlinkss
-z"BasicTest.test_executable_symlinks�r
�r�r�rre)r�r�r�r�)r)r)r)r7r8r9r:r=rP�
skipInVenvrcrr!rq�version_informrtrwr{r}r��unittest�
skipUnlessrr�r�r�rrrr	r;Us. 	#	
!r;c@s�eZdZdZdd�Zdd�Zdd�Zedd	��Zd
d�Z	e
jedke
j�e
jed
�e
jed�dd����ZdS)�
EnsurePipTestz%Test venv module installation of pip.cCs�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-crUrVzlatin-1�ZOK)rrr0rrrr%rYrZr[r\�decoderWr])r&r_Z
try_importr`rMrarbrrr	�assert_pip_not_installed'sz&EnsurePipTest.assert_pip_not_installedcCs1t|j�|jtj|j�|j�dS)N)rrr/rCrDr�)r&rrr	�test_no_pip_by_default7s
z$EnsurePipTest.test_no_pip_by_defaultcCs7t|j�|jtj|jdd�|j�dS)N�with_pipF)rrr/rCrDr�)r&rrr	�test_explicit_no_pip<s
z"EnsurePipTest.test_explicit_no_pipc
CsR|jtjjtj��ttjd��}|j|j�d�WdQRXdS)Nrorx)r<rrrH�devnullr3rWr4)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	--versionrUrVzlatin-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�)%rrrrZTemporaryDirectoryrrr0rgr3rhr/rCrDrYZCalledProcessErrorr-r�Zfail�formatrrr%rZr[r\rW�	ensurepipr �len�fsencoderJ�re�sub�	MULTILINE�rstripr�)r&r�ZenvvarsZhome_dirZ
bad_configZwin_locationZposix_locationrIZfname�dirpathZfpathr�excZdetails�msgr_r`rMrarbZexpected_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)r7r8r9r:r�r�r�r
r�r�r��skipIf�sslr�Z_MISSING_SSL_MESSAGEr��	threading�ctypesr�rrrr	r�$s
[r��__main__)$r:r�rZos.pathr�rErYrrZtest.supportrrrrr�textwrapr�rCr��ImportErrorr�r�r�rQrRr�r��lowerZexpectedFailurer
ZTestCaserr;r�r7�mainrrrr	�<module>sF(


	$��