a
    ñ»jvS  ã                   @   sD  d Z ddlZddlZddlZddlZddlZddlmZ ddlm	Z	m
Z
 ddlmZmZ ddlmZ ddlmZ ddlmZmZmZ dd	lmZmZ dd
lmZmZmZmZmZmZm Z m!Z!m"Z"m#Z# ddl$m%Z%m&Z&m'Z' ddlm(Z(m)Z) ddl*Z*e +e,¡Z-ej.j/Z0ej.j1Z2ej.j3Z4ej.j5Z6ej.j7Z8ddgZ9G dd„ dej:ƒZ:e:Z;dS )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ÚdefaultTestLoaderc                       sÀ   e Zd ZdZdZdZdZdZdZd&dd„Z	dd„ Z
dd„ Zd	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Zd'dd„Zd(dd„Zd)dd„Z‡ fdd„Zdd„ Zd*dd„Zd+d d!„Zd"d#„ Zd$d%„ Z‡  ZS ),r   a;  Test 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 pluginsNc                 C   s¤   |du rt ƒ }|du r t|d�}|du r.|j}|du r@t|ƒ}nt|ƒrP||ƒ}|| _|| _tt|ƒƒ| _|| _	|j
r€t||ƒ t|d�| _tƒ | _tj | ¡ dS )aü  Initialize 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)r   r	   Ú
workingDirr   r   r   ÚimporterÚop_normpathÚ
op_abspathÚselectorÚaddPathsr
   r   Ú
suiteClassÚsetÚ_visitedPathsÚunittestr   Ú__init__)Úselfr   r!   r    r$   © r,   ú1E:\soccer\ml_env\Lib\site-packages\nose/loader.pyr*   0   s&    


zTestLoader.__init__c                 C   sf   | j jrtj | |¡S || jfdd„}tt|t|ƒƒƒ}|sLt	|dƒrLdg}| j
rbt|t| j
ƒƒ |S )Nc                 S   s6   t || d ƒ}t|ƒr t||ƒ}nt|ƒs,dS | |¡S ©NF©Úgetattrr   r   r   Z
wantMethod©ÚattrÚclsÚselÚitemr,   r,   r-   ÚwantedX   s    z+TestLoader.getTestCaseNames.<locals>.wantedZrunTest)r   ZgetTestCaseNamesCompatr)   r   ÚgetTestCaseNamesr$   ÚlistÚfilterÚdirÚhasattrZsortTestMethodsUsingr   r   )r+   ÚtestCaseClassr6   Úcasesr,   r,   r-   r7   T   s    zTestLoader.getTestCaseNamesc                 C   s   |d u rdS || j v S r.   )r(   ©r+   Úpathr,   r,   r-   Ú_haveVisitedg   s    zTestLoader._haveVisitedc                 C   s   |d ur| j  |¡ d S ©N)r(   Úaddr>   r,   r,   r-   Ú_addVisitedPathl   s    zTestLoader._addVisitedPathc              	   #   sî  t  d|¡ ˆjj}| |¡ ˆjjr2t|ˆjƒ}t |¡}t	|t
ˆjjƒƒ |D ]ô}| d¡rbqRtt||ƒƒ‰ tˆ ƒ}d}|r’d}ˆj ˆ ¡}n$tˆ ƒ}|r¶| d¡rªqRˆj ˆ ¡}tˆ ƒ}	|rRˆ ˆ ¡sRˆ ˆ ¡ |�r| ¡  | d¡�rˆjˆ dd�V  nˆ ˆ ¡V  | ¡  qR|	�r0ˆjˆ dd�V  qRˆ ‡ ‡fdd	„¡V  qRg }
| |¡D ]}|
 |¡ �qVz|
�r|ˆ |
¡V  W nB tt f�y˜   ‚ Y n* t!�yÀ   ˆ t"t# $¡ Ž g¡V  Y n0 ˆjj�rà|D ]}t%|ƒ �qÐ| &|¡ 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.zload from dir %sÚ.FÚ_z.pyT©Ú
discoveredc                      s
   ˆ  ˆ ¡S rA   ©ÚloadTestsFromDirr,   ©Ú
entry_pathr+   r,   r-   Ú<lambda>¢   ó    z-TestLoader.loadTestsFromDir.<locals>.<lambda>N)'ÚlogÚdebugr   ÚpluginsZbeforeDirectoryr%   r
   ÚosÚlistdirr   r   Z	testMatchÚ
