ó J9•Qc@sÒdZddlmZddlZddlZddlZddlZddlZddlm Z ddl m Z m Z ddl mZmZddlmZddlmZdd lmZmZmZdd lmZmZdd lmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%dd l&m'Z'm(Z(m)Z)dd l m*Z*m+Z+ej,e-ƒZ.ej/j0Z1ej/j2Z3ej/j4Z5ej/j6Z7ej/j8Z9ddgZ:dej;fd„ƒYZ;e;Z<dS(sß 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. iÿÿÿÿ(t generatorsN(t isfunction(tunbound_methodtismethod(tFunctionTestCasetMethodTestCase(tFailure(tConfig(tImportertadd_patht remove_path(tdefaultSelectort TestAddress( t func_linenot getpackagetisclasst isgeneratort ispackagetregex_last_keyt resolve_namettransplant_functtransplant_classt test_address(tContextSuiteFactoryt ContextListt LazySuite(t sort_listt cmp_to_keyt TestLoadertdefaultTestLoadercBsæeZdZdZdZdZdZdZddddd„Z d„Z d„Z d„Z d„Z d„Zd„Zd„Zded „Zded „Zdd „Zd „Zd „Zdd„Zdd„Zd„Zd„ZRS(sATest 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 plugins cCs|dkrtƒ}n|dkr6td|ƒ}n|dkrN|j}n|dkrit|ƒ}nt|ƒr„||ƒ}n||_||_tt |ƒƒ|_||_ |j rÍt ||ƒnt d|ƒ|_tgƒ|_tjj|ƒdS(sInitialize 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. tconfigN(tNoneRRt workingDirR RRtimportert op_normpatht op_abspathtselectortaddPathsR Rt suiteClasstsett _visitedPathstunittestRt__init__(tselfRR!R R$((s//sys/lib/python2.7/site-packages/nose/loader.pyR*;s&           cCsØ|jjrtjj||ƒS||jd„}t|t|ƒƒ}xG|jD]<}x3|j|ƒD]"}||krf|j |ƒqfqfWqPW| r²t |dƒr²dg}n|j rÔt |t |j ƒƒn|S(s_Override to select with selector, unless config.getTestCaseNamesCompat is True cSsMt||dƒ}t|ƒr0t||ƒ}nt|ƒs@tS|j|ƒS(N(tgetattrRRRRtFalset wantMethod(tattrtclstseltitem((s//sys/lib/python2.7/site-packages/nose/loader.pytwantedls   trunTest(RtgetTestCaseNamesCompatR)RtgetTestCaseNamesR$tfiltertdirt __bases__tappendthasattrtsortTestMethodsUsingRR(R+t testCaseClassR3tcasestbasetcase((s//sys/lib/python2.7/site-packages/nose/loader.pyR6es    cCs|dkrtS||jkS(N(RR-R((R+tpath((s//sys/lib/python2.7/site-packages/nose/loader.pyt _haveVisiteds cCs#|dk r|jj|ƒndS(N(RR(tadd(R+RA((s//sys/lib/python2.7/site-packages/nose/loader.pyt_addVisitedPath‡s c #s™tjd|ƒˆjj}|j|ƒˆjjrJt|ˆjƒ}ntj|ƒ}t |t ˆjj ƒƒxa|D]Y}|j dƒr”qynt t||ƒƒ‰tˆƒ}t}|rÜt}ˆjjˆƒ}n<tˆƒ}|r|j dƒrqynˆjjˆƒ}ntˆƒ} |ryˆjˆƒ ryˆjˆƒ|r˜|jƒ|jdƒr}ˆjˆdtƒVnˆjˆƒV|jƒqÒ| rµˆjˆdtƒVqÒˆj‡‡fd†ƒVqyqyWg} x$|j|ƒD]} | j | ƒqìWy| rˆj| ƒVnWn=t!t"fk r:‚n$ˆjt#t$j%ƒŒgƒVnXˆjjrˆx|D]} t&| ƒqqWn|j'|ƒdS(sÚ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. sload from dir %st.t_s.pyt discoveredcs ˆjˆƒS(N(tloadTestsFromDir((t entry_pathR+(s//sys/lib/python2.7/site-packages/nose/loader.pytÅsN((tlogtdebugRtpluginstbeforeDirectoryR%R tostlistdirRRt testMatcht startswithR#top_joint op_isfileR-R$twantFiletop_isdirt wantDirectoryRRBRDt beforeContexttendswithtloadTestsFromNametTruetloadTestsFromFilet afterContextR&RHR:tKeyboardInterruptt SystemExitRtsystexc_infoR tafterDirectory( R+RARMt paths_addedtentriestentrytis_fileR3tis_dirt is_packagetteststtesttp((RIR+s//sys/lib/python2.7/site-packages/nose/loader.pyRH‹sd          !  c Csètjd|ƒyqg|jjj|ƒD] }|^q)}|r]td|ƒ}|j|ƒSt|dƒj ƒt d|ƒ‚Wn`t t fk r‚nGt jƒ}|jt|d|d|dd|ddfƒgƒSXdS( s¸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. sLoad from non-module file %strs!Unable to load tests from file %siiitaddressN(RKRLRRMR\R7RR&topentcloset ValueErrorR^R_R`RaR(R+tfilenameRjRitexc((s//sys/lib/python2.7/site-packages/nose/loader.pyR\Øs"%  cs1ˆ|‡‡fd†}ˆj|dˆdtƒS(sºLazy-load tests from a generator function. The generator function may yield either: * a callable, or * a function name resolvable within the same module c3s¸ybx[|ƒD]P}ˆj|ƒ\}}t|ƒsFt||ƒ}nt|d|d|ƒVq WWnOtk rx‚n<tjƒ}t|d|d|ddtˆƒƒVnXdS(Ntargt descriptoriiiRm( tparseGeneratedTesttcallableR,RR^R`RaRR(tgtmRjt test_funcRsRr(t generatorR+(s//sys/lib/python2.7/site-packages/nose/loader.pytgenerateûs   tcontextt can_split(R&R-(R+RztmoduleR{((RzR+s//sys/lib/python2.7/site-packages/nose/loader.pytloadTestsFromGeneratorôs csmtˆdƒrˆj}n|ƒ}ˆj}t||ƒ‰ˆ|‡‡fd†}ˆj|dˆdtƒS(sý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 tim_classc3sy²x«|ƒD] }ˆj|ƒ\}}t|ƒsOt|t||ƒƒ}nt|ƒrut|d|d|ƒVq t|ƒr›t|d|d|ƒVq ttd|ƒVq WWnOt k rÈ‚n<t j ƒ}t|d|d|ddt ˆƒƒVnXdS( NRsRtRjs%s is not a function or methodiiiRm( RuRvRR,RRRRt TypeErrorR^R`RaR(RwtcRjRyRsRr(RzR+(s//sys/lib/python2.7/site-packages/nose/loader.pyR{s$     R|R}(R;R€t__name__R,R&R-(R+RzR0tinsttmethodR{((RzR+s//sys/lib/python2.7/site-packages/nose/loader.pytloadTestsFromGeneratorMethod s    c stjdˆƒg}g}g}| s;ˆjjˆƒrx…tˆƒD]w}tˆ|dƒ}t|ƒr‘ˆjj|ƒr¿|j |ƒq¿qHt |ƒrHˆjj |ƒrH|j |ƒqHqHWt |d„ƒt |t ƒt‡‡fd†||ƒ}ntˆdgƒ} |r/tjj|ƒ}nx‡| D]} tjd| ƒtjd|| tjj| ƒƒˆjjsœ| sœtjj| ƒj|ƒr6|jˆj| ƒƒq6q6Wx-ˆjjjˆ|ƒD]}|j |ƒqÒWˆjt|dˆƒƒS( sãLoad all tests from module and return a suite containing them. If the module has been discovered and is not test-like, the suite will be empty by default, though plugins may add their own tests. sLoad from module %scSs|jS(N(Rƒ(tx((s//sys/lib/python2.7/site-packages/nose/loader.pyRJLscsˆj|dˆƒS(Ntparent(tmakeTest(tt(R~R+(s//sys/lib/python2.7/site-packages/nose/loader.pyRJNst__path__sLoad tests from module path %s?s!path: %s os.path.realpath(%s): %sR|N(RKRLR$t wantModuleR8R,RRt wantClassR:Rt wantFunctionRR tmapRORAtrealpathRttraverseNamespaceRRtextendRHRMtloadTestsFromModuleR&R( R+R~RARGRit test_classest test_funcsR2Rjt module_pathst module_path((R~R+s//sys/lib/python2.7/site-packages/nose/loader.pyR“6s:    c shtjd||ƒˆj}ˆjjj||ƒ}|rD||ƒSt|dˆjƒ}|rD|jrt|j}nˆj ||ƒ\}}t |ƒrêt |ddƒ|j krêt|tƒ rêt||j ƒ}t ||j ƒ}ntjd|||ƒt|tƒr||gƒS|tˆj||ƒgd|ƒƒSn |jrby€|jdkrqt|jƒ}n[ˆjjj|j|jƒzˆjj|j|jƒ}Wdˆjjj|j|jƒXWnZttfk ré‚nAtjƒ} |t| d| d| d d |jƒƒgƒSX|jrFˆj|j|ƒSˆj||jd |ƒSn|jr>|j‰|jrÚt ˆƒ} | dkrÄ|tt!d |jˆfd |jƒƒgƒSˆj|jd | ƒSt"ˆƒrüt#‡‡fd†ƒSt$ˆƒrˆj%ˆƒS|tt&dˆd |jƒƒgƒSn&|tt!d|d |jƒƒgƒSdS(sã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. sload from %s (%s)R t __module__sparent %s obj %s module %sR|NiiiRmRGs>Can't find callable %s in file %s: file is not a python moduleR~cs ˆjˆƒS(N(RH((RAR+(s//sys/lib/python2.7/site-packages/nose/loader.pyRJÂssNo such file %ssUnresolvable test name %s('RKRLR&RRMRZR R tcalltresolveRR,RRƒt isinstanceRRRR‰R~RqRt beforeImportR!timportFromPatht afterImportR^R_R`RattotupleR“RRpRVRRTR\tOSError( R+tnameR~RGtsuitet plug_teststaddrRˆtobjRrtpackage((RAR+s//sys/lib/python2.7/site-packages/nose/loader.pyRZds€                       cCsw|jjj||ƒ}|ra|\}}|ra|j|j|ƒtjj|||ƒgƒSntjj|||ƒS(sSLoad tests from all names, returning a suite containing all tests. (RRMtloadTestsFromNamesR&R)R(R+tnamesR~tplug_resR¢((s//sys/lib/python2.7/site-packages/nose/loader.pyR§Ðs  cCs”g}|jj}x$|j|ƒD]}|j|ƒq"W|sUtt|ƒj|ƒS|jgtt|ƒj|ƒD] }|^qtƒ|j|ƒS(s6Load tests from a unittest.TestCase subclass. (RRMtloadTestsFromTestCaseR:tsuperRR’R&(R+R=R>RMR@((s//sys/lib/python2.7/site-packages/nose/loader.pyRªÞs )cCs•||jd„}gt|t|ƒƒD]!}|jt||ƒ|ƒ^q(}x*|jjj|ƒD]}|j|ƒqeW|j t |d|ƒƒS(s!Load tests from a test class that is *not* a unittest.TestCase subclass. In this case, we can't depend on the class's `__init__` taking method name arguments, so we have to compose a MethodTestCase for each method in the class that looks testlike. cSsMt||dƒ}t|ƒr0t||ƒ}nt|ƒs@tS|j|ƒS(N(R,RRRRR-R.(R/R0R1R2((s//sys/lib/python2.7/site-packages/nose/loader.pyR3÷s   R|( R$R7R8R‰R,RRMtloadTestsFromTestClassR:R&R(R+R0R3R@R>Rj((s//sys/lib/python2.7/site-packages/nose/loader.pyR¬ïs :cCs™y|j||ƒSWn~ttfk r0‚netjƒ}yt|ƒ}Wn tk re‚n d}nXt|d|d|dd|ƒSXdS(NiiiRm(t _makeTestR^R_R`RaRRR(R+R¥RˆRrR¤((s//sys/lib/python2.7/site-packages/nose/loader.pyR‰s   cCslg}yt|ƒ}Wn tk r,‚n d}nXx-|jjj||ƒD]}|j|ƒqRWy|r|j|ƒSWnKttfk rœ‚n2t j ƒ}t |d|d|dd|ƒSXt |ƒr|rt |tjƒ rt||ƒ}nt |tjƒr|St|ƒrƒ|rT|j|jkrTt||jƒ}nt|tjƒrs|j|ƒS|j|ƒSnåt|ƒrï|dkr§|j}nt|tjƒrÆ||jƒSt|ƒrâ|j||ƒSt|ƒSnyt |ƒrQ|r(|j|jkr(t||jƒ}nt|ƒrD|j ||ƒSt!|ƒSnt t"d|d|ƒSdS(sVGiven a test object and its parent, return a test case or test suite. iiiRmsCan't make a test from %sN(#RR^RRRMR‰R:R&R_R`RaRRR›ttypest ModuleTypeRR)tTestCaseRR˜RƒRt issubclassRªR¬Rt __class__RR†RRRRR(R+R¥RˆR£R¤RjRr((s//sys/lib/python2.7/site-packages/nose/loader.pyR­sX   #%            cCsk|}|jdƒ}x'|D]}|t||dƒ}}qW|dkrattd|ƒ}n||fS(s#Resolve name within module REsNo such test %sN(tsplitR,RRRp(R+R¡R~R¥tpartstpartRˆ((s//sys/lib/python2.7/site-packages/nose/loader.pyRšNs  cCs‚t|tƒs"|tƒ}}nVt|ƒdkrK|dtƒ}}n-t|ƒdksct‚|d|d}}||fS(sŽGiven the yield value of a test generator, return a func and args. This is used in the two loadTestsFromGenerator* methods. ii(R›ttupletlentAssertionError(R+RjRyRs((s//sys/lib/python2.7/site-packages/nose/loader.pyRuZsN(RƒR˜t__doc__RRR!R R$R&R*R6RBRDRHR\RR†R-R“RZR§RªR¬R‰R­RšRu(((s//sys/lib/python2.7/site-packages/nose/loader.pyR,s0  )    M   ,.l     ; (=R¹t __future__RtloggingROR`R)R®tinspectRtnose.pyversionRRt nose.caseRRt nose.failureRt nose.configRt nose.importerRR R t nose.selectorR R t nose.utilR RRRRRRRRRt nose.suiteRRRRRt getLoggerRƒRKRAtnormpathR"tabspathR#tjoinRStisdirRVtisfileRTt__all__RR(((s//sys/lib/python2.7/site-packages/nose/loader.pyts6     F      ÿÿ?