Your IP : 216.73.216.61


Current Path : /opt/alt/python35/lib/python3.5/site-packages/nose/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib/python3.5/site-packages/nose/__pycache__/loader.cpython-35.pyc



�^�]�c�@s�dZddlZddlZddlZddlZddlZddlmZddlm	Z	m
Z
ddlmZm
Z
ddlmZddlmZddlmZmZmZdd	lmZmZdd
lmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#ddl$m%Z%m&Z&m'Z'ddlm(Z(m)Z)ej*e+�Z,ej-j.Z/ej-j0Z1ej-j2Z3ej-j4Z5ej-j6Z7d
dgZ8Gdd
�d
ej9�Z9e9Z:dS)z�
Test Loader
-----------

nose's test loader implements the same basic functionality as its
superclass, unittest.TestLoader, but extends it by more liberal
interpretations of what may be a test and how a test may be named.
�N)�
isfunction)�unbound_method�ismethod)�FunctionTestCase�MethodTestCase)�Failure)�Config)�Importer�add_path�remove_path)�defaultSelector�TestAddress)
�func_lineno�
getpackage�isclass�isgenerator�	ispackage�regex_last_key�resolve_name�transplant_func�transplant_class�test_address)�ContextSuiteFactory�ContextList�	LazySuite)�	sort_list�
cmp_to_key�
TestLoader�defaultTestLoadercs'eZdZdZdZdZdZdZdZdddddd�Z	dd�Z
dd�Zd	d
�Zdd�Z
d
d�Zdd�Zdd�Zdddd�Zdddd�Zddd�Z�fdd�Zdd�Zddd�Zdd d!�Zd"d#�Zd$d%�Z�S)&raATest loader that extends unittest.TestLoader to:

    * Load tests from test-like functions and classes that are not
      unittest.TestCase subclasses
    * Find and load test modules in a directory
    * Support tests that are generators
    * Support easy extensions of or changes to that behavior through plugins
    NcCs�|dkrt�}|dkr0td|�}|dkrE|j}|dkr`t|�}nt|�rx||�}||_||_tt|��|_||_	|j
r�t||�td|�|_
tg�|_tjj|�dS)aInitialize a test loader.

        Parameters (all optional):

        * config: provide a `nose.config.Config`_ or other config class
          instance; if not provided a `nose.config.Config`_ with
          default values is used.
        * importer: provide an importer instance that implements
          `importFromPath`. If not provided, a
          `nose.importer.Importer`_ is used.
        * workingDir: the directory to which file and module names are
          relative. If not provided, assumed to be the current working
          directory.
        * selector: a selector class or instance. If a class is
          provided, it will be instantiated with one argument, the
          current config. If not provided, a `nose.selector.Selector`_
          is used.
        N�config)rr	�
workingDirrrr�importer�op_normpath�
op_abspath�selector�addPathsr
r�
suiteClass�set�
_visitedPaths�unittestr�__init__)�selfrr!r r$�r,�</opt/alt/python35/lib/python3.5/site-packages/nose/loader.pyr*;s&						
zTestLoader.__init__cCs�|jjrtjj||�S||jdd�}tt|t|���}|rnt	|d�rndg}|j
r�t|t|j
��|S)z_Override to select with selector, unless
        config.getTestCaseNamesCompat is True
        cSsMt||d�}t|�r0t||�}nt|�s@dS|j|�S)NF)�getattrrrr�
wantMethod)�attr�cls�sel�itemr,r,r-�wantedlsz+TestLoader.getTestCaseNames.<locals>.wanted�runTest)
rZgetTestCaseNamesCompatr)r�getTestCaseNamesr$�list�filter�dir�hasattr�sortTestMethodsUsingrr)r+�
testCaseClassr4�casesr,r,r-r6es		zTestLoader.getTestCaseNamescCs|dkrdS||jkS)NF)r()r+�pathr,r,r-�_haveVisited}szTestLoader._haveVisitedcCs |dk	r|jj|�dS)N)r(�add)r+r>r,r,r-�_addVisitedPath�szTestLoader._addVisitedPathc
#s�tjd|��jj}|j|��jjrGt|�j�}tj|�}t	|t
�jj��xX|D]P}|jd�r�qvt
t||���t��}d}|r�d}�jj��}n6t��}|r|jd�r�qv�jj��}t��}	|rv�j��rv�j��|r�|j�|jd�rq�j�dd�Vn�j��V|j�qv|	r��j�dd�Vqv�j��fdd	��VqvWg}
x$|j|�D]}|
j|�q�Wy|
r�j|
�VWn?tt fk
r,�Yn%�jt!t"j#��g�VYnX�jjrxx|D]}t$|�qdW|j%|�d
S)z�Load tests from the directory at path. This is a generator
        -- each suite of tests from a module or other file is yielded
        and is expected to be executed before the next file is
        examined.
        zload from dir %s�.F�_z.py�
discoveredTcs
�j��S)N)�loadTestsFromDirr,)�
entry_pathr+r,r-�<lambda>�sz-TestLoader.loadTestsFromDir.<locals>.<lambda>N)&�log�debugr�pluginsZbeforeDirectoryr%r
�os�listdirrrZ	testMatch�
startswithr#�op_join�	op_isfiler$ZwantFile�op_isdirZ
wantDirectoryrr?rAZ
beforeContext�endswith�loadTestsFromName�loadTestsFromFileZafterContextr&rE�append�KeyboardInterrupt�
SystemExitr�sys�exc_inforZafterDirectory)
r+r>rJZpaths_added�entries�entry�is_filer4�is_dir�
is_package�tests�test�pr,)rFr+r-rE�sd




"
zTestLoader.loadTestsFromDircCs�tjd|�yodd�|jjj|�D�}|r[dd�|D�}|j|�St|d�j�td|��Wnet	t
fk
r��YnKtj�}|jt
|d|d|d	d
|ddf�g�SYnXdS)z�Load tests from a non-module file. Default is to raise a
        ValueError; plugins may implement `loadTestsFromFile` to
        provide a list of tests loaded from the file.
        zLoad from non-module file %scSsg|]}|�qSr,r,)�.0r_r,r,r-�
<listcomp>�s	z0TestLoader.loadTestsFromFile.<locals>.<listcomp>cSsg|]}|r|�qSr,r,)raZ_fr,r,r-rb�s	�rz!Unable to load tests from file %sr���addressN)rHrIrrJrSr&�open�close�
ValueErrorrUrVrWrXr)r+�filenamer^�excr,r,r-rS�s"	
zTestLoader.loadTestsFromFilecs4�|��fdd�}�j|d�dd�S)z�Lazy-load tests from a generator function. The generator function
        may yield either:

        * a callable, or
        * a function name resolvable within the same module
        c
3s�y_xX|�D]M}�j|�\}}t|�sCt||�}t|d|d|�Vq
WWnQtk
rv�Yn=tj�}t|d|d|ddt���VYnXdS)N�arg�
descriptorrrdrerf)	�parseGeneratedTest�callabler.rrUrWrXrr)�g�mr_�	test_funcrlrk)�	generatorr+r,r-�generate�s
z3TestLoader.loadTestsFromGenerator.<locals>.generate�context�	can_splitF)r&)r+rs�modulertr,)rsr+r-�loadTestsFromGenerator�s
z!TestLoader.loadTestsFromGeneratorcspt�d�r�jj}|�}�j}t||���|��fdd�}�j|d�dd�S)z�Lazy-load tests from a generator method.

        This is more complicated than loading from a generator function,
        since a generator method may yield:

        * a function
        * a bound or unbound method, or
        * a method name
        Zim_classc
3sy�x�|�D]�}�j|�\}}t|�sLt|t||��}t|�rrt|d|d|�Vq
t|�r�t|d|d|�Vq
ttd|�Vq
WWnQtk
r��Yn=t	j
�}t|d|d|ddt���VYnXdS)	Nrlrmr_z%s is not a callable or methodrrdrerf)rnrorr.rrr�	TypeErrorrUrWrXr)rp�cr_rrrlrk)rsr+r,r-rts$
z9TestLoader.loadTestsFromGeneratorMethod.<locals>.generaterurvF)r:�__self__�	__class__�__name__r.r&)r+rsr1�inst�methodrtr,)rsr+r-�loadTestsFromGeneratorMethods		z'TestLoader.loadTestsFromGeneratorMethodFcs9tjd��g}g}g}|s;�jj��r�xt��D]q}t�|d�}t|�r��jj|�r�|j|�qHt	|�rH�jj
|�rH|j|�qHWt|dd��t|t���fdd�||D�}t�dg�}	|r3t
jjt
jj|��}x�|	D]�}
tjd|
�tjd	|t
jj|
�t
jjt
jj|
����jjs�|s�t
jjt
jj|
��j|�r:t
jj|
�r:|j�j|
��q:Wx-�jjj�|�D]}|j|�q	W�jt|d
���S)z�Load all tests from module and return a suite containing
        them. If the module has been discovered and is not test-like,
        the suite will be empty by default, though plugins may add
        their own tests.
        zLoad from module %sNcSs|jS)N)r})�xr,r,r-rGJsz0TestLoader.loadTestsFromModule.<locals>.<lambda>cs%g|]}�j|d���qS)�parent)�makeTest)ra�t)rwr+r,r-rbLs	z2TestLoader.loadTestsFromModule.<locals>.<listcomp>�__path__zLoad tests from module path %s?z!path: %s os.path.realpath(%s): %sru)rHrIr$Z
wantModuler9r.rZ	wantClassrTrZwantFunctionrrrKr>�normcase�realpathrZtraverseNamespacerM�isdir�extendrErJ�loadTestsFromModuler&r)r+rwr>rDr^Ztest_classesZ
test_funcsr3r_Zmodule_paths�module_pathr,)rwr+r-r�4s>
 
		zTestLoader.loadTestsFromModulecsjtjd||��j}�jjj||�}|rD||�St|d�j�}|r>|jrq|j}�j	||�\}}t
|�r�t|dd�|jkr�t
|t�r�t||j�}t||j�}tjd|||�t
|t�r||g�S|t�j||�gd|��Sn(|jray�|jdkrkt|j�}n[�jjj|j|j�z�jj|j|j�}Wd�jjj|j|j�XWn_ttfk
r��YnEtj�}	|t|	d|	d|	d	d
|j��g�SYnX|jrE�j|j|�S�j||jd|�Sn|jr@|j�|jr�t��}
|
dkr�|tt d|j�fd
|j��g�S�j|jd
|
�St!��r�t"��fdd��St#��r�j$��S|tt%d�d
|j��g�Sn&|tt d|d
|j��g�SdS)z�Load tests from the entity with the given name.

        The name may indicate a file, directory, module, or any object
        within a module. See `nose.util.split_test_name` for details on
        test name parsing.
        zload from %s (%s)r �
__module__Nzparent %s obj %s module %srurrdrerfrDz>Can't find callable %s in file %s: file is not a python modulerwcs
�j��S)N)rEr,)r>r+r,r-rG�sz.TestLoader.loadTestsFromName.<locals>.<lambda>zNo such file %szUnresolvable test name %s)&rHrIr&rrJrRr
r �call�resolverr.r}�
isinstancerrrr�rwrjrZbeforeImportr!ZimportFromPathZafterImportrUrVrWrXZtotupler�rrirPrrOrS�OSError)r+�namerwrD�suite�
plug_tests�addrr��objrk�packager,)r>r+r-rRhs�	

		

			
			
zTestLoader.loadTestsFromNamecCst|jjj||�}|r^|\}}|r^|j|j|�tjj|||�g�Stjj|||�S)zSLoad tests from all names, returning a suite containing all
        tests.
        )rrJ�loadTestsFromNamesr&r)r)r+�namesrwZplug_resr�r,r,r-r��szTestLoader.loadTestsFromNamescs�g}|jj}x$|j|�D]}|j|�q"W|sUtt|�j|�S|jdd�tt|�j|�D��|j|�S)z6Load tests from a unittest.TestCase subclass.
        cSsg|]}|�qSr,r,)ra�caser,r,r-rb�s	z4TestLoader.loadTestsFromTestCase.<locals>.<listcomp>)rrJ�loadTestsFromTestCaserT�superrr�r&)r+r<r=rJr�)r|r,r-r��s	z TestLoader.loadTestsFromTestCasecs���jdd�}��fdd�t|t���D�}x*�jjj��D]}|j|�qVW�jt|d���S)a!Load tests from a test class that is *not* a unittest.TestCase
        subclass.

        In this case, we can't depend on the class's `__init__` taking method
        name arguments, so we have to compose a MethodTestCase for each
        method in the class that looks testlike.
        cSsMt||d�}t|�r0t||�}nt|�s@dS|j|�S)NF)r.rrrr/)r0r1r2r3r,r,r-r4�sz1TestLoader.loadTestsFromTestClass.<locals>.wantedcs+g|]!}�jt�|����qSr,)r�r.)rar�)r1r+r,r-rbs	z5TestLoader.loadTestsFromTestClass.<locals>.<listcomp>ru)	r$r8r9rrJ�loadTestsFromTestClassrTr&r)r+r1r4r=r_r,)r1r+r-r��sz!TestLoader.loadTestsFromTestClasscCs�y|j||�SWn�ttfk
r1�Ynktj�}yt|�}Wn"tk
rg�Ynd}YnXt|d|d|dd|�SYnXdS)Nrrdrerf)�	_makeTestrUrVrWrXrr)r+r�r�rkr�r,r,r-r�s
zTestLoader.makeTestcCsgg}yt|�}Wn"tk
r-�Ynd}YnXx-|jjj||�D]}|j|�qTWy|r�|j|�SWnPttfk
r��Yn6tj	�}t
|d|d|dd|�SYnXt|�r	|r	t|t
j�r	t||�}t|tj�r|St|�r�|rU|j|jkrUt||j�}t|tj�rt|j|�S|j|�Sn�t|�r�|dkr�|j}t|tj�r�||j�St|�r�|j||�St|�Snvt|�rL|r#|j|jkr#t||j�}t|�r?|j||�St |�Snt
t!d|d|�SdS)zVGiven a test object and its parent, return a test case
        or test suite.
        NrrdrerfzCan't make a test from %s)"rrUrrJr�rTr&rVrWrXrrr��types�
ModuleTyperr)�TestCaserr�r}r�
issubclassr�r�rr|rr�rrrxrry)r+r�r�r�r�r_rkr,r,r-r�sX
'%
	



zTestLoader._makeTestcCsh|}|jd�}x'|D]}|t||d�}}qW|dkr^ttd|�}||fS)z#Resolve name within module
        rBNzNo such test %s)�splitr.rri)r+r�rwr��parts�partr�r,r,r-r�Rs
zTestLoader.resolvecCs�t|t�s"|t�}}n\t|�dkrK|dt�}}n3t|�dksct�|d|dd�}}||fS)z�Given the yield value of a test generator, return a func and args.

        This is used in the two loadTestsFromGenerator* methods.

        rdrN)r��tuple�len�AssertionError)r+r_rrrlr,r,r-rn^szTestLoader.parseGeneratedTest)r}r��__qualname__�__doc__rr!r r$r&r*r6r?rArErSrxr�r�rRr�r�r�r�r�r�rnr,r,)r|r-r,s0	)M,4l;);r��loggingrKrWr)r��inspectrZnose.pyversionrrZ	nose.caserrZnose.failurerZnose.configrZ
nose.importerr	r
rZ
nose.selectorrr
Z	nose.utilrrrrrrrrrrZ
nose.suiterrrrr�	getLoggerr}rHr>�normpathr"�abspathr#�joinrNr�rP�isfilerO�__all__rrr,r,r,r-�<module>s4F��C