Your IP : 216.73.216.213


Current Path : /opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/test/__pycache__/test_site.cpython-34.pyc

�
g f;K�@s�dZddlZddlZddlmZmZmZddlZddlZddl	Z	ddl
Z
ddlZddlZ
ddlZ
ddlZddlZddlmZe	jjr�ejd��nddlZejr"ejjej�r"ejej�ejej�nGdd�dej�ZGdd	�d	e�ZGd
d�dej�Z Gdd
�d
ej�Z!e"dkr�ej#�ndS)zTests for 'site'.

Tests assume the initial paths in sys.path once the interpreter has begun
executing have not been removed.

�N)�captured_stderr�TESTFN�EnvironmentVarGuard)�copyzPython was invoked with -Sc@seZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	de
dd�Zdd�Zdd�Z
ejejdkd�dd��Zdd�Zejejd�dd��Zdd�Zd d!�Zd"d#�Zd$S)%�HelperFunctionsTestsz Tests for helper functions.
    cCs\tjdd�|_tj|_tj|_tj|_	t
j|_t
t
j�|_dS)zSave a copy of sys.pathN)�sys�path�sys_path�site�	USER_BASE�old_base�	USER_SITE�old_site�PREFIXES�old_prefixes�	sysconfig�_CONFIG_VARS�
original_varsr�old_vars)�self�r�3/opt/alt/python34/lib64/python3.4/test/test_site.py�setUp&szHelperFunctionsTests.setUpcCsj|jtjdd�<|jt_|jt_|jt_	|j
t_tjj
�tjj|j�dS)zRestore sys.pathN)r	rrrr
rrr
rrrrr�clear�updater)rrrr�tearDown/s
zHelperFunctionsTests.tearDowncCs�d}tjj|�}tj|�\}}|jtjj|�|�|tjj|�krt|j||�n|jtjj|�|�dS)N�	Beginning�End)rr)�osr�joinr
�makepath�assertEqual�abspath�normcase)r�
path_partsZoriginal_dirZabs_dirZnorm_dirrrr�
test_makepath9sz"HelperFunctionsTests.test_makepathcCsNtj�}x;dd�tjD�D]#}|j||d||f�q#WdS)NcSs;g|]1}|rtjj|�rtj|�d�qS)�)rr�isdirr
r )�.0rrrr�
<listcomp>Hs	z;HelperFunctionsTests.test_init_pathinfo.<locals>.<listcomp>zB%s from sys.path not found in set returned by _init_pathinfo(): %s)r
�_init_pathinforr�assertIn)rZdir_set�entryrrr�test_init_pathinfoFs
z'HelperFunctionsTests.test_init_pathinfocCsc|j|jtjd|j�|jtj|j�dtj�|jt	jj
|j��dS)z>Contain common code for testing results of reading a .pth filez%s not in sys.modulesrN)r+�importedr�modulesr
r �
good_dir_pathr�assertFalser�exists�bad_dir_path)r�pth_filerrr�pth_file_testsNs#z#HelperFunctionsTests.pth_file_testsc
Csbt�}|jdd�z7|j�tj|j|jt��|j|�Wd|j�XdS)N�prepT)	�PthFile�cleanup�creater
�
addpackage�base_dir�filename�setr5)rr4rrr�test_addpackageUs	
z$HelperFunctionsTests.test_addpackage�.cs�tjj|�}|d}tjj||��t�ddd�}|j�fdd��|j|�|j�||fS)Nz.pth�w�encodingzutf-8cs
tj��S)N)r�remover)�pth_fnrr�<lambda>jsz/HelperFunctionsTests.make_pth.<locals>.<lambda>)rrr"r�openZ
addCleanup�write�close)r�contents�pth_dirZpth_nameZpth_basenamer4r)rCr�make_pthds


