Your IP : 216.73.216.213


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

�
j f�I�@s�ddlZddlZddlZddlZddlZddlZddlmZddlZddl	ZGdd�dej
�ZGdd�dej�Z
edkr�ej�ndS)�N)�supportc@sPeZdZdZdZdZZZZdZ	dZ
dZZdd�Z
dS)�TestableTestProgramNT��cCsdS)N�)�selfrr�A/opt/alt/python34/lib64/python3.4/unittest/test/test_discovery.py�__init__szTestableTestProgram.__init__)�__name__�
__module__�__qualname__�module�exitZdefaultTest�failfast�
catchbreak�buffer�	verbosityZprogNameZ
testRunner�
testLoaderr	rrrrr
s
rc@seZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)S)*�
TestDiscoveryc	Csetj�}d|_|jd�}|j|d�ts>dS|jt��|jd�WdQXdS)Nz/fooz/foo/bar/baz.pyzbar.bazz/bar/baz.py)�unittest�
TestLoader�_top_level_dirZ_get_name_from_path�assertEqual�	__debug__�assertRaises�AssertionError)r�loader�namerrr�test_get_name_from_paths	z%TestDiscovery.test_get_name_from_pathc
s�tj�}tj��fdd�}tjj��fdd�}tjj��fdd�}ddd	d
ddd
gddgg��fdd�t_|j|�dd�}|tj_|j|�dd�}|tj_|j|�dd�|_dd�|_	tjj
d�}||_t|j
|d��}dd�d!D�}	|	jdd�d"D��|j||	�dS)#Ncs
�t_dS)N)�os�listdirr)�original_listdirrr�restore_listdir-sz6TestDiscovery.test_find_tests.<locals>.restore_listdircs�tj_dS)N)r�path�isfiler)�original_isfilerr�restore_isfile0sz5TestDiscovery.test_find_tests.<locals>.restore_isfilecs�tj_dS)N)rr#�isdirr)�original_isdirrr�
restore_isdir3sz4TestDiscovery.test_find_tests.<locals>.restore_isdirztest2.pyztest1.pyz
not_a_test.pyZtest_dirztest.fooztest-not-a-module.py�another_dirztest4.pyztest3.pycs
�jd�S)Nr)�pop)r#)�
path_listsrr�<lambda>9sz/TestDiscovery.test_find_tests.<locals>.<lambda>cSs
|jd�S)N�dir)�endswith)r#rrrr'<sz,TestDiscovery.test_find_tests.<locals>.isdircSs|jd�od|kS)Nr.r*)r/)r#rrrr$Asz-TestDiscovery.test_find_tests.<locals>.isfilecSs|dS)Nz moduler)r#rrrr-GscSs|dS)Nz testsr)r
rrrr-Hsz/fooztest*.pycSsg|]}|d�qS)z
 module testsr)�.0rrrr�
<listcomp>Ps	z1TestDiscovery.test_find_tests.<locals>.<listcomp>�test1�test2cSsg|]}d|d�qS)ztest_dir.%sz
 module testsr)r0rrrrr1Rs	�test3�test4)r2r3)r4r5)rrrr r#r$r'�
