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_pkgutil.cpython-34.pyo

�
g f�9�@sMddlmZmZmZmZddlZddlZddlZddlm	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZGdd�dej�ZGdd�dej�ZGdd	�d	ej�ZGd
d�dej�ZGdd
�d
ej�Zdd�ZedkrIe�ndS)�)�run_unittest�unload�check_warnings�CleanImportN)�spec_from_file_locationc@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�PkgutilTestscCs?tj�|_|jtj|j�tjjd|j�dS)Nr)	�tempfile�mkdtemp�dirname�
addCleanup�shutil�rmtree�sys�path�insert)�self�r�6/opt/alt/python34/lib64/python3.4/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
�zipfileZZipFileZwritestrrrrrr r!Ziter_modules�appendr")r�zipr#r$Zzip_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�rmdirrZ
walk_packagesZfail)rZpackage_name�d�trrr�test_unreadable_dir_on_syspath]sz+PkgutilTests.test_unreadable_dir_on_syspathN)�__name__�
__module__�__qualname__rrrr(r5rrrrrs
"rc@sleZdZGdd�de�ZGdd�de�Zdd�Zdd�Zd	d
�Zdd�Z	d
S)�PkgutilPEP302Testsc@s(eZdZdd�Zdd�ZdS)zPkgutilPEP302Tests.MyTestLoadercCs$|jjdd�d|jd<dS)N�loadsr�)�__dict__�get)r�modrrr�exec_moduleksz+PkgutilPEP302Tests.MyTestLoader.exec_modulecCsdS)Nz
Hello, world!r)rrrrrr osz(PkgutilPEP302Tests.MyTestLoader.get_dataN)r6r7r8r?r rrrr�MyTestLoaderjsr@c@s"eZdZdddd�ZdS)z!PkgutilPEP302Tests.MyTestImporterNcCs/tj�}t|d|jjd|dg�S)Nz<%s>r0�submodule_search_locations)r9r@r�	__class__r6)r�fullnamer�targetr0rrr�	find_specss
z+PkgutilPEP302Tests.MyTestImporter.find_spec)r6r7r8rErrrr�MyTestImporterrsrFcCstjjd|j��dS)Nr)r�	meta_pathrrF)rrrrrzszPkgutilPEP302Tests.setUpcCstjd=dS)Nr)rrG)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;rHrIz
Hello, world!)rHr!r:rr rr")rrHrrr�test_alreadyloaded�s
z%PkgutilPEP302Tests.test_alreadyloadedN)
r6r7r8�objectr@rFrrrJrKrrrrr9hsr9c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�ExtendPathTestsc	Csytj�}tjjd|�tjj||�}tj|�ttjj|d�d��}|j	d�WdQX|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_initcCsQtjj|||d�}t|d�� }tdj|�d|�WdQXdS)Nz.pyr)zvalue={}�file)rrrr�print�format)rr
rNZsubmodule_name�valueZmodule_namerOrrr�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)NrH�barr�bazr;zfoo.barzfoo.baz)rPrU�foo.bar�foo.bazr!rVrTrW�sorted�__path__rrrrr
rr")rrN�	dirname_0�	dirname_1rHrrr�test_simple�s&