startswithr#   Úop_joinÚ	op_isfiler$   ZwantFileÚop_isdirZwantDirectoryr   r@   rC   ZbeforeContextÚendswithÚloadTestsFromNameÚloadTestsFromFileZafterContextr&   rI   ÚappendÚKeyboardInterruptÚ
SystemExitÚ	Exceptionr   ÚsysÚexc_infor   ZafterDirectory)r+   r?   rP   Zpaths_addedÚentriesÚentryÚis_filer6   Úis_dirÚ
is_packageÚtestsÚtestÚpr,   rJ   r-   rI   p   sj    




ÿ

ÿ
ÿ
zTestLoader.loadTestsFromDirc                 C   sº   t  d|¡ zNt| jj |¡ƒ}|r>dd„ |D ƒ}|  |¡W S t|dƒ ¡  t	d| ƒ‚W nZ t
tfyr   ‚ Y nD ty´   t ¡ }|  t|d |d |d |d	d	fd
�g¡ Y S 0 d	S )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.zLoad from non-module file %sc                 S   s   g | ]}|r|‘qS r,   r,   )Ú.0Ú_fr,   r,   r-   Ú
<listcomp>º   rM   z0TestLoader.loadTestsFromFile.<locals>.<listcomp>Úrz!Unable to load tests from file %sr   é   é   N©Úaddress)rN   rO   r8   r   rP   rY   r&   ÚopenÚcloseÚ
ValueErrorr[   r\   r]   r^   r_   r   )r+   Úfilenamere   Úexcr,   r,   r-   rY   ²   s&    ÿÿÿzTestLoader.loadTestsFromFilec                    s$   ˆ |f‡ ‡fdd„	}ˆj |ˆ dd�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              	   3   sš   zF| ƒ D ]:}ˆ  |¡\}}t|tjjƒs2t||ƒ}t||| d�V  qW nN tyZ   ‚ Y n< ty”   t	 
¡ }t|d |d |d tˆ ƒd�V  Y n0 d S )N©ÚargZ
descriptorr   rl   rm   rn   )ÚparseGeneratedTestÚ
isinstanceÚcollectionsÚabcÚCallabler0   r   r[   r]   r^   r_   r   r   )ÚgÚmrf   Ú	test_funcrv   rt   ©Ú	generatorr+   r,   r-   ÚgenerateÎ   s    

ÿz3TestLoader.loadTestsFromGenerator.<locals>.generateF©ÚcontextZ	can_split)r&   )r+   r€   Úmoduler�   r,   r   r-   ÚloadTestsFromGeneratorÉ   s    z!TestLoader.loadTestsFromGeneratorc                    sL   t ˆ dƒrˆ jj}|ƒ }ˆ j}t||ƒ‰ ˆ |f‡ ‡fdd„	}ˆj|ˆ dd�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 Zim_classc              	   3   sÚ   z†| ƒ D ]z}ˆ  |¡\}}t|tjjƒs8t|t||ƒƒ}t|ƒrRt||| d�V  qt|tjjƒrrt| ||d�V  qt	t
d| ƒV  qW nN tyš   ‚ Y n< tyÔ   t ¡ }t	|d |d |d tˆ ƒd�V  Y n0 d S )Nru   )rf   rv   z%s is not a callable or methodr   rl   rm   rn   )rw   rx   ry   rz   r{   r   r0   r   r   r   Ú	TypeErrorr[   r]   r^   r_   r   )r|   Úcrf   r~   rv   rt   r   r,   r-   r�   ê   s(    
þÿz9TestLoader.loadTestsFromGeneratorMethod.<locals>.generateFr‚   )r;   Ú__self__Ú	__class__Ú__name__r0   r&   )r+   r€   r3   ÚinstÚmethodr�   r,   r   r-   ÚloadTestsFromGeneratorMethodÝ   s    