zHelperFunctionsTests.make_pthcCs�|jd�\}}t��}tj||t��WdQX|j|j�d�|j|j�tjt	j
j||���|j|j�d�|j|j�d�|j|j�d�dS)Nzimport bad)syntax
zline 1�	Tracebackzimport bad\)syntax�SyntaxError)rJrr
r:r=�assertRegex�getvalue�re�escaperrr)rrIrC�err_outrrr�!test_addpackage_import_bad_syntaxosz6HelperFunctionsTests.test_addpackage_import_bad_syntaxcCs�|jd�\}}t��}tj||t��WdQX|j|j�d�|j|j�tjt	j
j||���|j|j�d�|j|j�d�dS)Nzrandompath
import nosuchmodule
zline 2rK�ImportError)rJrr
r:r=rMrNrOrPrrr)rrIrCrQrrr�test_addpackage_import_bad_exec~sz4HelperFunctionsTests.test_addpackage_import_bad_exec�win32zIWindows does not raise an error for file paths containing null characterscCs�|jd�\}}t��}tj||t��WdQX|j|j�d�|j|j�tjt	j
j||���|j|j�d�|j|j�d�dS)NZabcdef
zline 1rK�	TypeError)rJrr
r:r=rMrNrOrPrrr)rrIrCrQrrr�#test_addpackage_import_bad_pth_file�sz8HelperFunctionsTests.test_addpackage_import_bad_pth_filec
Cs\t�}|jdd�z1|j�tj|jt��|j|�Wd|j�XdS)Nr6T)r7r8r9r
�
addsitedirr;r=r5)rr4rrr�test_addsitedir�s	
z$HelperFunctionsTests.test_addsitedirz<requires access to PEP 370 user-site (site.ENABLE_USER_SITE)cCs�tj}|j|tj�tjj�}tj	tj
dd|gd|�}|j|d�tjj�}tj	tj
ddd|gd|�}|tj�dkr�|j|d�n|j|d�tjj�}d|d<tj	tj
dd|gd|�}|tj�dkr7|j|d�n|j|d�tjj�}d	|d
<tj	tj
ddgd|�}|j|d�dS)Nz-cz$import sys; sys.exit(%r in sys.path)�envr&z-sr�1ZPYTHONNOUSERSITEz/tmp�PYTHONUSERBASEz=import sys, site; sys.exit(site.USER_BASE.startswith("/tmp")))
r
r
r+rrr�environr�
subprocess�call�
executabler!�getsitepackages)rZusersiterZ�rcrrr�
test_s_option�s8	
	
	

	
		z"HelperFunctionsTests.test_s_optionc
Cs�dt_tj�}|jtj|�dt_ddl}d|_t��6}d|d<|jtj�jd�tj��WdQXdS)Nr�xoxor\)	r
r�getuserbaser!rrr�
assertTrue�
startswith)r�	user_baserr]rrr�test_getuserbase�s			
z%HelperFunctionsTests.test_getuserbasecCsQdt_dt_tj�}|jtj|�|j|jtj�|�dS)N)r
r
r�getusersitepackagesr!rfrg)r�	user_siterrr�test_getusersitepackages�s
		z-HelperFunctionsTests.test_getusersitepackagescCs�dgt_tj�}tjdkr�tjd�r�dgt_tj�}|jt|�d�t	j
jdtjd�tjdd�d�}|j|d|�n*t	j
d	kr�|jt|�d�t	j
jdd
dtjdd�d�}|j|d|�t	j
jdd
dtjdd�d�}|j|d|�t	j
jdd
d�}|j|d|�nV|jt|�d�|j|dd�t	j
jdd
d�}|j|d|�dS)Nrd�darwin�PYTHONFRAMEWORKzPython.framework�z/Libraryz
site-packages��/�lib64�pythonr�libr&zsite-python)r
rrar�platformr�get_config_varr!�lenrrr�version�sep)r�dirsZwantedrrr�test_getsitepackages�s4	#	#	z)HelperFunctionsTests.test_getsitepackagesN)�__name__�
__module__�__qualname__�__doc__rrr%r-r5r>rrJrRrT�unittestZskipIfrrurWrY�
skipUnlessr
�ENABLE_USER_SITErcrirlr{rrrrr"s 	

'
!&	rc@sIeZdZdZeddddd�Zdd�Zd	d
d�ZdS)
r7z/Helper class for handling testing of .pth filesZtimeZ__testdir__Z__badcCs�|d|_tjjd�|_tjj|j|j�|_||_||_||_	tjj|j|j�|_
tjj|j|j	�|_dS)zInitialize instance variablesz.pth�N)r<rrr"r;r�	file_pathr.�good_dirname�bad_dirnamer0r3)r�
filename_baser.r�r�rrr�__init__	s
			zPthFile.__init__c
Cs�t|jd�}zatdd|�tdd|�td|jd|�t|jd|�t|jd|�Wd|j�Xtj|j	�dS)aoCreate a .pth file with a comment, blank lines, an ``import
        <self.imported>``, a line with self.good_dirname, and a line with
        self.bad_dirname.

        Creation of the directory for self.good_dir_path (based off of
        self.good_dirname) is also performed.

        Make sure to call self.cleanup() to undo anything done by this method.

        r@z#import @bad module name�file�
z	import %sN)
rEr��printr.r�r�rGr�mkdirr0)rZFILErrrr9szPthFile.createFcCs�tjj|j�r(tj|j�n|rbtjj|j�|_	|j	r�tj|j=q�n|j	r�|j	tj|j<ntjj|j
�r�tj|j
�ntjj|j�r�tj|j�ndS)z�Make sure that the .pth file is deleted, self.imported is not in
        sys.modules, and that both self.good_dirname and self.bad_dirname are
        not existing directories.N)
