U é üe…Wã@sDdZddlZddlZddlZddlmZddlmZddlm Z ddl m Z m Z m Z ddlZejdkr¨ejdd…d kr˜ddlZe d ¡dd lmZnGd d „d eƒZe e¡ZeƒZdd„ZGdd„deƒZGdd„dejƒZGdd„deƒZGdd„deƒZ Gdd„deƒZ!Gdd„dejƒZ"Gdd„dƒZ#Gdd„dƒZ$dS) zâ Test Suites ----------- Provides a LazySuite, which is a suite whose test list is a generator function, and ContextSuite,which can run fixtures (setup/teardown functions or methods) for the context that contains its tests. éN)ÚTest)ÚConfig)ÚResultProxyFactory)ÚisclassÚ resolve_nameÚtry_runÚclié)r éÚ IronPython)ÚStringExceptionc@s eZdZdS)r N)Ú__name__Ú __module__Ú __qualname__©rrú8/opt/hc_python/lib/python3.8/site-packages/nose/suite.pyr sr cCsd|j|jfS)Nz%s.%s)rr )ÚclsrrrÚ _strclass%src@seZdZdZdS)ÚMixedContextErrorzQError raised when a context suite sees tests from more than one context. N)r rrÚ__doc__rrrrr(srcsteZdZdZd‡fdd„ Zdd„Zdd„Zd d „ZeZd d „Z d d„Z dd„Z dd„Z dd„Z ee e ddƒZ‡ZS)Ú LazySuitez:A suite that may use a generator as its list of tests rcstt|ƒ ¡| |¡dS)zFInitialize the suite. tests may be an iterable or a generator N)ÚsuperrÚ__init__Ú _set_tests)ÚselfÚtests©Ú __class__rrr2szLazySuite.__init__cCs t|jƒS©N)ÚiterÚ_tests©rrrrÚ__iter__8szLazySuite.__iter__cCsdt|jƒt|ƒfS)Nz<%s tests=generator (%s)>)rrÚidr!rrrÚ__repr__;sÿzLazySuite.__repr__cCs t |¡Sr©ÚobjectÚ__hash__r!rrrr'?szLazySuite.__hash__cCs|j |¡dSr)Ú _precacheÚappend©rÚtestrrrÚaddTestDszLazySuite.addTestcCs"|jD]}|jrq||ƒq|Sr)r Ú shouldStop)rÚresultr+rrrÚrunHs   z LazySuite.runcCsjt dt|ƒ¡|jrdS|jdkr(dSz(t|jƒ}|dk rN|j |¡WdSWntk rdYnXdS)Nz tests in %s?TF)ÚlogÚdebugr#r(Útest_generatorÚnextr)Ú StopIterationr*rrrÚ__bool__Os    zLazySuite.__bool__ccsDt d|j¡|jD] }|Vq|jdkr.dS|jD] }|Vq4dS)Nzprecache is %s)r0r1r(r2r*rrrÚ _get_tests^s   zLazySuite._get_testscCsXg|_t|tjƒ}t|tjƒr,|s,|ƒ|_n(|rD| |g¡d|_n| |¡d|_dSr)r(Ú isinstanceÚunittestÚ TestSuiteÚ collectionsÚCallabler2ZaddTests)rrZis_suiterrrrgs    zLazySuite._set_testsNzbAccess the tests in this suite. Access is through a generator, so iteration may not be repeatable.)r)r rrrrr"r$r'Ú__str__r,r/r5r6rÚpropertyr Ú __classcell__rrrrr/s ÿrcsØeZdZdZejjZdZdZdZ dZ dZ dZ dZ dZd-‡fd d „ Zdd„ZeZdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd.dd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„Ze ee!j"d d,ƒZ#‡Z$S)/Ú ContextSuitea4A suite with context. A ContextSuite executes fixtures (setup and teardown functions or methods) for the context containing its tests. The context may be explicitly passed. If it is not, a context (or nested set of contexts) will be constructed by examining the tests in the suite. F)Z setup_classZ setup_allZ setupClassZsetupAllZ setUpClassZsetUpAll)Zteardown_classZ teardown_allZ teardownClassZ teardownAllZ tearDownClassZ tearDownAll)Z setup_moduleZ setupModuleZ setUpModuleÚsetupÚsetUp)Zteardown_moduleZteardownModuleZtearDownModuleÚteardownÚtearDown)Z setup_packageZ setupPackageZ setUpPackage)Zteardown_packageZteardownPackageZtearDownPackagerNTcs`t d||t|ƒ¡||_||_|dkr.tƒ}||_||_d|_||_ d|_ t t |ƒ  |¡dS)NzContext suite for %s (%s) (%s)F)r0r1r#ÚcontextÚfactoryrÚconfigÚ resultProxyÚhas_runÚ can_splitÚ error_contextrr?r)rrrDrErFrGrIrrrr“szContextSuite.__init__cCsdt|jƒt|jd|jƒfS)Nz<%s context=%s>r )rrÚgetattrrDr!rrrr$¡sþzContextSuite.__repr__cCs$|jrdt|ƒ|jfSt|ƒSdS)Nz%s:%s)rJÚreprr!rrrr#§szContextSuite.idcCs t |¡Srr%r!rrrr'­szContextSuite.__hash__cOs |j||ŽSr©r/©rÚargÚkwrrrÚ__call__±szContextSuite.__call__cCst ¡S)z.Hook for replacing error tuple output )ÚsysÚexc_infor!rrrrS´szContextSuite.exc_infocCs>| ¡}tjdkr:t|dtƒr:t|dƒ|d|df}|S)z:Bottleneck to fix up IronPython string exceptions rrér )rSrRÚplatformr7r Ústr)rÚerrrÚ _exc_info¹s  zContextSuite._exc_infocCsþt dt|ƒ||j¡|jr0| ||¡|}}n ||}}z | ¡Wn8tk r\‚Yn$d|_| ||  ¡¡YdSXz,|jD] }|j r t d¡qª||ƒqˆW5d|_ z |  ¡Wn6tk rÖ‚Yn"d|_| ||  ¡¡YnXXdS)z5Run tests in suite inside of suite fixtures. z#suite %s (%s) run called, tests: %sr@NTrBZstopping) r0r1r#r rGrAÚKeyboardInterruptrJZaddErrorrXrHrCr-)rr.Úorigr+rrrr/Æs4     zContextSuite.runcCs^|j}|dkrdS|j||dr$dS|j}|rZ|j |g¡}|D]}|j||dr@dSq@dS)NF)Ú ctx_callbackT)rDÚimplementsAnyFixturerEÚget)rr[rDrEÚ ancestorsÚancestorrrrÚ hasFixturesìsÿzContextSuite.hasFixturescCsrt|ƒr|j|j}n&|j|j}t|dƒr<||j|j7}d}|D]}t||ƒrDd}q\qD|dkrh|S|||ƒS)NÚ__path__FT)rÚ classSetupÚ classTeardownÚ moduleSetupÚmoduleTeardownÚhasattrÚ packageSetupÚpackageTeardown)rrDr[ÚnamesZfixtÚmrrrr\üs   z!ContextSuite.implementsAnyFixturecCsèt dt|ƒ|j¡|s,t dt|ƒ¡dS|jrFt dt|ƒ¡dS|j}|dkrXdS|j}|rÊ|j |g¡dd…}|r´| ¡}t d|¡||jkrœqxt d|¡|  |¡qx||jkrÔ|  |¡n |  |¡d|_t d¡dS)Nz suite %s setUp called, tests: %szsuite %s has no testszsuite %s already set upzancestor %s may need setupzancestor %s does need setupTzcompleted suite setup) r0r1r#r Ú was_setuprDrEr]ÚpopÚ setupContext)rrDrEr^r_rrrrA s2       zContextSuite.setUpcCsv|jj |¡t d||¡|jr>||jjkr2dS||jj|<t|ƒrN|j}n|j }t |dƒrh|j |}t ||ƒdS)Nz%s setup context %sra) rFÚpluginsZ startContextr0r1rErkrrbrdrfrgr©rrDrirrrrm-s    zContextSuite.setupContextcCs|jdkrdSd|jS)Nz test suiteztest suite for %s©rDr!rrrÚshortDescription>s zContextSuite.shortDescriptioncCsðt d¡|jr|jr0t d|j|jf¡dSd|_|j}|dkrRt d¡dS|j}|râ|j |g¡|g}|D]j}t d|¡||jkrœt d|¡qt||jkr´t d|¡qt|j|}t d||¡||krt| |¡qtn | |¡dS) Nzcontext teardownz6No reason to teardown (was_setup? %s was_torndown? %s)TzNo context to tear downzancestor %s may need teardownzancestor %s was not setupzancestor %s already torn downz%s setup ancestor %s)r0r1rkÚ was_torndownrDrEr]ÚteardownContext)rrDrEr^r_r@rrrrCCs:   ÿÿ       zContextSuite.tearDowncCsvt d||¡|jr0||jjkr$dS||jj|<t|ƒr@|j}n|j}t|dƒrZ|j|}t ||ƒ|j j   |¡dS)Nz%s teardown context %sra) r0r1rErrrrcrerfrhrrFrnZ stopContextrorrrrsds     zContextSuite.teardownContextccsD| ¡D]6}t|tƒs"t|tjƒr*|Vqt||j|jdVqdS)N©rFrG)r6r7rr8r9rFrGr*rrrÚ_get_wrapped_teststs þzContextSuite._get_wrapped_testszOAccess the tests in this suite. Tests are returned inside of a context wrapper.)rNNNNT)N)%r rrrr8ZTestCaseZfailureExceptionrkrrrbrcrdrergrhrr$r<r#r'rQrSrXr/r`r\rArmrqrCrsrur=rrr r>rrrrr?zsD ÿ &  ! ÿr?c@sTeZdZdZeZddefdd„Zdd„Zdd„Z d d „Z d d „Z d d„Z dd„Z dS)ÚContextSuiteFactoryaCFactory for ContextSuites. Called with a collection of tests, the factory decides on a hierarchy of contexts by introspecting the collection or the tests themselves to find the objects containing the test objects. It always returns one suite, but that suite may consist of a hierarchy of nested suites. NcCsV|dkrtƒ}||_|dk r"||_|tkr4t|d}||_i|_i|_i|_i|_ dS)N)rF) rrFÚ suiteClassÚ_defrrGÚsuitesrDrkrr)rrFrwrGrrrrŠs zContextSuiteFactory.__init__cKsŠt d|¡| dt|ddƒ¡}t d||¡|dkrz| |¡}z| |¡}Wn*tk rx|j| |¡df|ŽYSX|j||f|ŽS)aÄReturn ``ContextSuite`` for tests. ``tests`` may either be a callable (in which case the resulting ContextSuite will have no parent context and be evaluated lazily) or an iterable. In that case the tests will wrapped in nose.case.Test, be examined and the context of each found and a suite of suites returned, organized into a stack with the outermost suites belonging to the outermost contexts. zCreate suite for %srDNztests %s context %s) r0r1rlrKÚ wrapTestsÚ findContextrÚ makeSuiteÚ mixedSuites)rrrPrDrrrrQšs  zContextSuiteFactory.__call__ccs²t d|¡|dkrdSt|dƒr,|jj}nt|dƒr>|jj}t|dƒrV|j d¡}n,t|dƒrv|j d¡dd…}n td |ƒ‚|r®t d ||¡t d  |¡ƒV|  ¡q‚dS) zØReturn the ancestry of the context (that is, all of the packages and modules containing the context), in order of descent with the outermost ancestor last. This method is a generator. zget ancestry %sNZim_classÚ__self__rÚ.r éÿÿÿÿz%s has no ancestors?z %s ancestors %s) r0r1rfr~rrÚsplitr Ú TypeErrorrÚjoinrl)rrDr^rrrÚancestry®s        zContextSuiteFactory.ancestrycCsjt|tjƒst|tjƒrdSd}|D]@}t|ddƒ}|dkr>q$|dkrL|}q$||kr$td||fƒ‚q$|S)NrDz5Tests with different contexts in same suite! %s != %s)r7r:r;r8r9rKr)rrrDr+Úctxrrrr{És  ÿÿzContextSuiteFactory.findContextcKs®|j|f||j||jdœ|—Ž}|dk rª|j |g¡ |¡|j |g¡ |¡t d|t |ddƒ¡|  |¡D]8}|j |g¡ |¡|j| |¡t d||j ¡qp|S)N)rDrFrErGzsuite %s has context %sr zsuite %s has ancestor %s) rwrFrGryÚ setdefaultr)rDr0r1rKr„r )rrrDrPÚsuiter_rrrr|Ús*ÿþþ ÿzContextSuiteFactory.makeSuitecCs|sgS| d¡}|s|gS|}|dd…}t|ddƒ}|dk r|gdd„| |¡Dƒ}|D]¢}|g}g} |D]t} d} t| ddƒ} | dkrš|  | ¡qr| |kr®| | ¡qr| | ¡D]} | |kr¸| | ¡d} qØq¸| sr|  | ¡qr|rø| ||¡}| | ¡}q`|g|S)acThe complex case where there are tests that don't all share the same context. Groups tests into suites with common ancestors, according to the following (essentially tail-recursive) procedure: Starting with the context of the first test, if it is not None, look for tests in the remaining tests that share that ancestor. If any are found, group into a suite with that ancestor as the context, and replace the current suite with that suite. Continue this process for each ancestor of the first test, until all ancestors have been processed. At this point if any tests remain, recurse with those tests as the input, returning a list of the common suite (which may be the suite or test we started with, if no common tests were found) plus the results of recursion. rNrDcSsg|]}|‘qSrr)Ú.0ÚarrrÚ sz3ContextSuiteFactory.mixedSuites..FT)rlrKr„r)r|r})rrÚheadr‡ÚtailrDr^r_ÚcommonZremainr+Z found_commonZtest_ctxZ test_ancestorrrrr}ésB           zContextSuiteFactory.mixedSuitescCs¬t d|¡t|tjƒs$t|tjƒr2t d¡|Sg}|D]l}t d|¡t|tƒs`t|tjƒrl| |¡q:t|t ƒrŽ| |j ||j d¡q:| t||j |j d¡q:|S)Nzwrap %sz I won't wrapz wrapping %srprt)r0r1r7r:r;r8r9rr)Ú ContextListr|rDrFrG)rrÚwrappedr+rrrrzs     ÿzContextSuiteFactory.wrapTests)r rrrr?rwrxrrQr„r{r|r}rzrrrrrv‚s2rvc@s"eZdZdZddd„Zdd„ZdS)rŽzÄNot quite a suite -- a group of tests in a context. This is used to hint the ContextSuiteFactory about what context the tests belong to, in cases where it may be ambiguous or missing. NcCs||_||_dSr)rrD)rrrDrrrr3szContextList.__init__cCs t|jƒSr)rrr!rrrr"7szContextList.__iter__)N)r rrrrr"rrrrrŽ.s rŽcs8eZdZdZ‡fdd„Zdd„Zdd„Zdd „Z‡ZS) ÚFinalizingSuiteWrapperzÐWraps suite and calls final function after suite has executed. Used to call final functions in cases (like running in the standard test runner) where test running is not under nose's control. cstt|ƒ ¡||_||_dSr)rrrr‡Úfinalize)rr‡r‘rrrrAszFinalizingSuiteWrapper.__init__cOs |j||ŽSrrMrNrrrrQFszFinalizingSuiteWrapper.__call__cCs t|jƒSr)rr‡r!rrrr"JszFinalizingSuiteWrapper.__iter__c Os$z|j||ŽW¢S|j||ŽXdSr)r‘r‡rNrrrr/MszFinalizingSuiteWrapper.run) r rrrrrQr"r/r>rrrrr;s  rc@seZdZdd„ZdS)ÚTestDircOs tdƒ‚dS)Nz…TestDir is not usable with nose 0.10. The class is present in nose.suite for backwards compatibility purposes but it may not be used.©ÚNotImplementedError©rOrPrrrrVsÿzTestDir.__init__N©r rrrrrrrr’Usr’c@seZdZdd„ZdS)Ú TestModulecOs tdƒ‚dS)NzˆTestModule is not usable with nose 0.10. The class is present in nose.suite for backwards compatibility purposes but it may not be used.r“r•rrrr^sÿzTestModule.__init__Nr–rrrrr—]sr—)%rÚloggingrRr8Z nose.caserZ nose.configrZ nose.proxyrZ nose.utilrrrr:rUÚ version_infoZclrZ AddReferenceZIronPython.Runtime.Exceptionsr Ú ExceptionÚ getLoggerr r0r&rxrrr9rr?rvrŽrr’r—rrrrÚs8       K -