z'TestLoader.loadTestsFromGeneratorMethodFc                    sŒ  t  dˆ ¡ g }g }g }|r(ˆj ˆ ¡r°tˆ ƒD ]N}tˆ |dƒ}t|ƒr`ˆj |¡r~| |¡ q0t	|ƒr0ˆj 
|¡r0| |¡ q0t|dd„ ƒ t|tƒ ‡ ‡fdd„|| D ƒ}tˆ dg ƒ}	|rÔtj tj |¡¡}|	D ]~}
t  d|
¡ t  d	|tj |
¡tj tj |
¡¡¡ ˆjj�s:|�r:tj tj |
¡¡ |¡rØtj |
¡rØ| ˆ |
¡¡ qØˆjj ˆ |¡D ]}| |¡ �qhˆ t|ˆ d
�¡S )z>Load all tests from module and return a suite containing them.zLoad from module %sNc                 S   s   | j S rA   )rŠ   )Úxr,   r,   r-   rL     rM   z0TestLoader.loadTestsFromModule.<locals>.<lambda>c                    s   g | ]}ˆj |ˆ d �‘qS ))Úparent)ÚmakeTest)rh   Út©r„   r+   r,   r-   rj     s   ÿz2TestLoader.loadTestsFromModule.<locals>.<listcomp>Ú__path__zLoad tests from module path %s?z!path: %s os.path.realpath(%s): %s©rƒ   )rN   rO   r$   Z
wantModuler:   r0   r   Z	wantClassrZ   r   ZwantFunctionr   r   rQ   r?   ÚnormcaseÚrealpathr   ZtraverseNamespacerS   ÚisdirÚextendrI   rP   ÚloadTestsFromModuler&   r   )r+   r„   r?   rG   re   Ztest_classesZ
test_funcsr5   rf   Zmodule_pathsÚmodule_pathr,   r’   r-   r™     sL    
þþ
ÿÿÿzTestLoader.loadTestsFromModulec              
      s¢  t  d||¡ ˆj}ˆjj ||¡}|r0||ƒS t|ˆjd�}|rÜ|jrN|j}ˆ 	||¡\}}t
|ƒršt|ddƒ|jkršt|tƒsšt||jƒ}t||jƒ}t  d|||¡ t|tƒr¾||gƒS |tˆ ||¡g|d�ƒS �nÂ|j�rÚzp|jdu rüt|jƒ}nVˆjj |j|j¡ z*ˆj |j|j¡}W ˆjj |j|j¡ nˆjj |j|j¡ 0 W nZ ttf�yn   ‚ Y nB t�y®   t ¡ }	|t|	d |	d |	d	 | ¡ d
�gƒ Y S 0 |j�rÆˆ |j|¡S ˆj||j|d�S nÄ|j�r‚|j‰ |j�r4t ˆ ƒ}
|
du �r$|tt!d|jˆ f | ¡ d
�gƒS ˆj|j|
d�S t"ˆ ƒ�rPt#‡ ‡fdd„ƒS t$ˆ ƒ�rdˆ %ˆ ¡S |tt&dˆ  | ¡ d
�gƒS n|tt!d| | ¡ d
�gƒS dS )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.zload from %s (%s))r    Ú
__module__Nzparent %s obj %s module %sr”   r   rl   rm   rn   rF   z>Can't find callable %s in file %s: file is not a python module)r„   c                      s
   ˆ  ˆ ¡S rA   rH   r,   ©r?   r+   r,   r-   rL   l  rM   z.TestLoader.loadTestsFromName.<locals>.<lambda>zNo such file %szUnresolvable test name %s)'rN   rO   r&   r   rP   rX   r   r    ÚcallÚresolver   r0   rŠ   rx   r   r   r   r�   r„   rs   r   ZbeforeImportr!   ZimportFromPathZafterImportr[   r\   r]   r^   r_   Ztotupler™   r   rr   rV   r   rU   rY   ÚOSError)r+   Únamer„   rG   ÚsuiteÚ
plug_testsÚaddrr�   Úobjrt   Úpackager,   rœ   r-   rX   *  s¤    ÿþý

ÿ
ÿÿÿÿ
ÿÿ
þüÿ


