B
    ֐<[#                 @   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	m
Z
mZmZ eeZdddg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
--------------

Test selection is handled by a Selector. 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	   zCore test selector. Examines test candidates and determines whether,
    given the specified configuration, the test candidate should be selected
    as a test.
    c             C   s   |d krt  }| | d S )N)r   	configure)selfconfig r   ,lib/python3.7/site-packages/nose/selector.py__init__"   s    zSelector.__init__c             C   s2   || _ |j| _|j| _|j| _|j| _|j| _d S )N)r   excludeignoreFilesincludepluginsZ	testMatchmatch)r   r   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 )zDoes the name match my requirements?

        To match, a name must match config.testMatch OR config.include
        and it must not match config.exclude
        c             S   s   g | ]}|r|qS r   r   ).0_fr   r   r   
<listcomp>7   s    z$Selector.matches.<locals>.<listcomp>c                s   g | ]}|  qS r   )search)r   Zinc)namer   r   r   7   s    c             S   s   g | ]}|r|qS r   r   )r   r   r   r   r   r   9   s    c                s   g | ]}|  qS r   )r   )r   exc)r   r   r   r   9   s    )r   r   r   r   )r   r   r   )r   r   matches/   s
    zSelector.matchesc             C   sx   t |dd}|dk	r|}n&|jd o>t|tjp>| |j}| j|}|dk	rft	
d|| |}t	
d|| |S )zIs 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_z$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%   <   s    zSelector.wantClassc                s   t | t|r:| j p6dd  fdd| jD D  }n|  pV| jjoV | jjk}| j|}|dk	r~t	d|| |}t	d|| |S )zIs 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   r   Z   s    z*Selector.wantDirectory.<locals>.<listcomp>c                s   g | ]}|  qS r   )r   )r   r   )tailr   r   r   Z   s    Nz$Plugin setting selection of %s to %szwantDirectory %s? %s)
op_basenamer   r   r   r   ZsrcDirsr   wantDirectoryr&   r'   )r   dirnamer*   r+   r   )r,   r   r.   Q   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k	rtd|| |}td	|| |S )
a  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   q   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)r-   r   r&   r'   r   Z
includeExer   infoop_splitextr   r   wantFile)r   fileZignore_matchesZdummyZextZpysrcr*   r+   r   )r0   r   r3   g   s$    	zSelector.wantFilec             C   s   yt |dr|j}n|j}W n tk
r0   dS X t|dd}|dk	rL|}n|d o`| |}| j|}|dk	rz|}t	
d|| |S )z)Is the function a test function?
        compat_func_nameFr   Nr   zwantFunction %s? %s)hasattrr5   r!   AttributeErrorr    r"   r   r   wantFunctionr&   r'   )r   Zfunctionfuncnamer)   r*   r+   r   r   r   r8      s    

zSelector.wantFunctionc             C   s|   y
|j }W n tk
r   dS X |dr.dS t|dd}|dk	rH|}n
| |}| j|}|dk	rj|}td|| |S )z%Is the method a test method?
        Fr   r   NzwantMethod %s? %s)	r!   r7   r"   r    r   r   
wantMethodr&   r'   )r   methodZmethod_namer)   r*   r+   r   r   r   r:      s    


zSelector.wantMethodc             C   sd   t |dd}|dk	r|}n | |jdd p8|jdk}| j|}|dk	rR|}td|| |S )zIs 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   moduler)   r*   r+   r   r   r   r@      s    
zSelector.wantModuleN)r!   
__module____qualname____doc__r   r   r   r%   r.   r3   r8   r:   r@   r   r   r   r   r	      s   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 krt  }|| _|| _t|\| _| _| _t	d|| j| j| j | jd krl| jd k	rlt
| j| j| _| jrt| j| _t| jstt|| j| _| jd krt| 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   filenamerA   callr&   r'   r   r   op_isabs
op_abspathop_joinr   )r   r   rG   r   r   r   r      s(    



zTestAddress.__init__c             C   s   | j | j| jfS )N)rH   rA   rI   )r   r   r   r   totuple   s    zTestAddress.totuplec             C   s   | j S )N)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   rH   rA   rI   )r   r   r   r   __repr__   s    
zTestAddress.__repr__)N)r!   rB   rC   rD   r   rM   rN   rO   r   r   r   r   r      s
   
)"rD   ZloggingrE   r$   Znose.configr   Z	nose.utilr   r   r   r   r   r   Z	getLoggerr!   r&   __all__pathjoinrL   basenamer-   existsZ	op_existssplitextr2   isabsrJ   abspathrK   objectr	   r
   r   r   r   r   r   <module>   s"    

 '