Your IP : 216.73.216.52


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



��Yf�D�@s>ddlmZmZmZmZddlZddlZddlZddlm	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZGdd�dej�ZGdd�dej�ZGdd	�d	ej�ZGd
d�dej�ZGdd
�d
ej�Zdd�Zedkr:e�dS)�)�run_unittest�unload�check_warnings�CleanImportN)�spec_from_file_locationc@sdeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�PkgutilTestscCs?tj�|_|jtj|j�tjjd|j�dS)Nr)	�tempfile�mkdtemp�dirname�
addCleanup�shutil�rmtree�sys�path�insert)�self�r�6/opt/alt/python35/lib64/python3.5/test/test_pkgutil.py�setUpszPkgutilTests.setUpcCstjd=dS)Nr)rr)rrrr�tearDownszPkgutilTests.tearDowncCs4d}d}tjj|j|�}tj|�ttjj|d�d�}|j�ttjj|d�d�}|j|�|j�tjtjj|d��ttjj|dd�d�}|j|�|j�tj	|d�}|j
||�tj	|d�}|j
||�tj|=dS)N�test_getdata_filesyss%Hello, world!
Second line
Third linez__init__.py�wbzres.txt�subzsub/res.txt)
�osr�joinr
�mkdir�open�close�write�pkgutil�get_data�assertEqualr�modules)r�pkg�
RESOURCE_DATAZpackage_dir�f�res1�res2rrrrs$



!

z!PkgutilTests.test_getdata_filesyscCs=d}d}d}tjj|j|�}tj|d�}|j|dd�|j|d|�|j|d|�|j�tjj	d	|�t
j|d
�}|j||�t
j|d�}|j||�g}x0t
j
|g�D]\}	}
}|j|
�q�W|j|dg�tjd	=tj|=dS)Nztest_getdata_zipfile.zip�test_getdata_zipfiles%Hello, world!
Second line
Third line�wz/__init__.py�z/res.txtz/sub/res.txtrzres.txtzsub/res.txt)rrrr
�zipfile�ZipFile�writestrrrrrr r!Ziter_modules�appendr")r�zipr#r$�zip_file�zr&r'�names�loader�nameZispkgrrrr(:s(
"
z!PkgutilTests.test_getdata_zipfilecCsud}tjj|j|�}tj|d�|jtj|�x-tjd|jg�D]}|j	d�qZWdS)NZunreadable_packagerrzunexpected package found)
rrrr
rr�rmdirr�
walk_packagesZfail)rZpackage_name�d�trrr�test_unreadable_dir_on_syspath\sz+PkgutilTests.test_unreadable_dir_on_syspathc	Csd}tjj|j|�}tj|�ttjj|d�d�}|j�tjtjj|d��ttjj|dd�d�}|j�ttjj|dd�d�}|j�d}tjj|j|�}tj|�ttjj|d�d�}|j�tjtjj|d��ttjj|dd�d�}|j�ttjj|dd�d�}|j�dddddd	g}d
d�tj|jg�D�}|j	||�x*|D]"}|j
d�r�q�tj|=q�WdS)
N�test_walkpackages_filesysz__init__.pyrrzmod.pyzsub.test_walkpackages_filesysz!sub.test_walkpackages_filesys.modztest_walkpackages_filesys.subz!test_walkpackages_filesys.sub.modcSsg|]}|d�qS)�r)�.0�errr�
<listcomp>�s	z:PkgutilTests.test_walkpackages_filesys.<locals>.<listcomp>�mod)
rrrr
rrrrr6r!�endswithrr")	r�pkg1Zpkg1_dirr%�pkg2Zpkg2_dir�expected�actualr#rrrr:gs@

!
!


!
!
	"
z&PkgutilTests.test_walkpackages_filesysc	Cssd}d}d}tjj|j|�}tj|d�}|j|dd�|j|d|dd�|j|d|dd�|j|dd�|j|d|dd�|j|d|dd�|j�tjj	d	|�dd
dddd
g}dd�t
j|g�D�}|j||�tjd	=x*|D]"}|j
d�raqItj|=qIWdS)zBTests the same as test_walkpackages_filesys, only with a zip file.ztest_walkpackages_zipfile.zip�test_walkpackages_zipfilerr)z/__init__.pyr*�/z/mod.pyrzsub.test_walkpackages_zipfilez!sub.test_walkpackages_zipfile.modztest_walkpackages_zipfile.subz!test_walkpackages_zipfile.sub.modcSsg|]}|d�qS)r;r)r<r=rrrr>�s	z:PkgutilTests.test_walkpackages_zipfile.<locals>.<listcomp>r?N)rrrr
r+r,r-rrrrr6r!r@r")	rr/rArBr0r1rCrDr#rrrrE�s4
	

