ó À$TSc@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</opt/alt/python27/lib/python2.7/site-packages/nose/loader.pyR*;s&           cCsŽ|jjrtjj||ƒS||jd„}t|t|ƒƒ}| rht|dƒrhdg}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</opt/alt/python27/lib/python2.7/site-packages/nose/loader.pytwantedls   trunTest( RtgetTestCaseNamesCompatR)RtgetTestCaseNamesR$tfiltertdirthasattrtsortTestMethodsUsingRR(R+t testCaseClassR3tcases((s</opt/alt/python27/lib/python2.7/site-packages/nose/loader.pyR6es   cCs|dkrtS||jkS(N(RR-R((R+tpath((s</opt/alt/python27/lib/python2.7/site-packages/nose/loader.pyt _haveVisited}s cCs#|dk r|jj|ƒndS(N(RR(tadd(R+R=((s</opt/alt/python27/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</opt/alt/python27/lib/python2.7/site-packages/nose/loader.pytÃsN((tlogtdebugRtpluginstbeforeDirectoryR%R tostlistdirRRt testMatcht startswithR#top_joint op_isfileR-R$twantFiletop_isdirt wantDirectoryRR>R@t beforeContexttendswithtloadTestsFromNametTruetloadTestsFromFilet afterContextR&RDtappendtKeyboardInterruptt SystemExitRtsystexc_infoR tafterDirectory( R+R=RIt paths_addedtentriestentrytis_fileR3tis_dirt is_packagetteststtesttp((RER+s</opt/alt/python27/lib/python2.7/site-packages/nose/loader.pyRD‰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(RGRHRRIRXR7RR&topentcloset ValueErrorR[R\R]R^R(R+tfilenameRgRftexc((s</opt/alt/python27/lib/python2.7/site-packages/nose/loader.pyRXÖ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 descriptoriiiRj( tparseGeneratedTesttcallableR,RR[R]R^RR(tgtmRgt test_funcRpRo(t generatorR+(s</opt/alt/python27/lib/python2.7/site-packages/nose/loader.pytgenerateùs   tcontextt can_split(R&R-(R+RwtmoduleRx((RwR+s</opt/alt/python27/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 WWnOtk rÈ‚n<t j ƒ}t|d|d|ddt ˆƒƒVnXdS( NRpRqRgs%s is not a callable or methodiiiRj( RrRsRR,RRRt TypeErrorR[R]R^R(RttcRgRvRpRo(RwR+(s</opt/alt/python27/lib/python2.7/site-packages/nose/loader.pyRxs$     RyRz(R9R}t__name__R,R&R-(R+RwR0tinsttmethodRx((RwR+s</opt/alt/python27/lib/python2.7/site-packages/nose/loader.pytloadTestsFromGeneratorMethods    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|ƒr6tjj| ƒrÊ|jˆj| ƒƒqÊ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</opt/alt/python27/lib/python2.7/site-packages/nose/loader.pyRFJscsˆj|dˆƒS(Ntparent(tmakeTest(tt(R{R+(s</opt/alt/python27/lib/python2.7/site-packages/nose/loader.pyRFLst__path__sLoad tests from module path %s?s!path: %s os.path.realpath(%s): %sRyN(RGRHR$t wantModuleR8R,RRt wantClassRZRt wantFunctionRR tmapRKR=trealpathRttraverseNamespaceRNtisdirtextendRDRItloadTestsFromModuleR&R( R+R{R=RCRft test_classest test_funcsR2Rgt module_pathst module_path((R{R+s</opt/alt/python27/lib/python2.7/site-packages/nose/loader.pyR‘4s<     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 %sRyNiiiRjRCs>Can't find callable %s in file %s: file is not a python moduleR{cs ˆjˆƒS(N(RD((R=R+(s</opt/alt/python27/lib/python2.7/site-packages/nose/loader.pyRFÃssNo such file %ssUnresolvable test name %s('RGRHR&RRIRVR R tcalltresolveRR,RR€t isinstanceRRRR†R{RnRt beforeImportR!timportFromPatht afterImportR[R\R]R^ttotupleR‘RRmRRRRPRXtOSError( R+tnameR{RCtsuitet plug_teststaddrR…tobjRotpackage((R=R+s</opt/alt/python27/lib/python2.7/site-packages/nose/loader.pyRVes€                       cCsw|jjj||ƒ}|ra|\}}|ra|j|j|ƒtjj|||ƒgƒSntjj|||ƒS(sSLoad tests from all names, returning a suite containing all tests. (RRItloadTestsFromNamesR&R)R(R+tnamesR{tplug_resR ((s</opt/alt/python27/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. (RRItloadTestsFromTestCaseRZtsuperRRR&(R+R;R<RItcase((s</opt/alt/python27/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</opt/alt/python27/lib/python2.7/site-packages/nose/loader.pyR3øs   Ry( R$R7R8R†R,RRItloadTestsFromTestClassRZR&R(R+R0R3RªR<Rg((s</opt/alt/python27/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(NiiiRj(t _makeTestR[R\R]R^RRR(R+R£R…RoR¢((s</opt/alt/python27/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. iiiRjsCan't make a test from %sN(#RR[RRRIR†RZR&R\R]R^RRR™ttypest ModuleTypeRR)tTestCaseRR–R€Rt issubclassR¨R«Rt __class__RRƒRRR|RR~(R+R£R…R¡R¢RgRo((s</opt/alt/python27/lib/python2.7/site-packages/nose/loader.pyR¬sX   #%            cCsk|}|jdƒ}x'|D]}|t||dƒ}}qW|dkrattd|ƒ}n||fS(s#Resolve name within module RAsNo such test %sN(tsplitR,RRRm(R+RŸR{R£tpartstpartR…((s</opt/alt/python27/lib/python2.7/site-packages/nose/loader.pyR˜Os  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+RgRvRp((s</opt/alt/python27/lib/python2.7/site-packages/nose/loader.pyRr[sN(R€R–t__doc__RRR!R R$R&R*R6R>R@RDRXR|RƒR-R‘RVR¥R¨R«R†R¬R˜Rr(((s</opt/alt/python27/lib/python2.7/site-packages/nose/loader.pyR,s0  )    M   ,1l     ; (=R¸t __future__RtloggingRKR]R)R­tinspectRtnose.pyversionRRt nose.caseRRt nose.failureRt nose.configRt nose.importerRR R t nose.selectorR R t nose.utilR RRRRRRRRRt nose.suiteRRRRRt getLoggerR€RGR=tnormpathR"tabspathR#tjoinRORRRtisfileRPt__all__RR(((s</opt/alt/python27/lib/python2.7/site-packages/nose/loader.pyts6     F      ÿÿ@