zExtendPathTests.test_simplec
Cs�tj}tj}d}d}|j|�}tjj||�}dj||�}tj	j
|d�tj	j
|d�z4|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��WdQX|jt��t|d��WdQXWdtj|�tjd=ytj	d=tj	d=Wntk
r�YnXXdS)N�spamZeggsz{}.{}rzinvalid.modulez.spamz	spam.eggs)r�iter_importers�get_importerrPrrrrSrr"�poprU�	importlib�
import_module�list�	_get_specr0�AttributeErrorZassertIsInstance�	machinery�
FileFinderr!�SourceFileLoader�assertIsNoneZassertRaises�ImportErrorrr
�KeyError)
rr`rarN�modnamer
ZpathitemrCZ	importersZexpected_importer�finder�specr0rrr�test_iter_importers�sJ		

	

	




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)	NrHrVrz__init__.pyrWr;zfoo.barzfoo.baz)rPrUr�unlinkrrrXrYr!rVrTrWrZr[rr
rr")rrNr\r]rHrrr�test_mixed_namespace�s(





z$ExtendPathTests.test_mixed_namespaceN)r6r7r8rPrUr^rqrsrrrrrM�s
0rMc@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�NestedNamespacePackageTestcCs)tj�|_tjdd�|_dS)N)rr	�basedirrr�old_path)rrrrrsz NestedNamespacePackageTest.setUpcCs*|jtjdd�<tj|j�dS)N)rvrrrr
ru)rrrrrsz#NestedNamespacePackageTest.tearDownc	Cs�|jdd�\}}tjj|j|jdtjj��}tj|dd�ttjj||d�d��}|j	|�WdQXdS)N�.r;�exist_okTz.pyr))
�rsplitrrrru�replace�sep�makedirsrr)rr1�contents�base�final�	base_pathr%rrr�
create_modules
*%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)r3r;)r�rrrrrrur#rrr!�lenr[Z
pkg.subpkgZsubpkgZpkg.subpkg.cr�Zpkg.subpkg.dr3)rZpkgutil_boilerplater#r�r3rrr�test_nested s&%%z&NestedNamespacePackageTest.test_nestedN)r6r7r8rrr�r�rrrrrtsrtc@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�}WdQXdS)Nr*)r�rZImpImporter)r�xrrr�test_importer_deprecatedBs
z0ImportlibMigrationTests.test_importer_deprecatedcCs/|j��tjdddd�}WdQXdS)Nr*)r�rZ	ImpLoader)rr�rrr�test_loader_deprecatedFs
z.ImportlibMigrationTests.test_loader_deprecatedc
Csqt��b}|jtjd��|jtjd��|jtjd��|jt|j�d�WdQXdS)Nrrztest.supportr)r�assertIsNotNoner�
get_loaderr!r��warnings)rr)rrr� test_get_loader_avoids_emulationJs
z8ImportlibMigrationTests.test_get_loader_avoids_emulationcCs\t}bzEt��6}|jtjt��|jt|j�d�WdQXWd|aXdS)Nr)	�
__loader__rr�rr�r6r!r�r�)rZthis_loaderr)rrr�0test_get_loader_handles_missing_loader_attributeQs#zHImportlibMigrationTests.test_get_loader_handles_missing_loader_attributec
Cs^d}tt�|�}|`t|��!|tj|<tj|�}WdQX|j|�dS)Nr_)�typer�__spec__rr"rr�rk)rr1r>r0rrr�.test_get_loader_handles_missing_spec_attribute\s

zFImportlibMigrationTests.test_get_loader_handles_missing_spec_attributec
Csad}tt�|�}d|_t|��!|tj|<tj|�}WdQX|j|�dS)Nr_)r�rr�rr"rr�rk)rr1r>r0rrr�+test_get_loader_handles_spec_attribute_nonees	

zCImportlibMigrationTests.test_get_loader_handles_spec_attribute_nonecCsEd}dtj|<ztj|�}Wdtj|=X|j|�dS)Nz
totally bogus)rr"rr�rk)rr1r0rrr�#test_get_loader_None_in_sys_modulesns
z;ImportlibMigrationTests.test_get_loader_None_in_sys_modulescCs&d}tj|�}|j|�dS)Nz
totally bogus)r�find_loaderrk)rr1r0rrr�test_find_loader_missing_modulewsz7ImportlibMigrationTests.test_find_loader_missing_modulec
Csqt��b}|jtjd��|jtjd��|jtjd��|jt|j�d�WdQXdS)Nrrztest.supportr)rr�rr�r!r�r�)rr)rrr�!test_find_loader_avoids_emulation|s
z9ImportlibMigrationTests.test_find_loader_avoids_emulationc
CsEt��6}|jtjd��|jt|j�d�WdQXdS)Nz*??r)rrkrrar!r�r�)rr)rrr�"test_get_importer_avoids_emulation�sz:ImportlibMigrationTests.test_get_importer_avoids_emulationc
CsFt��7}xtj�D]}qW|jt|j�d�WdQXdS)Nr)rrr`r!r�r�)rr)Zimporterrrr�$test_iter_importers_avoids_emulation�sz<ImportlibMigrationTests.test_iter_importers_avoids_emulationN)r6r7r8r�r�r�r�r�r�r�r�r�r�r�r�rrrrr�8s			r�cCsItttttt�ddl}ddl}|jj	�|j
�dS)Nr)rrr9rMrtr��	zipimportrc�_zip_directory_cache�clear�invalidate_caches)r�rcrrr�	test_main�s

r��__main__)Ztest.supportrrrrZunittestrrc�importlib.utilrrrZos.pathr�typesrr+ZTestCaserr9rMrtr�r�r6rrrr�<module>s&"T*})W