Your IP : 216.73.216.85


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



��Yf�L�@svdZddlZddlZddlmZmZmZddlZddlZddl	Z	ddl
Z
ddlZddlZ
ddlZ
ddlZddlZddlmZe	jjr�ejd��ddlZdadd�Zdd	�ZGd
d�dej�ZGdd
�d
e�ZGdd�dej�ZGdd�dej�Zedkrrej �dS)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 -ScCs�tjdd�atjr�tjjtj�r�y$tjtj�tj	tj�WnAt
k
r�}z!tjdtj|f��WYdd}~XnXdS)Nz-unable to create user site directory (%r): %s)
�sys�path�OLD_SYS_PATH�site�ENABLE_USER_SITE�os�isdir�	USER_SITE�makedirs�
addsitedir�PermissionError�unittest�SkipTest)�exc�r�3/opt/alt/python35/lib64/python3.5/test/test_site.py�setUpModule!s	rcCsttjdd�<dS)N)rrrrrrr�tearDownModule0src@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)rr�sys_pathr	�	USER_BASE�old_baser
�old_site�PREFIXES�old_prefixes�	sysconfig�_CONFIG_VARS�
original_varsr�old_vars)�selfrrr�setUp8szHelperFunctionsTests.setUpcCsj|jtjdd�<|jt_|jt_|jt_	|j
t_tjj
�tjj|j�dS)zRestore sys.pathN)rrrrr	rrr
rrr!rr �clear�updater")r#rrr�tearDownAs
zHelperFunctionsTests.tearDowncCs�d}tjj|�}tj|�\}}|jtjj|�|�|tjj|�krt|j||�n|jtjj|�|�dS)N�	Beginning�End)r(r))rr�joinr	�makepath�assertEqual�abspath�normcase)r#�
path_partsZoriginal_dirZabs_dirZnorm_dirrrr�
test_makepathKsz"HelperFunctionsTests.test_makepathcCsNtj�}x;dd�tjD�D]#}|j||d||f�q#WdS)NcSs;g|]1}|rtjj|�rtj|�d�qS)�)rrrr	r+)�.0rrrr�
<listcomp>Zs	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)r#Zdir_set�entryrrr�test_init_pathinfoXs
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)r5�importedr�modulesr	r+�
good_dir_pathr�assertFalser�exists�bad_dir_path)r#�pth_filerrr�pth_file_tests`s#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�setr?)r#r>rrr�test_addpackagegs	
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>|sz/HelperFunctionsTests.make_pth.<locals>.<lambda>)rrr-r*�openZ
addCleanup�write�close)r#�contents�pth_dirZpth_nameZpth_basenamer>r)rMr�make_pthvs


zHelperFunctionsTests.make_pthc
Cs�|jd�\}}t��}tj||t��WdQRX|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)rTrr	rDrG�assertRegex�getvalue�re�escaperrr*)r#rSrM�err_outrrr�!test_addpackage_import_bad_syntax�sz6HelperFunctionsTests.test_addpackage_import_bad_syntaxc
Cs�|jd�\}}t��}tj||t��WdQRX|j|j�d�|j|j�tjt	j
j||���|j|j�d�|j|j�d�dS)Nzrandompath
import nosuchmodule
zline 2rU�ImportError)rTrr	rDrGrWrXrYrZrrr*)r#rSrMr[rrr�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��WdQRX|j|j�d�|j|j�tjt	j
j||���|j|j�d�|j|j�d�dS)Nzabcdef
zline 1rU�
ValueError)rTrr	rDrGrWrXrYrZrrr*)r#rSrMr[rrr�#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)Nr@T)rArBrCr	rrErGr?)r#r>rrr�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)�envr1z-sr�1ZPYTHONNOUSERSITEz/tmp�PYTHONUSERBASEz=import sys, site; sys.exit(site.USER_BASE.startswith("/tmp")))
r	r
r5rrr�environr�
subprocessZcall�
executabler,�getsitepackages)r#Zusersiterc�rcrrr�
test_s_option�s8	
	
	

	
		z"HelperFunctionsTests.test_s_optionc
Cs�dt_tj�}|jtj|�dt_ddl}d|_t��6}d|d<|jtj�jd�tj��WdQRXdS)Nr�xoxore)	r	r�getuserbaser,rr r�
assertTrue�
startswith)r#�	user_baserrfrrr�test_getuserbase�s			
z%HelperFunctionsTests.test_getuserbasecCsQdt_dt_tj�}|jtj|�|j|jtj�|�dS)N)r	r
r�getusersitepackagesr,rnro)r#�	user_siterrr�test_getusersitepackages�s
		z-HelperFunctionsTests.test_getusersitepackagescCsndgt_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
jdddtjdd�d�}|j|d
|�nV|jt|�d�|j|d
d�t	j
jddd�}|j|d	|�dS)Nrl�darwin�PYTHONFRAMEWORKzPython.framework�z/Library�z
site-packagesr1�/�lib64�pythonr�lib)r	rrir�platformr�get_config_varr,�lenrrr*�version�sep)r#�dirsZwantedrrr�test_getsitepackages�s*	#	z)HelperFunctionsTests.test_getsitepackagesN)�__name__�
__module__�__qualname__�__doc__r$r'r0r7r?rHrrTr\r^rZskipIfrr}rarb�
skipUnlessr	r
rkrqrtr�rrrrr4s 	

