Your IP : 216.73.216.213


Current Path : /proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/test_venv.cpython-34.pyo

�
g f�@�
@s�dZddlZddlZddlZddlZddlZddlZddlZddlm	Z	m
Z
mZmZm
Z
mZddlZddlZddlZyddlZWnek
r�dZYnXejejejkd�Zejj�dkrejZndd�ZGdd	�d	ej�ZGd
d�de�ZeGdd
�d
e��Zdd�Z e!dkr�e �ndS)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�run_unittest�can_symlink�EnvironmentVarGuard�rmtreezTest not appropriate in a venvZnulcCs|S)N�)�frr�3/opt/alt/python34/lib64/python3.4/test/test_venv.py�failsOnWindows#src@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
�setUp)s			 		zBaseTest.setUpcCst|j�dS)N)rr)r'rrr
�tearDown9szBaseTest.tearDowncOsGt��&}t��}|||�WdQXWdQX|j�|j�fS)N)rr�getvalue)r'�func�args�kwargs�output�errorrrr
�run_with_capture<szBaseTest.run_with_capturecGstjj|j|�S)N)rr�joinr)r'r,rrr
�get_env_fileBszBaseTest.get_env_filecGs1t|j|�d��}|j�}WdQX|S)N�r)�openr2�read)r'r,r	�resultrrr
�get_text_file_contentsEszBaseTest.get_text_file_contentsN)	�__name__�
__module__�__qualname__�__doc__r(r)r0r2r7rrrr
r&src	@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)r2�
assertTruerr�isdir)r'r,�fnrrr
r>MszBasicTest.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|��n|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)rrr0�venv�creater>rrrr2�structZcalcsizerrr r"r=r�islink�assertFalse�existsr7r#r$�dirname�assertInr&�print�listdir)r'�pZ
conditions�datar$rr?�bdrrr
�
test_defaultsQs0
$	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)�assertEqualr rSrRrT�exec_prefixrrr0rDrErrr1rr&�
subprocess�Popen�PIPE�communicate�strip�encode)r'�envpy�cmdrRZexpectedrN�out�errrrr
�
test_prefixesqs 
!zBasicTest.test_prefixes�win32rrr�
site-packagesrrrzpython%d.%dNrUc
Cstxm|D]e}tjj|j|�}tj|�tjj||�}t|d��}|jd�WdQXqWdS)zn
        Create some files in the environment which are unrelated
        to the virtual environment.
        �wbsStill here?N)rrr1r�mkdirr4�write)r'�paths�filename�subdirs�dr?r	rrr
�create_contents�s

zBasicTest.create_contentscCs	|j|jd�tj|j�xt|jD]i}tjj|j|d�}|jtjj	|��t
|d��}|j|j�d�WdQXq-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)ro)ro)rn�ENV_SUBDIRSrDrErrrr1r=rIr4rXr5�
EnvBuilderrH)r'rlr?r	�builderrrr
�test_overwrite_existing�s z!BasicTest.test_overwrite_existingcCs�xtj|�D]n}tjj||�}tjj|�sOtjj|�r_tj|�qtjj|�rt|�qqWdS)N)	rrMrr1rG�isfile�remover>r)r'rr?rrr
�clear_directory�s$zBasicTest.clear_directorycCs�x�|jdd�D]r}tjj|j|�}t|d��}|jd�WdQX|jtt	ft
j|j�|j|j�qWdS)Nrrg�)
rrrrr1rr4riZassertRaises�
ValueError�OSErrorrDrErx)r'rjr?r	rrr
�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|��n|jtjj
|�d|�qWdS)	zC
        Test upgrading an existing environment directory.
        FT�upgradezContents of %r:z    %rzFile %r should exist.N)FT)rDrsr0rErr>rrrr2r&rrrIrLrMr=)r'r}rtr?rPrrr
�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�falserqZsystem_site_packagesz
pyvenv.cfgz"include-system-site-packages = %s
N�Tztrue�Fr�)r�r�)rDrsrErr7rK)r'Zssp�srtrOrrr
�test_isolation�s
zBasicTest.test_isolationzNeeds symlinkscCswxpdD]h}tjddd|�}|j|j�|j|j|j�}|r|jtj	j
|��qqWdS)z3
        Test symlinking works as expected
        FTrq�symlinksN)FT)rDrsrErr2rr&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)zD
        Test that the sys.executable value is as expected.
        z-cz!import sys; print(sys.executable)rVrWN)rrr0rDrErrr1rrr&rZr[r\r]rXr^r_)r'r`rarNrbrcrrr
�test_executable�s
-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.
        rqTr�z-cz!import sys; print(sys.executable)rVrWN)rrrDrsrErrr1rrr&rZr[r\r]rXr^r_)r'rtr`rarNrbrcrrr
�test_executable_symlinks	s
-z"BasicTest.test_executable_symlinks�zScripts�zInclude��Lib�r�rf)r�r�r�r�)zbin)zinclude)zlib)r8r9r:r;r>rQ�
skipInVenvrdr r"rr�version_infornrurxr|r~r��unittestZ
skipUnlessrr�r�r�rrrr
r<Js. 	#	
!r<c@sseZdZdZdd�Zdd�Zdd�Zedd	��Ze	j
ed
kej
�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-crVrWzlatin-1�ZOK)rrr1rrrr&rZr[r\r]�decoderXr^)r'r`Z
try_importrarNrbrcrrr
�assert_pip_not_installedsz&EnsurePipTest.assert_pip_not_installedcCs1t|j�|jtj|j�|j�dS)N)rrr0rDrEr�)r'rrr
�test_no_pip_by_default,s
z$EnsurePipTest.test_no_pip_by_defaultcCs7t|j�|jtj|jdd�|j�dS)N�with_pipF)rrr0rDrEr�)r'rrr
�test_explicit_no_pip1s
z"EnsurePipTest.test_explicit_no_pipc
CsQ|jtjjtj��ttjd��}|j|j�d�WdQXdS)Nrpry)r=rrrI�devnullr4rXr5)r'r	rrr
� test_devnull_exists_and_is_empty6sz.EnsurePipTest.test_devnull_exists_and_is_emptyNc'Cs	t|j�t��A}d|d<d|d<tj��}||d<d}d}d}xs|fD]h\}}tjj||�}tj|�tjj||�}	t	|	d��}
|
j
|�WdQXqbWy |jtj
|jdd
�Wn\tjk
rL}z9|jjdd�}d}
|j|
j||��WYdd}~XnXWdQXWdQXtjjtjj|j�|j|j�}|dddg}tj|dtjdtj�}|j�\}}|jd�}|j|d�|jd�}djtj��}|j|dt|��|�tj|j�jd�}|j||�|ddg}t��:}tj|dtjdtj�}|j�\}}WdQX|jd�}|j|d�|jd�}|jd|�|jd|�|j �dS)N�eZPYTHONWARNINGS�1ZPIP_NO_INSTALL�HOMEz[global]
no-install=1�pip�pip.ini�.pip�pip.conf�wr�T�errors�replacez{}

**Subprocess Output**
{}z-Imz	--versionrVrWzlatin-1r�zpip {}zensurepip._uninstallzSuccessfully uninstalled pipz#Successfully uninstalled setuptools)r�r�)r�r�)!rrrrZTemporaryDirectoryrrr1rhr4rir0rDrErZZCalledProcessErrorr.r�Zfail�formatrrr&r[r\r]rX�	ensurepipr!�len�fsencoderKr�)r'ZenvvarsZhome_dirZ
bad_configZwin_locationZposix_locationrJZfname�dirpathZfpathr	�excZdetails�msgr`rarNrbrcZexpected_versionrrrr
�
test_with_pipAsZ




8- zEnsurePipTest.test_with_pip)r8r9r:r;r�r�r�rr�r��skipIf�sslr�Z_MISSING_SSL_MESSAGEr�rrrr
r�sr�cCsttt�dS)N)rr<r�rrrr
�	test_main�sr��__main__)"r;r�rZos.pathrFrZr rZtest.supportrrrrrr�textwrapr�rDr��ImportErrorr�rRrSr�r��lowerZexpectedFailurerZTestCaserr<r�r�r8rrrr
�<module>s6.
	$�w