ýÿ
ÿÿzTestLoader.loadTestsFromNamec                 C   sP   | j j ||¡}|r@|\}}|r@|  |  |¡tj | ||¡g¡S tj | ||¡S )zALoad tests from all names, returning a suite containing all tests)r   rP   ÚloadTestsFromNamesr&   r)   r   )r+   Únamesr„   Zplug_resr¡   r,   r,   r-   r¦   |  s    þzTestLoader.loadTestsFromNamesc                    s^   g }| j j}| |¡D ]}| |¡ q|s:tt| ƒ |¡S | ttt| ƒ |¡ƒ¡ |  |¡S )z-Load tests from a unittest.TestCase subclass.)	r   rP   ÚloadTestsFromTestCaserZ   Úsuperr   r˜   r8   r&   )r+   r<   r=   rP   Úcase©r‰   r,   r-   r¨   ˆ  s    ÿz TestLoader.loadTestsFromTestCasec                    s^   ˆ ˆj fdd„}‡ ‡fdd„t|tˆ ƒƒD ƒ}ˆjj ˆ ¡D ]}| |¡ q<ˆ t|ˆ d�¡S )zALoad tests from a class that is NOT a unittest.TestCase subclass.c                 S   s6   t || d ƒ}t|ƒr t||ƒ}nt|ƒs,dS | |¡S r.   r/   r1   r,   r,   r-   r6   –  s    z1TestLoader.loadTestsFromTestClass.<locals>.wantedc                    s   g | ]}ˆ  tˆ |ƒˆ ¡‘qS r,   )r�   r0   )rh   rª   ©r3   r+   r,   r-   rj   �  s   ÿz5TestLoader.loadTestsFromTestClass.<locals>.<listcomp>r”   )	r$   r9   r:   r   rP   ÚloadTestsFromTestClassrZ   r&   r   )r+   r3   r6   r=   rf   r,   r¬   r-   r­   ”  s    ÿz!TestLoader.loadTestsFromTestClassc                 C   s–   z|   ||¡W S  ttfy&   ‚ Y nl ty�   t ¡ }zt|ƒ}W n( tyZ   ‚ Y n tyn   d }Y n0 t|d |d |d |d� Y S 0 d S )Nr   rl   rm   rn   )Ú	_makeTestr[   r\   r]   r^   r_   r   r   )r+   r¤   r�   rt   r£   r,   r,   r-   r�   £  s    
zTestLoader.makeTestc              	   C   sî  g }zt |ƒ}W n( ty$   ‚ Y n ty8   d}Y n0 | jj ||¡D ]}| |¡ qJz|rl|  |¡W S W nL ttfy†   ‚ Y n6 tyº   t	 
¡ }t|d |d |d |d� Y S 0 t|ƒrÞ|rÞt|tjƒsÞt||ƒ}t|tjƒrî|S t|ƒ�r<|�r|j|jk�rt||jƒ}t|tjƒ�r0|  |¡S |  |¡S n®t|ƒ�rŽ|du �rV|j}t|tjƒ�rn||jƒS t|ƒ�r„|  ||¡S t|ƒS n\t|ƒ�rØ|�r¸|j|jk�r¸t||jƒ}t|ƒ�rÎ|   ||¡S t!|ƒS ntt"d| |d�S dS )z@Given a test object and its parent, return a test case or suite.Nr   rl   rm   rn   zCan't make a test from %s)#r   r[   r]   r   rP   r�   rZ   r&   r\   r^   r_   r   r   rx   ÚtypesÚ
ModuleTyper   r)   ZTestCaser   r›   rŠ   r   Ú
issubclassr¨   r­   r   r‰   r   r�   r   r   r…   r   r†   )r+   r¤   r�   r¢   r£   rf   rt   r,   r,   r-   r®   ²  sb    
"ÿþ
ý











ÿzTestLoader._makeTestc                 C   sH   |}|  d¡}|D ]}|t||dƒ }}q|du r@ttd| ƒ}||fS )zResolve name within module.rD   NzNo such test %s)Úsplitr0   r   rr   )r+   r    r„   r¤   ÚpartsÚpartr�   r,   r,   r-   rž   é  s    
zTestLoader.resolvec                 C   s`   t |tƒs|d }}nBt|ƒdkr2|d d }}n&t|ƒdksBJ ‚|d |dd…  }}||fS )zƒGiven the yield value of a test generator, return a func and args.
        This is used in the two loadTestsFromGenerator* methods.r,   rl   r   N)rx   ÚtupleÚlen)r+   rf   r~   rv   r,   r,   r-   rw   ó  s    
zTestLoader.parseGeneratedTest)NNNN)NF)NF)N)N)N)rŠ   r›   Ú__qualname__Ú__doc__r   r!   r    r$   r&   r*   r7   r@   rC   rI   rY   r…   r�   r™   rX   r¦   r¨   r­   r�   r®   rž   rw   Ú__classcell__r,   r,   r«   r-   r   #   s2     ÿ
$B%
(
R


7
)<r¸   ÚloggingrQ   r^   r)   r¯   Úinspectr   Znose.pyversionr   r   Z	nose.caser   r   Znose.failurer   Znose.configr   Znose.importerr	   r
   r   Znose.selectorr   r   Z	nose.utilr   r   r   r   r   r   r   r   r   r   Z
nose.suiter   r   r   r   r   ry   Ú	getLoggerrŠ   rN   r?   Únormpathr"   Úabspathr#   ÚjoinrT   r—   rV   ÚisfilerU   Ú__all__r   r   r,   r,   r,   r-   Ú<module>   s8   0
   `