'
!&	rc@sIeZdZdZeddddd�Zdd�Zd	d
d�ZdS)
rAz/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)rFrrr-rEr*�	file_pathr8�good_dirname�bad_dirnamer:r=)r#�
filename_baser8r�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.

        rJz#import @bad module name�file�
z	import %sN)
rOr��printr8r�r�rQr�mkdirr:)r#ZFILErrrrC"szPthFile.createFcCs�tjj|j�r%tj|j�|r\tjj|j�|_	|j	rxtj|j=n|j	rx|j	tj|j<tjj|j
�r�tj|j
�tjj|j�r�tj|j�dS)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)
rrr<r�rLrr9�getr8Zimported_moduler:�rmdirr=)r#r@rrrrB8s		zPthFile.cleanupN)r�r�r�r�rr�rCrBrrrrrAs
rAc@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)r#rrrr$MszImportSideEffectTests.setUpcCs|jtjdd�<dS)zRestore sys.pathN)rrr)r#rrrr'QszImportSideEffectTests.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|�dj|jd���|jtjj|	�dj|	jd���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-crc�stdoutrrwzexpected absolute path, got {}�ascii)r�r�r�r�r�)rr�relpath�dirname�__file__rfrr*rg�Popenrrh�PIPE�communicater,�
returncode�
splitlinesr;�isabsrn�format�decode)
r#�parentrc�codeZcommand�procr��stderrZ
os__file__Zos__cached__rrr�test_abs_pathsUs:!
z$ImportSideEffectTests.test_abs_pathscCsHtj�t�}x.tjD]#}|j||�|j|�qWdS)N)r	�removeduppathsrGrr�assertNotIn�add)r#Z
seen_pathsrrrr�test_no_duplicate_pathss

	z-ImportSideEffectTests.test_no_duplicate_pathsztest not implementedcCsdS)Nr)r#rrr�test_add_build_dir�sz(ImportSideEffectTests.test_add_build_dircCs0|jttd��|jttd��dS)N�quit�exit)rn�hasattr�builtins)r#rrr�test_setting_quit�sz'ImportSideEffectTests.test_setting_quitcCsF|jttd��|jttd��|jttd��dS)N�	copyright�credits�license)rnr�r�)r#rrr�test_setting_copyright�sz,ImportSideEffectTests.test_setting_copyrightcCs|jttd��dS)N�help)rnr�r�)r#rrr�test_setting_help�sz'ImportSideEffectTests.test_setting_helpcCsotjdkrkddl}|j�djd�rkx4tjjj�D]}|dkrGPqGW|jd�dS)Nr_rr1�cp�mbcszdid not alias mbcs)	rr}�localeZgetdefaultlocalero�	encodings�aliases�values�fail)r#r��valuerrr�test_aliasing_mbcs�sz(ImportSideEffectTests.test_aliasing_mbcscCsEdtjkrAyddl}Wntk
r3YnX|jd�dS)N�
sitecustomizerz(sitecustomize not imported automatically)rr9r�r]r�)r#r�rrr�test_sitecustomize_executed�s
z1ImportSideEffectTests.test_sitecustomize_executedZnetworkrx�finalzonly for released versionsZHTTPSHandlerz$need SSL support to download licensecCs�tjj�d}tjj|dd�}yFtjj|��-tjj	|��}|j
�}WdQRXWdQRXWn4tjjk
r�}z|j
}WYdd}~XnX|j|ddd|�dS)Nr1�methodZHEAD���msgzCan't find )r��_Printer__data�split�urllib�requestZRequest�test�supportZtransient_internetZurlopenZgetcode�errorZ	HTTPErrorr�r,)r#ZurlZreq�datar��errr�test_license_exists_at_url�s	z0ImportSideEffectTests.test_license_exists_at_urlN)r�r�r�r�r$r'r�r�r�skipr�r�r�r�r�r�r�r�Zrequires_resourceZsystem_must_validate_certr�r�version_infor�r�r�r�rrrrr�Js"*	

	r�c@seZdZdd�ZdS)�StartupImportTestsc
Cs>tjtjddddgdtjdtj�}|j�\}}|jd�}|jd�}t|�}|jd|�d	d
ddd
h}tj	dkr�|j
|j|�|�|jd||�tj	dkr�|jd||�ddddddddddh
j
tj�}|j
|j|�|�dS)Nz-Iz-vz-cz#import sys; print(set(sys.modules))r�r�zutf-8r	rY�_sre�sre_compile�
sre_constants�	sre_parserur��copyreg�_collections�collections�	functools�heapq�	itertools�keyword�operator�reprlib�types�weakref)rgr�rrhr�r�r��evalr5r}r;�intersectionr��
difference�builtin_module_names)r#�popenr�r�r9Zre_modsZcollection_modsrrr�test_startup_imports�s(			z'StartupImportTests.test_startup_importsN)r�r�r�r�rrrrr��sr��__main__)!r�rZtest.supportr�rrrr�rrrYr�Zurllib.requestr�Zurllib.errorrgrr�flags�no_siterr	rrrZTestCaser�objectrAr�r�r��mainrrrr�<module>s2�7|"