addCleanup�_get_module_from_name�loadTestsFromModule�abspathr�list�_find_tests�extendr)
rrr"r&r)r'r$Z	top_level�suiteZexpectedr)r(r%r!r,r�test_find_tests)s8	


		
zTestDiscovery.test_find_testscs�tj�}tj��fdd�}tjj��fdd�}tjj��fdd�}ddd	g��gggg��fd
d�t_�j|�dd�tj_�j|��fd
d�tj_�j|�Gdd�dt���fdd�|_	�fdd�}||_
d|_t|j
dd��}�j|dd	dg��j�jdd	g��j�j|dddfg�dS)Ncs
�t_dS)N)rr r)r!rrr"ZszCTestDiscovery.test_find_tests_with_package.<locals>.restore_listdircs�tj_dS)N)rr#r$r)r%rrr&]szBTestDiscovery.test_find_tests_with_package.<locals>.restore_isfilecs�tj_dS)N)rr#r'r)r(rrr)`szATestDiscovery.test_find_tests_with_package.<locals>.restore_isdirZa_directory�test_directoryZtest_directory2cs
�jd�S)Nr)r+)r#)r,rrr-esz<TestDiscovery.test_find_tests_with_package.<locals>.<lambda>cSsdS)NTr)r#rrrr-hscstjj|��kS)N)rr#�basename)r#)�directoriesrrr-ksc@s4eZdZgZgZdd�Zdd�ZdS)z:TestDiscovery.test_find_tests_with_package.<locals>.ModulecsS|�_�jj|�tjj|�dkrO�fdd�}|�_ndS)Nr?cs�jj|||f�dS)N�
load_tests)�load_tests_args�append)r�tests�pattern)rrrrBvszWTestDiscovery.test_find_tests_with_package.<locals>.Module.__init__.<locals>.load_tests)r#�pathsrDrr@rB)rr#rBr)rrr	rs
	zCTestDiscovery.test_find_tests_with_package.<locals>.Module.__init__cSs|j|jkS)N)r#)r�otherrrr�__eq__{szATestDiscovery.test_find_tests_with_package.<locals>.Module.__eq__N)r
rrrGrCr	rIrrrr�Modulens	rJcs
�|�S)Nr)r)rJrrr-~scs#|r�jd��n|jdS)Nz+use_load_tests should be False for packagesz
 module tests)ZfailureExceptionr#)r
Zuse_load_tests)rrrr8szGTestDiscovery.test_find_tests_with_package.<locals>.loadTestsFromModulez/fooztest*rBz
 module tests)rrrr r#r$r'r6�objectr7r8rr:r;rrGrC)rrr"r&r)r8r=r)rJrAr(r%r!r,rr�test_find_tests_with_packageVs4	


			z*TestDiscovery.test_find_tests_with_packagec
s�tj�}tjj�tjj��fdd�}dd�tj_|j|�tjdd���fdd�}|j|�tjjtjj	d��}|j
t��|jdd	d�WdQX|j
|j|�|j|tj�d
d�tj_dd�tj_�fdd
�}|j|�g�d�fdd�}||_t|_|jddd�}tjjd�}tjjd�}	|j
|d�|j
|j|�|j
�|	dfg�|j|tj�dS)Ncs�tj_dS)N)rr#r$r)r%rrr&�sz3TestDiscovery.test_discover.<locals>.restore_isfilecSsdS)NFr)r#rrrr-�sz-TestDiscovery.test_discover.<locals>.<lambda>cs�tjdd�<dS)N)�sysr#r)�
orig_sys_pathrr�restore_path�sz1TestDiscovery.test_discover.<locals>.restore_pathz/fooz/foo/bar�
top_level_dircSsdS)NTr)r#rrrr-�scSsdS)NTr)r#rrrr-�scs�tj_dS)N)rr#r'r)r(rrr)�sz2TestDiscovery.test_discover.<locals>.restore_isdircs�j||f�dgS)NrE)rD)�	start_dirrF�	namespace)�_find_tests_argsrrr;�sz0TestDiscovery.test_discover.<locals>._find_testsz/foo/bar/bazrFz	['tests'])rrrr#r$r'r6rMr9�normpathr�ImportError�discoverrr�assertInr;�str�
suiteClass)
rrr&rO�	full_pathr)r;r=rPrQr)rSrNr(r%r�
test_discover�s:


		zTestDiscovery.test_discovercsxtj��fdd�t_tjj�dd�tj_tjdd�����fdd�}|j|�dS)Ncs�gS)Nr)�_)�fakefilerrr-�sz8TestDiscovery.setup_import_issue_tests.<locals>.<lambda>cSsdS)NTr)r\rrrr-�scs,�tj_�t_�tjdd�<dS)N)rr#r$r rMr)r$r rNrr�restore�s	z7TestDiscovery.setup_import_issue_tests.<locals>.restore)rr r#r$rMr6)rr]r^r)r]r$r rNr�setup_import_issue_tests�s	z&TestDiscovery.setup_import_issue_testscCs�tj�}|jd�|jd�}|jtj�tj�|j	|j