rrr2r�rBrr/�getr.Zimported_moduler0�rmdirr3)rr6rrrr8+s		zPthFile.cleanupN)r|r}r~rrr�r9r8rrrrr7s
r7c@seZdZdZdd�Zdd�Zdd�Zdd	�Zej	d
�dd��Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zejjd�ejjejejddkd�ejeejd�d�dd�����ZdS) �ImportSideEffectTestsz(Test side-effects from importing 'site'.cCstjdd�|_dS)zMake a copy of sys.pathN)rrr	)rrrrr@szImportSideEffectTests.setUpcCs|jtjdd�<dS)zRestore sys.pathN)r	rr)rrrrrDszImportSideEffectTests.tearDownc
Cs�tjjtjjtj��}tjj�}||d<d}dj|�}tj	t
jdd	|gd
|dtj�}|j
�\}}|j|jd�|j�dd
�\}}	|jtjj|��|jtjj|	��tj	t
jd	|gd
|dtj�}|j
�\}}|j|jd�|j�dd
�\}}	|jtjj|��|jtjj|	��dS)N�
PYTHONPATH�import os, sys�9os_file = os.__file__.encode("ascii", "backslashreplace")�(sys.stdout.buffer.write(os_file + b"\n")�=os_cached = os.__cached__.encode("ascii", "backslashreplace")�*sys.stdout.buffer.write(os_cached + b"\n")r�z-Sz-crZ�stdoutrrp)r�r�r�r�r�)rr�relpath�dirname�__file__r]rrr^�Popenrr`�PIPE�communicater!�
returncode�
splitlinesr1�isabsrf)
r�parentrZ�codeZcommand�procr��stderrZ
os__file__Zos__cached__rrr�test_abs_pathsHs2!
z$ImportSideEffectTests.test_abs_pathscCsHtj�t�}x.tjD]#}|j||�|j|�qWdS)N)r
�removeduppathsr=rr�assertNotIn�add)rZ
seen_pathsrrrr�test_no_duplicate_pathsns

	z-ImportSideEffectTests.test_no_duplicate_pathsztest not implementedcCsdS)Nr)rrrr�test_add_build_dirwsz(ImportSideEffectTests.test_add_build_dircCs0|jttd��|jttd��dS)N�quit�exit)rf�hasattr�builtins)rrrr�test_setting_quit~sz'ImportSideEffectTests.test_setting_quitcCsF|jttd��|jttd��|jttd��dS)N�	copyright�credits�license)rfr�r�)rrrr�test_setting_copyright�sz,ImportSideEffectTests.test_setting_copyrightcCs|jttd��dS)N�help)rfr�r�)rrrr�test_setting_help�sz'ImportSideEffectTests.test_setting_helpcCsxtjdkrtddl}|j�djd�rtx:tjjj�D]}|dkrGPqGqGW|jd�qtndS)NrUrr&�cp�mbcszdid not alias mbcs)	rru�localeZgetdefaultlocalerg�	encodings�aliases�values�fail)rr��valuerrr�test_aliasing_mbcs�sz(ImportSideEffectTests.test_aliasing_mbcscCsHdtjkrDyddl}Wntk
r3YqDX|jd�ndS)N�
sitecustomizerz(sitecustomize not imported automatically)rr/r�rSr�)rr�rrr�test_sitecustomize_executed�s
z1ImportSideEffectTests.test_sitecustomize_executedZnetworkro�finalzonly for released versionsZHTTPSHandlerz$need SSL support to download licensecCs�tjj�d}tjj|dd�}yDtjj|��,tjj	|��}|j
�}WdQXWdQXWn4tjjk
r�}z|j
}WYdd}~XnX|j|ddd|�dS)Nr&�methodZHEAD���msgzCan't find )r��_Printer__data�split�urllib�requestZRequest�test�supportZtransient_internetZurlopenZgetcode�errorZ	HTTPErrorr�r!)rZurlZreq�datar��errr�test_license_exists_at_url�s	z0ImportSideEffectTests.test_license_exists_at_urlN)r|r}r~rrrr�r�r��skipr�r�r�r�r�r�r�r�Zrequires_resourceZsystem_must_validate_certr�r�version_infor�r�r�r�rrrrr�=s"&	

	r�c@seZdZdd�ZdS)�StartupImportTestsc
CsDtjtjddddgdtjdtj�}|j�\}}|jd�}|jd�}t|�}|jd|�d	d
ddd
h}tj	dkr�|j
|j|�|�n|jd||�tj	dkr�|jd||�nddddddddddh
j
tj�}|j
|j|�|�dS)Nz-Iz-vz-cz#import sys; print(set(sys.modules))r�r�zutf-8r
rO�_sre�sre_compile�
sre_constants�	sre_parsermr��copyreg�_collections�collections�	functools�heapq�	itertools�keyword�operator�reprlib�types�weakref)r^r�rr`r�r��decode�evalr+rur1�intersectionr��
difference�builtin_module_names)r�popenr�r�r/Zre_modsZcollection_modsrrr�test_startup_imports�s(			z'StartupImportTests.test_startup_importsN)r|r}r~r�rrrrr��sr��__main__)$rr�Ztest.supportr�rrrr�rrrOr�Zurllib.requestr�Zurllib.errorr^rr�flags�no_siteZSkipTestr
r�rr'r
�makedirsrXZTestCaser�objectr7r�r�r|�mainrrrr�<module>s2�7x"