a
    ñ»jy#  ã                   @   sº   d 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m	Z	 ddlm
Z
mZmZ e e¡Zg d¢ZejjZejjZejjZejjZejjZejjZG dd„ deƒZeZ G d	d
„ d
eƒZ!dS )z�
Test Selection
--------------
The test loader calls the appropriate selector method for each object
it encounters that it thinks may be a test.é    N)ÚConfig)Úsplit_test_nameÚsrcÚgetfilename)Ú
getpackageÚ	ispackageÚis_executable)ÚSelectorÚdefaultSelectorÚTestAddressc                   @   sX   e Zd Z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„ Zdd„ ZdS )r	   z…Core test selector. Examines test candidates and determines if
    the test candidate should be selected as a test, given the config.c                 C   s   |d u rt ƒ }|  |¡ d S ©N)r   Ú	configure©ÚselfÚconfig© r   ú3E:\soccer\ml_env\Lib\site-packages\nose/selector.pyÚ__init__   s    zSelector.__init__c                 C   s2   || _ |j| _|j| _|j| _|j| _|j| _d S r   )r   ÚexcludeÚignoreFilesÚincludeÚpluginsZ	testMatchÚmatchr   r   r   r   r      s    zSelector.configurec                    sX   | j  ˆ ¡s0| joVdd„ ‡ fdd„| jD ƒD ƒoV| j pVdd„ ‡ fdd„| jD ƒD ƒ S )z˜Does the name match my requirements?
        To match, a name must match config.testMatch OR config.include
        and it must not match config.excludec                 S   s   g | ]}|r|‘qS r   r   ©Ú.0Ú_fr   r   r   Ú
<listcomp>0   s   þz$Selector.matches.<locals>.<listcomp>c                    s   g | ]}|  ˆ ¡‘qS r   ©Úsearch)r   Úinc©Únamer   r   r   1   s   c                 S   s   g | ]}|r|‘qS r   r   r   r   r   r   r   9   s   þc                    s   g | ]}|  ˆ ¡‘qS r   r   ©r   Úexcr    r   r   r   :   s   )r   r   r   r   )r   r!   r   r    r   Úmatches'   s    
ÿÿü
ÿÿòzSelector.matchesc                 C   sx   t |ddƒ}|dur|}n&|j d¡ o>t|tjƒp>|  |j¡}| j |¡}|durft	 
d||¡ |}t	 
d||¡ |S )z¯Is the class a wanted test class?
        A class must be a unittest.TestCase subclass, or match test name
        requirements. Classes that start with _ are always excluded.Ú__test__NÚ_ú$Plugin setting selection of %s to %szwantClass %s? %s)ÚgetattrÚ__name__Ú
startswithÚ
issubclassÚunittestZTestCaser$   r   Ú	wantClassÚlogÚdebug)r   ÚclsÚdeclaredÚwantedÚ
plug_wantsr   r   r   r-   A   s    
üzSelector.wantClassc                    s�   t |ƒ‰ t|ƒr:| j p6dd„ ‡ fdd„| jD ƒD ƒ }n|  ˆ ¡pV| jjoVˆ | jjv }| j |¡}|dur~t 	d||¡ |}t 	d||¡ |S )z²Is the directory a wanted test directory?
        All package directories match, so long as they do not match exclude.
        All other directories must match test requirements.c                 S   s   g | ]}|r|‘qS r   r   r   r   r   r   r   _   s   ÿz*Selector.wantDirectory.<locals>.<listcomp>c                    s   g | ]}|  ˆ ¡‘qS r   r   r"   ©Útailr   r   r   `   ó    Nr'   zwantDirectory %s? %s)
Úop_basenamer   r   r$   r   ZsrcDirsr   ÚwantDirectoryr.   r/   )r   Údirnamer2   r3   r   r4   r   r8   W   s$    ÿþ
ÿÿzSelector.wantDirectoryc                    sª   t |ƒ‰ ‡ fdd„| jD ƒ}|r0t dˆ ¡ dS | jjsPt|ƒrPt d|¡ dS tˆ ƒ\}}|dk}|op|  	ˆ ¡}| j
 |¡}|dur˜t d||¡ |}t d	||¡ |S )
zþIs the file a wanted test file?
        The file must be a python source file and match testMatch or include,
        and not match exclude. Files that match ignore are *never* wanted,
        regardless of plugin, testMatch, include or exclude settings.c                    s   g | ]}|  ˆ ¡r|‘qS r   r   )r   Zignore_this©Úbaser   r   r   x   s   