�d�tt|�d�d}|jt
��|j�WdQXx4ttjd�D]}tjtj||��q�WdS)Nztest_this_does_not_exist.py�.rr)rrr_rVrWr�getcwdrMr#r�countTestCasesr:rrUZtest_this_does_not_exist�range�pickle�HIGHEST_PROTOCOL�loads�dumps)rrr=�test�protorrr�.test_discover_with_modules_that_fail_to_import�s
z<TestDiscovery.test_discover_with_modules_that_fail_to_importcCs�tj�}dd�}||_|jd�|jd�}|j|j�d�tj�}|j|�|jt	|j
�d�x4ttj
d�D]}tjtj||��q�WdS)NcSstjd��dS)NZ	skipperoo)rZSkipTest)rrrrr7�szeTestDiscovery.test_discover_with_module_that_raises_SkipTest_on_import.<locals>._get_module_from_nameztest_skip_dummy.pyr`r)rrr7r_rVrrbZ
TestResultZrun�lenZskippedrcrdrerfrg)rrr7r=�resultrirrr�8test_discover_with_module_that_raises_SkipTest_on_import�s	

zFTestDiscovery.test_discover_with_module_that_raises_SkipTest_on_importcCs�t�}g}|j|_|jddg�|j|gg�g|dd�<|jddddg�|j|ddgg�dS)N�	somethingrV�foo�bar)rrD�
_do_discovery�	parseArgsr)r�program�argsrrr�$test_command_line_handling_parseArgs�s	z2TestDiscovery.test_command_line_handling_parseArgscCs�t�}g}|j|_|jdg�|j|gg�|j|jd�|j|jd�|j|jd�|j|j	d�dS)NrnrF)
rrDrqrrrr�assertIsrrr)rrsrtrrr�.test_command_line_handling_discover_by_defaults	z<TestDiscovery.test_command_line_handling_discover_by_defaultcCs�t�}g}|j|_|jddddddg�|j|gg�|j|jd�|j|jd�|j|jd�|j|j	d�dS)Nrnz-vz-bz-cz-f�T)
rrDrqrrrrrvrrr)rrsrtrrr�;test_command_line_handling_discover_by_default_with_optionss	zITestDiscovery.test_command_line_handling_discover_by_default_with_optionscCs�t�}d|_tj��8}|jt�� }|jddddg�WdQXWdQX|j|jj	d�|j
d|j��dS)NZoneZtwoZthreeZfourrxzusage:)rx)rrrZcaptured_stderrr�
SystemExitrqr�	exceptionrtrW�getvalue)rrs�stderr�cmrrr�:test_command_line_handling_do_discovery_too_many_argumentss		%zHTestDiscovery.test_command_line_handling_do_discovery_too_many_argumentscCshtjtj�}|j�Gdd�dt�}|�|_|jdg�|j|jdg�dS)Nc@s"eZdZgZdd�ZdS)zYTestDiscovery.test_command_line_handling_do_discovery_uses_default_loader.<locals>.LoadercSs|jj|||f�dS)NrE)rtrD)rrQrFrPrrrrV+szbTestDiscovery.test_command_line_handling_do_discovery_uses_default_loader.<locals>.Loader.discoverN)r
rrrtrVrrrr�Loader)sr�z-vr`�test*.py)r`r�N)	rK�__new__r�TestProgramZ_initArgParsersrrqrrt)rrsr�rrr�;test_command_line_handling_do_discovery_uses_default_loader%s
zITestDiscovery.test_command_line_handling_do_discovery_uses_default_loadercCs�t�}Gdd�dt�}|jdgd|�|j|jd�|j|jd�|j|jdg�g|_t�}|jdgd|�|j|jd�|j|jdg�g|_t�}|jgd|�|j|jd�|j|jdg�g|_t�}|jd	gd|�|j|jd�|j|jdg�g|_t�}|jd	d
gd|�|j|jd�|j|jdg�g|_t�}|jd	d
dgd|�|j|jd�|j|jdg�g|_t�}|jdd	gd|�|j|jd�|j|jdg�g|_t�}|jd
d	gd|�|j|jd�|j|jdg�g|_t�}|jdd	gd|�|j|jd�|j|jdg�|j|j�|j|j	�g|_t�}|jdd
dd	dddgd|�|j|jd�|j|jdg�|j|jd�|j
|j�|j
|j	�dS)Nc@s"eZdZgZdd�ZdS)zRTestDiscovery.test_command_line_handling_do_discovery_calls_loader.<locals>.LoadercSs|jj|||f�dS)NrE)rtrD)rrQrFrPrrrrV8sz[TestDiscovery.test_command_line_handling_do_discovery_calls_loader.<locals>.Loader.discoverN)r
rrrtrVrrrrr�6sr�z-vrxrEr`�test*.pyz	--verbose�fish�eggs�hamz-sz-tz-pz-fz-c)r`r�N)r`r�N)r`r�N)r�r�N)r�r�N)r�r�r�)r�r�N)r`r�r�)r`r�N)r�r�N)rrKrqrrrhrtZassertFalserr�
assertTrue)rrsr�rrr�4test_command_line_handling_do_discovery_calls_loader3sr																			!zBTestDiscovery.test_command_line_handling_do_discovery_calls_loadercs�Gdd�dt�}|tjd<tjjd��tj�tjj�tjj�����fdd�}|j	|�dd�}dd	�}d
d�}|t_|tj_|tj_�S)Nc@seZdZdZdS)z0TestDiscovery.setup_module_clash.<locals>.Modulez
bar/foo.pyN)r
rr�__file__rrrrrJ~srJrocsQ�t_�tj_�tj_tjd=�tjkrMtjj��ndS)Nro)rr r#r$r'rM�modules�remover)rZr(r%r!rr�cleanup�s	
z1TestDiscovery.setup_module_clash.<locals>.cleanupcSsdgS)Nzfoo.pyr)r\rrrr �sz1TestDiscovery.setup_module_clash.<locals>.listdircSsdS)NTr)r\rrrr$�sz0TestDiscovery.setup_module_clash.<locals>.isfilecSsdS)NTr)r\rrrr'�sz/TestDiscovery.setup_module_clash.<locals>.isdir)
rKrMr�rr#r9r r$r'r6)rrJr�r r$r'r)rZr(r%r!r�setup_module_clash}s
	
	z TestDiscovery.setup_module_clashcCs�|j�}tj�}tjjd�}tjjd�}tjd||f�}|jt	d||j
dddd�|jtjd|�dS)	NrprozZ'foo' module incorrectly imported from %r. Expected %r. Is this module globally installed?z^%s$rQrFzfoo.pyr)
r�rrrr#r9�re�escapeZassertRaisesRegexrUrVrrM)rrZr�mod_dir�expected_dir�msgrrr�test_detect_module_clash�s	
z&TestDiscovery.test_detect_module_clashcs�|j�}tjj�tjjd��tjjd���fdd�}|j|���fdd�}|tj_tj�}|jdddd	�dS)
Nrprocs�tj_dS)N)rr#�realpathr)�original_realpathrrr��sz5TestDiscovery.test_module_symlink_ok.<locals>.cleanupcs2|tjj�d�kr.tjj�d�S|S)Nzfoo.py)rr#�join)r#)r�r�rrr��sz6TestDiscovery.test_module_symlink_ok.<locals>.realpathrQrFzfoo.py)	r�rr#r�r9r6rrrV)rrZr�r�rr)r�r�r�r�test_module_symlink_ok�s
z$TestDiscovery.test_module_symlink_okcs�tj�}�g�tjjtjjtjj���d�_d���fdd�}||_	|j
d�}�j�j��j|j
��dS)NFcsd�_�j|���S)NT)�wasRunr)rQrFrR)�expectedPathrrErrr;�s	zBTestDiscovery.test_discovery_from_dotted_path.<locals>._find_testsz
unittest.test)rrrr#r9�dirnamerhr�r�r;rVr�rZ_tests)rrr;r=r)r�rrEr�test_discovery_from_dotted_path�s	$		z-TestDiscovery.test_discovery_from_dotted_pathc	s�tj�}tj�dd�t_tjj�tjj�dd�tj_tjdd������fdd�}|j|�|j	t
��}|jd�WdQX|jt
|j�d�dS)NcSsdgS)Nztest_this_does_not_exist.pyr)r\rrrr-�szOTestDiscovery.test_discovery_from_dotted_path_builtin_modules.<locals>.<lambda>cSsdS)NFr)r\rrrr-�scs8�tj_�tj_�t_�tjdd�<dS)N)rr#r$r'r rMr)r'r$r rNrrr^�s	zNTestDiscovery.test_discovery_from_dotted_path_builtin_modules.<locals>.restorerMz2Can not use builtin modules as dotted module names)rrrr r#r$r'rMr6r�	TypeErrorrVrrXr{)rrr^r~r)r'r$r rNr�/test_discovery_from_dotted_path_builtin_modules�s	
z=TestDiscovery.test_discovery_from_dotted_path_builtin_modulescs�tj�}t�tjd��ddg�_tjdddddg��_�fdd�}�fdd	�}|j|�|t	_g�d�fd
d�}||_
t|_|j
d�}|j|dd
g�dS)N�packagez/az/br�submodule_search_locationscs�tj|<�S)N)rMr�)�packagenamert�kwargs)r�rr�_import�s
zLTestDiscovery.test_discovery_from_dotted_namespace_packages.<locals>._importcs
�t_dS)N)�builtins�
__import__r)�orig_importrrr��szLTestDiscovery.test_discovery_from_dotted_namespace_packages.<locals>.cleanupcs�j||f�d|gS)Nz%s/tests)rD)rQrFrR)rSrrr;�szPTestDiscovery.test_discovery_from_dotted_namespace_packages.<locals>._find_testsz/a/testsz/b/tests)rrr��types�
ModuleType�__path__�SimpleNamespace�__spec__r6r�r;r:rYrVr)rrr�r�r;r=r)rSr�r�r�-test_discovery_from_dotted_namespace_packages�s"	
			z;TestDiscovery.test_discovery_from_dotted_namespace_packagesc
s�tj�}tjd��t��fdd�}�fdd�}|j|�|t_|jt��}|j	d�WdQX|j
t|j�dj
���dS)Nr�cs�tj|<�S)N)rMr�)r�rtr�)r�rrr�s
z>TestDiscovery.test_discovery_failed_discovery.<locals>._importcs
�t_dS)N)r�r�r)r�rrr�sz>TestDiscovery.test_discovery_failed_discovery.<locals>.cleanupz$don't know how to discover from {!r})rrr�r�r�r6r�rr�rVrrXr{�format)rrr�r�r~r)r�r�r�test_discovery_failed_discoverys
	z-TestDiscovery.test_discovery_failed_discoveryN)r
rrrr>rLr[r_rjrmrurwryrr�r�r�r�r�r�r�r�r�rrrrrs(
-?.
Jr�__main__)rr�rMr�rdr�rhrrZ
unittest.testr�rZTestCaserr
�mainrrrr�<module>s��