o
    g#                     @   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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
--------------

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 u rt  }| | d S N)r   	configureselfconfig r   K/home/ubuntu/cloudmapper/venv/lib/python3.10/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plugins	testMatchmatchr   r   r   r   r   '   s   zSelector.configurec                    sX   | j  s| jodd  fdd| jD D o+| j p+d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      g | ]}|r|qS r   r   .0_fr   r   r   
<listcomp>7       z$Selector.matches.<locals>.<listcomp>c                       g | ]}|  qS r   search)r   incnamer   r   r   7       c                 S   r   r   r   r   r   r   r   r   9   r   c                    r    r   r!   r   excr$   r   r   r   9   r&   )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r3t	
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_$Plugin setting selection of %s to %szwantClass %s? %s)getattr__name__
startswith
issubclassunittestTestCaser)   r   	wantClasslogdebug)r   clsdeclaredwanted
plug_wantsr   r   r   r3   <   s   
zSelector.wantClassc                    s   t | t|r| j pdd  fdd| jD D  }n|  p+| jjo+ | jjv }| j|}|du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   r   r   r   r   r   r   r   r   Z   r   z*Selector.wantDirectory.<locals>.<listcomp>c                    r    r   r!   r'   tailr   r   r   Z   r&   Nr,   zwantDirectory %s? %s)
op_basenamer   r   r)   r   srcDirsr   wantDirectoryr4   r5   )r   dirnamer8   r9   r   r:   r   r>   Q   s"   

zSelector.wantDirectoryc                    s   t |  fdd| jD }|rtd  dS | jjs(t|r(td| dS t \}}|dk}|o8| 	 }| j
|}|durLt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   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   r4   r5   r   
includeExer   infoop_splitextr)   r   wantFile)r   fileignore_matchesdummyextpysrcr8   r9   r   rA   r   rF   g   s&   	zSelector.wantFilec                 C   s   zt |dr
|j}n|j}W n
 ty   Y dS w t|dd}|dur&|}n|d o0| |}| j|}|dur=|}t	
d|| |S )z)Is the function a test function?
        compat_func_nameFr*   Nr+   zwantFunction %s? %s)hasattrrL   r.   AttributeErrorr-   r/   r)   r   wantFunctionr4   r5   )r   functionfuncnamer7   r8   r9   r   r   r   rO      s"   
zSelector.wantFunctionc                 C   s|   z|j }W n
 ty   Y dS w |drdS t|dd}|dur$|}n| |}| j|}|dur5|}td|| |S )z%Is the method a test method?
        Fr+   r*   NzwantMethod %s? %s)	r.   rN   r/   r-   r)   r   
wantMethodr4   r5   )r   methodmethod_namer7   r8   r9   r   r   r   rR      s    


zSelector.wantMethodc                 C   sd   t |dd}|dur|}n| |jdd p|jdk}| j|}|dur)|}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   
wantModuler4   r5   )r   moduler7   r8   r9   r   r   r   rY      s   zSelector.wantModuleN)r.   
__module____qualname____doc__r   r   r)   r3   r>   rF   rO   rR   rY   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 r6| jd ur6t
| j| j| _| jrXt| j| _t| jsMtt|| j| _| jd u rXt| 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   filenamerZ   callr4   r5   r   r   op_isabs
op_abspathop_joinr   )r   r%   r`   r   r   r   r      s.   



zTestAddress.__init__c                 C   s   | j | j| jfS r   )ra   rZ   rb   r   r   r   r   totuple   s   zTestAddress.totuplec                 C   s   | j S r   r$   rf   r   r   r   __str__   s   zTestAddress.__str__c                 C   s   d| j | j| j| jf S )Nz%s: (%s, %s, %s))r%   ra   rZ   rb   rf   r   r   r   __repr__   s   
zTestAddress.__repr__r   )r.   r[   r\   r]   r   rg   rh   ri   r   r   r   r   r      s    
r   )"r]   loggingr^   r1   nose.configr   	nose.utilr   r   r   r   r   r   	getLoggerr.   r4   __all__pathjoinre   basenamer<   exists	op_existssplitextrE   isabsrc   abspathrd   objectr	   r
   r   r   r   r   r   <module>   s$     
 '