B t `#@sdZddlZddlZddlZddlmZddlmZmZm Z m Z m Z m Z e eZdddgZejjZejjZejjZejjZejjZejjZGdddeZeZ Gd ddeZ!dS) 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_namesrc getfilename getpackage ispackage is_executableSelectordefaultSelector TestAddressc@sXeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ dS)r zCore test selector. Examines test candidates and determines whether, given the specified configuration, the test candidate should be selected as a test. cCs|dkrt}||dS)N)r configure)selfconfigr1/tmp/pip-unpacked-wheel-cjhnoqsi/nose/selector.py__init__"szSelector.__init__cCs2||_|j|_|j|_|j|_|j|_|j|_dS)N)rexclude ignoreFilesincludepluginsZ testMatchmatch)r rrrrr 's zSelector.configurecsX|js0|joVddfdd|jDDoV|j pVddfdd|jDD 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 cSsg|] }|r|qSrr).0_frrr 7sz$Selector.matches..csg|]}|qSr)search)rinc)namerrr7scSsg|] }|r|qSrr)rrrrrr9scsg|]}|qSr)r)rexc)rrrr9s)rrrr)r rr)rrmatches/s  zSelector.matchescCsxt|dd}|dk r|}n&|jd o>t|tjp>||j}|j|}|dk 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 %szwantClass %s? %s) getattr__name__ startswith issubclassunittestZTestCaserr wantClasslogdebug)r clsdeclaredwanted plug_wantsrrrr&<s    zSelector.wantClasscst|t|r:|j p6ddfdd|jDD }n|pV|jjoV|jjk}|j|}|dk 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. cSsg|] }|r|qSrr)rrrrrrZsz*Selector.wantDirectory..csg|]}|qSr)r)rr)tailrrrZsNz$Plugin setting selection of %s to %szwantDirectory %s? %s) op_basenamerrrrZsrcDirsr wantDirectoryr'r()r dirnamer+r,r)r-rr/Qs"   zSelector.wantDirectorycst|fdd|jD}|r0tddS|jjsPt|rPtd|dSt\}}|dk}|op| }|j |}|dk rtd|||}td |||S) aIs 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. csg|]}|r|qSr)r)rZ ignore_this)baserrrqsz%Selector.wantFile..z'%s matches ignoreFiles pattern; skippedFz%s is executable; skippedz.pyNzplugin setting want %s to %szwantFile %s? %s) r.rr'r(rZ includeExerinfo op_splitextrrwantFile)r fileZignore_matchesdummyextZpysrcr+r,r)r1rr4gs$    zSelector.wantFilecCsyt|dr|j}n|j}Wntk r0dSXt|dd}|dk rL|}n|d o`||}|j|}|dk rz|}t d|||S)z)Is the function a test function? compat_func_nameFrNr zwantFunction %s? %s) hasattrr8r"AttributeErrorr!r#rr wantFunctionr'r()r functionfuncnamer*r+r,rrrr;s    zSelector.wantFunctioncCs|y |j}Wntk rdSX|dr.dSt|dd}|dk rH|}n ||}|j|}|dk rj|}td|||S)z%Is the method a test method? Fr rNzwantMethod %s? %s) r"r:r#r!rr wantMethodr'r()r method method_namer*r+r,rrrr>s     zSelector.wantMethodcCsdt|dd}|dk r|}n ||jddp8|jdk}|j|}|dk rR|}td|||S)zIs the module a test module? The tail of the module name must match test requirements. One exception: we always want __main__. rN.__main__zwantModule %s? %s)r!rr"splitr wantModuler'r()r moduler*r+r,rrrrEs   zSelector.wantModuleN) r" __module__ __qualname____doc__rr rr&r/r4r;r>rErrrrr s c@s2eZdZdZd ddZddZddZd d ZdS) r aA 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. NcCs|dkrt}||_||_t|\|_|_|_t d||j|j|j|jdkrl|jdk rlt |j|j|_|jrt |j|_t |jst t||j|_|jdkrt|j|_t d||j|j|jdS)Nz4Test name %s resolved to file %s, module %s, call %sz;Final resolution of test name %s: file %s module %s call %s)osgetcwdr workingDirrfilenamerFcallr'r(rrop_isabs op_abspathop_joinr)r rrLrrrrs(       zTestAddress.__init__cCs|j|j|jfS)N)rMrFrN)r rrrtotupleszTestAddress.totuplecCs|jS)N)r)r rrr__str__szTestAddress.__str__cCsd|j|j|j|jfS)Nz%s: (%s, %s, %s))rrMrFrN)r rrr__repr__s zTestAddress.__repr__)N)r"rGrHrIrrRrSrTrrrrr s  )"rIloggingrJr%Z nose.configrZ nose.utilrrrrrr getLoggerr"r'__all__pathjoinrQbasenamer.existsZ op_existssplitextr3isabsrOabspathrPobjectr r r rrrrs"    '