Ñò ªƒùGc@sšdZddklZddkZddkZddkZddkZddklZl Z ddk l Z l Z ddk lZddklZddklZlZlZdd klZlZdd klZlZlZlZlZlZlZl Z l!Z!dd k"l#Z#l$Z$l%Z%ei&e'ƒZ(ei)i*Z+ei)i,Z-ei)i.Z/ei)i0Z1ei)i2Z3d d gZ4d ei5fd„ƒYZ5e5Z6dS(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 isfunctiontismethod(tFunctionTestCasetMethodTestCase(tFailure(tConfig(tImportertadd_patht remove_path(tdefaultSelectort TestAddress( t cmp_linenot getpackagetisclasst isgeneratort ispackaget match_lastt resolve_namettransplant_functtransplant_class(tContextSuiteFactoryt ContextListt LazySuitet TestLoadertdefaultTestLoadercBs¼eZdZdZdZdZdZdZddddd„Z d„Z d„Z d„Z d„Z d„Zed„Zded„Zdd „Zd „Zd „Zdd „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ÿ|djo tƒ}n|djotd|ƒ}n|djo |i}n|djot|ƒ}nt|ƒo||ƒ}n||_||_tt |ƒƒ|_||_ |i ot ||ƒnt d|ƒ|_tii|ƒ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_abspathtselectortaddPathsRRt suiteClasstunittestRt__init__(tselfRRRR ((s//usr/lib/python2.6/site-packages/nose/loader.pyR$7s$           cCsÛ|iiotii||ƒS||id„}t|t|ƒƒ}xI|iD]>}x5|i|ƒD]$}||jo|i |ƒqhqhWqRW| ot |dƒo dg}n|i o|i |i ƒn|S(s_Override to select with selector, unless config.getTestCaseNamesCompat is True cSs1t||dƒ}t|ƒptS|i|ƒS(N(tgetattrRRtFalset wantMethod(tattrtclstseltitem((s//usr/lib/python2.6/site-packages/nose/loader.pytwantedes trunTest( RtgetTestCaseNamesCompatR#RtgetTestCaseNamesR tfiltertdirt __bases__tappendthasattrtsortTestMethodsUsingtsort(R%t testCaseClassR-tcasestbasetcase((s//usr/lib/python2.6/site-packages/nose/loader.pyR0^s     c #sƒtid|ƒˆii}|i|ƒˆiiot|ˆiƒ}nti|ƒ}|i ‡fd†ƒxT|D]L}|i dƒoqxnt t ||ƒƒ‰t ˆƒ}t}|ot}ˆiiˆƒ}nAtˆƒ}|o-|i dƒoqxnˆiiˆƒ}ntˆƒ} |o’|oN|iƒ|idƒoˆiˆdtƒVnˆiˆƒV|iƒqÄ| oˆiˆdtƒVqĈi‡‡fd†ƒVqxqxWg} x$|i|ƒD]} | i| ƒqÞWy| oˆi| ƒVnWn?ttfj o ‚n%ˆitt i!ƒŒgƒVnXˆiiot"t#|ƒn|i$|ƒ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 %scst||ˆiiƒS((RRt testMatch(tatb(R%(s//usr/lib/python2.6/site-packages/nose/loader.pytƒst.t_s.pyt discoveredcs ˆiˆƒS((tloadTestsFromDir((R%t entry_path(s//usr/lib/python2.6/site-packages/nose/loader.pyR?©sN(%tlogtdebugRtpluginstbeforeDirectoryR!RtostlistdirR7t startswithRtop_joint op_isfileR'R twantFiletop_isdirt wantDirectoryRt beforeContexttendswithtloadTestsFromNametTruetloadTestsFromFilet afterContextR"RCR4tKeyboardInterruptt SystemExitRtsystexc_infotmapR tafterDirectory( R%tpathRGt paths_addedtentriestentrytis_fileR-tis_dirt is_packagetteststtest((R%RDs//usr/lib/python2.6/site-packages/nose/loader.pyRCvsd       ! cCsÓtid|ƒy{g}|iii|ƒD] }||q-~}|otd|ƒ}|i|ƒSt|dƒi ƒt d|ƒ‚WnAt t fj o ‚n't iƒ}|it|Œ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 %sN(RERFRRGRUR1RR"topentcloset ValueErrorRWRXRYRZR(R%tfilenamet_[1]ReRdtexc((s//usr/lib/python2.6/site-packages/nose/loader.pyRU»s) cCs||d„}|i|ƒ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 c ss’x‹|ƒD]€}y|d|d}}Wn'tj o|dtƒ}}nXt|ƒpt||ƒ}nt|d|d|ƒVq WdS(Niitargt descriptor(RittupletcallableR&R(tgtmRet test_funcRm((s//usr/lib/python2.6/site-packages/nose/loader.pytgenerateÜs  (R"(R%t generatortmoduleRt((s//usr/lib/python2.6/site-packages/nose/loader.pytloadTestsFromGeneratorÕs cCsF|i}|ƒ}|i}t||ƒ}||d„}|i|ƒ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 c ssÝxÖ|ƒD]Ë}y|d|d}}Wn'tj o|dtƒ}}nXt|ƒpt||ƒ}nt|ƒot|d|d|ƒVq t|ƒot|d|d|ƒVq ttd|ƒVq WdS(NiiRmRnRes%s is not a function or method( RiRoRpR&RRRRt TypeError(RqtcReRsRm((s//usr/lib/python2.6/site-packages/nose/loader.pyRtøs    (tim_classt__name__R&R"(R%RuR*tinsttmethodRt((s//usr/lib/python2.6/site-packages/nose/loader.pytloadTestsFromGeneratorMethodçs   c s‹tidˆƒg}g}g}| pˆiiˆƒoÏxŒtˆƒD]~}tˆ|dƒ}t|ƒo(ˆii|ƒo|i |ƒqÈqJt |ƒo$ˆii |ƒo|i |ƒqJqJW|i d„ƒ|i t ƒt‡‡fd†||ƒ}ntˆdgƒ}x$|D]} |iˆi| ƒƒq%Wx*ˆiiiˆƒD]}|i |ƒq[Wˆit|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 %scSst|i|iƒS((tcmpR{(R=R>((s//usr/lib/python2.6/site-packages/nose/loader.pyR?#scsˆi|dˆƒS(tparent(tmakeTest(tt(R%Rv(s//usr/lib/python2.6/site-packages/nose/loader.pyR?%st__path__tcontextN(RERFR t wantModuleR2R&RRt wantClassR4Rt wantFunctionR7R R[textendRCRRGtloadTestsFromModuleR"R( R%RvRBRdt test_classest test_funcsR,RetpathsR]((R%Rvs//usr/lib/python2.6/site-packages/nose/loader.pyR‰ s2    c s-tid||ƒˆi}ˆiii||ƒ}|o ||ƒSt|dˆiƒ}|oÝ|io |i}nˆi ||ƒ\}}t |ƒoDt |ddƒ|i jo(t||i ƒ}t ||i ƒ}ntid|||ƒt|tƒo||gƒS|tˆi||ƒgd|ƒƒSnë|ioøy‚|idjot|iƒ}n\ˆiii|i|iƒzˆii|i|iƒ}Wdˆiii|i|iƒXWn>ttfj o ‚n$tiƒ} |t| ŒgƒSX|ioˆi|i|ƒSˆi|d|ƒSné|ioÄ|i‰|ioTtˆƒ} | djo$|tt d|iˆfƒgƒSˆi|id | ƒSt!ˆƒot"‡‡fd †ƒSt#ˆƒoˆi$ˆƒS|tt%d ˆƒgƒSn|tt d |ƒ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)Rt __module__sparent %s obj %s module %sR„NRBs>Can't find callable %s in file %s: file is not a python moduleRvcs ˆiˆƒS((RC((R]R%(s//usr/lib/python2.6/site-packages/nose/loader.pyR?ŽssNo such file %ssUnresolvable test name %s(&RERFR"RRGRSR RtcalltresolveRR&RR{Rt isinstanceRRRRvRjRt beforeImportRtimportFromPatht afterImportRWRXRYRZR‰R RiRORRMRUtOSError( R%tnameRvRBtsuitet plug_teststaddrR€tobjRltpackage((R%R]s//usr/lib/python2.6/site-packages/nose/loader.pyRS4st                  cCs{|iii||ƒ}|oF|\}}|o/|i|i|ƒtii|||ƒgƒSntii|||ƒS(sSLoad tests from all names, returning a suite containing all tests. (RRGtloadTestsFromNamesR"R#R(R%tnamesRvtplug_resR–((s//usr/lib/python2.6/site-packages/nose/loader.pyR›šs  !cCsžg}|ii}x$|i|ƒD]}|i|ƒq"W|ptt|ƒi|ƒS|ig}tt|ƒi|ƒD] }||qz~ƒ|i|ƒS(s6Load tests from a unittest.TestCase subclass. (RRGtloadTestsFromTestCaseR4tsuperRRˆR"(R%R8R9RGR;Rk((s//usr/lib/python2.6/site-packages/nose/loader.pyRž¨s -c Cs||id„}g}t|t|ƒƒD]"}||it||ƒ|ƒq,~}x*|iii|ƒD]}|i|ƒqmW|i 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. cSs1t||dƒ}t|ƒptS|i|ƒS(N(R&RRR'R((R)R*R+R,((s//usr/lib/python2.6/site-packages/nose/loader.pyR-Ás R„( R R1R2RR&RRGtloadTestsFromTestClassR4R"R(R%R*R-RkR;R9Re((s//usr/lib/python2.6/site-packages/nose/loader.pyR ¹s>c Csúg}x-|iii||ƒD]}|i|ƒqWy|o|i|ƒSWn/ttfj o ‚ntti ƒŒSXt |t i ƒo|St |ƒob|o)|i|ijot||iƒ}nt|t i ƒo|i|ƒS|i|ƒSnït|ƒog|djo |i}nt|t i ƒo||iƒSt|ƒo|i||ƒSt|ƒSn{t|ƒo\|o)|i|ijot||iƒ}nt|ƒo|i||ƒSt|ƒSnttd|ƒSdS(sVGiven a test object and its parent, return a test case or test suite. sCan't make a test from %sN(RRGRR4R"RWRXRRYRZRR#tTestCaseRRR{Rt issubclassRžR RRt __class__RR~RRRRwRRx(R%R™R€R—Re((s//usr/lib/python2.6/site-packages/nose/loader.pyRÌsF       cCsm|}|idƒ}x'|D]}|t||dƒ}}qW|djottd|ƒ}n||fS(s#Resolve name within module R@sNo such test %sN(tsplitR&RRRi(R%R•RvR™tpartstpartR€((s//usr/lib/python2.6/site-packages/nose/loader.pyRús N(R{Rt__doc__RRRRR R"R$R0RCRURwR~R'R‰RSR›RžR RR(((s//usr/lib/python2.6/site-packages/nose/loader.pyR(s(  &  E   & 'f    .(7R§t __future__RtloggingRIRYR#tinspectRRt nose.caseRRt nose.failureRt nose.configRt nose.importerRRR t nose.selectorR R t nose.utilR R RRRRRRRt nose.suiteRRRt getLoggerR{RER]tnormpathRtabspathRtjoinRLtisdirROtisfileRMt__all__RR(((s//usr/lib/python2.6/site-packages/nose/loader.pyts.    @      ÿß