z&PkgutilTests.test_walkpackages_zipfileN)
�__name__�
__module__�__qualname__rrrr(r9r:rErrrrrs"(rc@sleZdZGdd�de�ZGdd�de�Zdd�Zdd�Zd	d
�Zdd�Z	d
S)�PkgutilPEP302Testsc@s4eZdZdd�Zdd�Zdd�ZdS)zPkgutilPEP302Tests.MyTestLoadercCsdS)Nr)r�specrrr�
create_module�sz-PkgutilPEP302Tests.MyTestLoader.create_modulecCs$|jjdd�d|jd<dS)N�loadsrr;)�__dict__�get)rr?rrr�exec_module�sz+PkgutilPEP302Tests.MyTestLoader.exec_modulecCsdS)Nz
Hello, world!r)rrrrrr �sz(PkgutilPEP302Tests.MyTestLoader.get_dataN)rGrHrIrLrPr rrrr�MyTestLoader�srQc@s"eZdZdddd�ZdS)z!PkgutilPEP302Tests.MyTestImporterNcCs/tj�}t|d|jjd|dg�S)Nz<%s>r3�submodule_search_locations)rJrQr�	__class__rG)r�fullnamer�targetr3rrr�	find_spec�s
z+PkgutilPEP302Tests.MyTestImporter.find_spec)rGrHrIrVrrrr�MyTestImporter�srWcCstjjd|j��dS)Nr)r�	meta_pathrrW)rrrrr�szPkgutilPEP302Tests.setUpcCstjd=dS)Nr)rrX)rrrrr�szPkgutilPEP302Tests.tearDowncCs*|jtjdd�d�tjd=dS)N�foo�dummyz
Hello, world!)r!rr rr")rrrr�test_getdata_pep302�sz&PkgutilPEP302Tests.test_getdata_pep302cCs\ddl}|j|jd�|jtjdd�d�|j|jd�tjd=dS)Nrr;rYrZz
Hello, world!)rYr!rMrr rr")rrYrrr�test_alreadyloaded�s
z%PkgutilPEP302Tests.test_alreadyloadedN)
rGrHrI�objectrQrWrrr[r\rrrrrJ�srJc@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�ExtendPathTestsc	Csztj�}tjjd|�tjj||�}tj|�ttjj|d�d��}|j	d�WdQRX|S)Nrz__init__.pyr)zKfrom pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
)
rr	rrrrrrrr)r�pkgnamer
Zpkgdir�flrrr�create_init�s
!zExtendPathTests.create_initcCsRtjj|||d�}t|d�� }tdj|�d|�WdQRXdS)Nz.pyr)zvalue={}�file)rrrr�print�format)rr
r_Zsubmodule_name�valueZmodule_namer`rrr�create_submodule�sz ExtendPathTests.create_submodulecCs'd}|j|�}|j|�}|j||dd�|j||dd�ddl}ddl}|j|jjd�|j|jjd�|jt|j	�tt
jj||�t
jj||�g��t
j|�t
j|�tjd=tjd=tjd=tjd=tjd=dS)NrY�barr�bazr;zfoo.barzfoo.baz)rarf�foo.bar�foo.bazr!rgrerh�sorted�__path__rrrrr
rr")rr_�	dirname_0�	dirname_1rYrrr�test_simple�s&





zExtendPathTests.test_simplec
 Cs�tj}tj}d}d}|j|�}tjj||�}dj||�}tj	j
|d�tj	j
|d�z6|j|||d�tj
|�t||��}||�}	x�|D]�}
tj|
|�}|j}y
|j}Wntk
rYnX|j|
tjj�|j|
|	�|j|tjj�|jtj|
|��q�W|jt��t|d��WdQRX|jt��t|d��WdQRXWdtj|�tjd=ytj	d=tj	d=Wntk
r�YnXXdS)N�spamZeggsz{}.{}rzinvalid.modulez.spamz	spam.eggs)r�iter_importers�get_importerrarrrrdrr"�poprf�	importlib�
import_module�list�	_get_specr3�AttributeErrorZassertIsInstance�	machinery�
FileFinderr!�SourceFileLoader�assertIsNoneZassertRaises�ImportErrorrr
�KeyError)
rrqrrr_�modnamer
ZpathitemrTZ	importersZexpected_importer�finderrKr3rrr�test_iter_importerssJ		

	

	




z#ExtendPathTests.test_iter_importerscCsFd}|j|�}|j|�}|j||dd�tjtjj||d��|j||dd�ddl}ddl}|j|j	j
d�|j|jj
d�|jt|j
�ttjj||�tjj||�g��tj|�tj|�tjd=tjd=tjd=tjd=tjd=dS)	NrYrgrz__init__.pyrhr;zfoo.barzfoo.baz)rarfr�unlinkrrrirjr!rgrerhrkrlrr
rr")rr_rmrnrYrrr�test_mixed_namespace?s(





z$ExtendPathTests.test_mixed_namespaceN)rGrHrIrarfror�r�rrrrr^�s
0r^c@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�NestedNamespacePackageTestcCs)tj�|_tjdd�|_dS)N)rr	�basedirrr�old_path)rrrrr`sz NestedNamespacePackageTest.setUpcCs*|jtjdd�<tj|j�dS)N)r�rrrr
r�)rrrrrdsz#NestedNamespacePackageTest.tearDownc	Cs�|jdd�\}}tjj|j|jdtjj��}tj|dd�ttjj||d�d��}|j	|�WdQRXdS)N�.r;�exist_okTz.pyr))
�rsplitrrrr��replace�sep�makedirsrr)rr4�contents�base�final�	base_pathr%rrrrLhs
*%z(NestedNamespacePackageTest.create_modulecCsad}|jd|�|jd|�|jd|�|jd|�|jdd�|jdd	�tjjd
tjj|jd��tjjd
tjj|jd��d
dl}|jt	d
�|j
t|j�d�d
dl
}|jt	d�|j
t|jj�d�d
dlm}d
dlm}|j
|d�|j
|d�dS)NzBimport pkgutil; __path__ = pkgutil.extend_path(__path__, __name__)za.pkg.__init__zb.pkg.__init__za.pkg.subpkg.__init__zb.pkg.subpkg.__init__za.pkg.subpkg.czc = 1zb.pkg.subpkg.dzd = 2r�a�br#�z
pkg.subpkg)�c)r7r;)rLrrrrrr�r#rrr!�lenrlZ
pkg.subpkgZsubpkgZpkg.subpkg.cr�Zpkg.subpkg.dr7)rZpkgutil_boilerplater#r�r7rrr�test_nestedos&%%z&NestedNamespacePackageTest.test_nestedN)rGrHrIrrrLr�rrrrr�^sr�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�ImportlibMigrationTestscCstdtf�S)Nz5This emulation is deprecated, use 'importlib' instead)r�DeprecationWarning)rrrr�check_deprecated�sz(ImportlibMigrationTests.check_deprecatedc	Cs%|j��tjd�WdQRXdS)Nr*)r�rZImpImporter)rrrr�test_importer_deprecated�s
z0ImportlibMigrationTests.test_importer_deprecatedcCs.|j��tjdddd�WdQRXdS)Nr*)r�rZ	ImpLoader)rrrr�test_loader_deprecated�s
z.ImportlibMigrationTests.test_loader_deprecatedc
Csrt��b}|jtjd��|jtjd��|jtjd��|jt|j�d�WdQRXdS)Nrrztest.supportr)r�assertIsNotNoner�
get_loaderr!r��warnings)rr)rrr� test_get_loader_avoids_emulation�s
z8ImportlibMigrationTests.test_get_loader_avoids_emulationcCs]t}bzFt��6}|jtjt��|jt|j�d�WdQRXWd|aXdS)Nr)	�
__loader__rr�rr�rGr!r�r�)rZthis_loaderr)rrr�0test_get_loader_handles_missing_loader_attribute�s$zHImportlibMigrationTests.test_get_loader_handles_missing_loader_attributec
Cs_d}tt�|�}|`t|��!|tj|<tj|�}WdQRX|j|�dS)Nrp)�typer�__spec__rr"rr�r|)rr4r?r3rrr�.test_get_loader_handles_missing_spec_attribute�s

zFImportlibMigrationTests.test_get_loader_handles_missing_spec_attributec
Csbd}tt�|�}d|_t|��!|tj|<tj|�}WdQRX|j|�dS)Nrp)r�rr�rr"rr�r|)rr4r?r3rrr�+test_get_loader_handles_spec_attribute_none�s	

zCImportlibMigrationTests.test_get_loader_handles_spec_attribute_nonecCsEd}dtj|<ztj|�}Wdtj|=X|j|�dS)Nz
totally bogus)rr"rr�r|)rr4r3rrr�#test_get_loader_None_in_sys_modules�s
z;ImportlibMigrationTests.test_get_loader_None_in_sys_modulescCs&d}tj|�}|j|�dS)Nz
totally bogus)r�find_loaderr|)rr4r3rrr�test_find_loader_missing_module�sz7ImportlibMigrationTests.test_find_loader_missing_modulec
Csrt��b}|jtjd��|jtjd��|jtjd��|jt|j�d�WdQRXdS)Nrrztest.supportr)rr�rr�r!r�r�)rr)rrr�!test_find_loader_avoids_emulation�s
z9ImportlibMigrationTests.test_find_loader_avoids_emulationc
CsFt��6}|jtjd��|jt|j�d�WdQRXdS)Nz*??r)rr|rrrr!r�r�)rr)rrr�"test_get_importer_avoids_emulation�sz:ImportlibMigrationTests.test_get_importer_avoids_emulationc
CsGt��7}xtj�D]}qW|jt|j�d�WdQRXdS)Nr)rrrqr!r�r�)rr)Zimporterrrr�$test_iter_importers_avoids_emulation�sz<ImportlibMigrationTests.test_iter_importers_avoids_emulationN)rGrHrIr�r�r�r�r�r�r�r�r�r�r�r�rrrrr��s			r�cCsItttttt�ddl}ddl}|jj	�|j
�dS)Nr)rrrJr^r�r��	zipimportrt�_zip_directory_cache�clear�invalidate_caches)r�rtrrr�	test_main�s

r��__main__)Ztest.supportrrrrZunittestrrt�importlib.utilrrrZos.pathrrr+ZTestCaserrJr^r�r�r�rGrrrr�<module>s$"�-})W