ÿz%Selector.wantFile.<locals>.<listcomp>z'%s matches ignoreFiles pattern; skippedFz%s is executable; skippedz.pyNzplugin setting want %s to %szwantFile %s? %s)r7   r   r.   r/   r   Z
includeExer   ÚinfoÚop_splitextr$   r   ÚwantFile)r   ÚfileZignore_matchesÚdummyÚextZpysrcr2   r3   r   r:   r   r>   p   s&    
ÿzSelector.wantFilec                 C   sŒ   zt |dƒr|j}n|j}W n ty0   Y dS 0 t|ddƒ}|durL|}n| d¡ o`|  |¡}| j |¡}|durz|}t	 
d||¡ |S )z Is the function a test function?Úcompat_func_nameFr%   Nr&   zwantFunction %s? %s)ÚhasattrrB   r)   ÚAttributeErrorr(   r*   r$   r   ÚwantFunctionr.   r/   )r   ÚfunctionÚfuncnamer1   r2   r3   r   r   r   rE   Œ   s    

zSelector.wantFunctionc                 C   s|   z
|j }W n ty   Y dS 0 | d¡r.dS t|ddƒ}|durH|}n
|  |¡}| j |¡}|durj|}t d||¡ |S )zIs the method a test method?Fr&   r%   NzwantMethod %s? %s)	r)   rD   r*   r(   r$   r   Ú
wantMethodr.   r/   )r   ÚmethodÚmethod_namer1   r2   r3   r   r   r   rH   ¡   s    


zSelector.wantMethodc                 C   sd   t |ddƒ}|dur|}n |  |j d¡d ¡p8|jdk}| j |¡}|durR|}t d||¡ |S )zŽIs the module a test module?
        The tail of the module name must match test requirements.
        One exception: we always want __main__.r%   NÚ.éÿÿÿÿÚ__main__zwantModule %s? %s)r(   r$   r)   Úsplitr   Ú
wantModuler.   r/   )r   Úmoduler1   r2   r3   r   r   r   rO   ¶   s    þzSelector.wantModuleN)r)   Ú
__module__Ú__qualname__Ú__doc__r   r   r$   r-   r8   r>   rE   rH   rO   r   r   r   r   r	      s   r	   c                   @   s2   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ ZdS )r   aª  A test address represents a user's request to run a particular test.
    The user may specify a filename or module (or neither),
    and/or a callable (a class, function, or method).
    The naming format for test addresses is:

    filename_or_module:callable

    Filenames that are not absolute will be made absolute relative to
    the working dir.
    The filename or module part will be considered a module name if it
    doesn't look like a file, that is, if it doesn't exist on the file
    system and it doesn't contain any directory separators and it
    doesn't end in .py.
    Callables may be a class name, function name, method name,
    or class.method specification.Nc                 C   sÌ   |d u rt  ¡ }|| _|| _t|ƒ\| _| _| _t 	d|| j| j| j¡ | jd u rl| jd urlt
| j| jƒ| _| jr°t| jƒ| _t| jƒsštt|| jƒƒ| _| jd u r°t| jƒ| _t 	d|| j| j| j¡ d S )Nz4Test name %s resolved to file %s, module %s, call %sz;Final resolution of test name %s: file %s module %s call %s)ÚosÚgetcwdr!   Ú
workingDirr   ÚfilenamerP   Úcallr.   r/   r   r   Úop_isabsÚ
op_abspathÚop_joinr   )r   r!   rV   r   r   r   r   Ü   s*    ÿ



þzTestAddress.__init__c                 C   s   | j | j| jfS r   )rW   rP   rX   ©r   r   r   r   Útotupleñ   s    zTestAddress.totuplec                 C   s   | j S r   r    r\   r   r   r   Ú__str__ô   s    zTestAddress.__str__c                 C   s   d| j | j| j| jf S )Nz%s: (%s, %s, %s))r!   rW   rP   rX   r\   r   r   r   Ú__repr__÷   s    ÿzTestAddress.__repr__)N)r)   rQ   rR   rS   r   r]   r^   r_   r   r   r   r   r   Ì   s
   
r   )"rS   ÚloggingrT   r,   Znose.configr   Z	nose.utilr   r   r   r   r   r   Ú	getLoggerr)   r.   Ú__all__ÚpathÚjoinr[   Úbasenamer7   ÚexistsZ	op_existsÚsplitextr=   ÚisabsrY   ÚabspathrZ   Úobjectr	   r
   r   r   r   r   r   Ú<module>   s$   
 3