σ i$VQc@`sΏdZddlmZmZddlZddlmZddlmZm Z ddl m Z ddl m Z mZddlmZmZmZgZee jƒd efd „ƒYƒZdS( sP Things likely to be used by writers of unit tests. Maintainer: Jonathan Lange i(tdivisiontabsolute_importN(t implementer(tdefertutils(tfailure(titrialtutil(tFailTesttSkipTesttSynchronousTestCasetTestCasecB`sςeZdZdd„Zd„ZeZd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z d „Zd „Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zed„ZRS(s= A unit test. The atom of the unit testing universe. This class extends L{SynchronousTestCase} which extends C{unittest.TestCase} from the standard library. The main feature is the ability to return C{Deferred}s from tests and fixture methods and to have the suite wait for those C{Deferred}s to fire. Also provides new assertions such as L{assertFailure}. @ivar timeout: A real number of seconds. If set, the test will raise an error if it takes longer than C{timeout} seconds. If not set, util.DEFAULT_TIMEOUT_DURATION is used. trunTestcC`stt|ƒj|ƒdS(sŸ Construct an asynchronous test case for C{methodName}. @param methodName: The name of a method on C{self}. This method should be a unit test. That is, it should be a short method that calls some of the assert* methods. If C{methodName} is unspecified, L{SynchronousTestCase.runTest} will be used as the test method. This is mostly useful for testing Trial. N(tsuperR t__init__(tselft methodName((s</usr/lib/python2.7/dist-packages/twisted/trial/_asynctest.pyR-s c`s1‡fd†}‡‡fd†}|j||ƒS(sΦ Fail if C{deferred} does not errback with one of C{expectedFailures}. Returns the original Deferred with callbacks added. You will need to return this Deferred from your test case. c`sˆjd|fƒ‚dS(Ns&did not catch an error, instead got %r(tfailureException(tignore(R(s</usr/lib/python2.7/dist-packages/twisted/trial/_asynctest.pyt_cb@sc`s?|jˆŒr|jSdˆt|ƒf}ˆj|ƒ‚dS(Ns Expected: %r Got: %s(tchecktvaluetstrR(Rtoutput(texpectedFailuresR(s</usr/lib/python2.7/dist-packages/twisted/trial/_asynctest.pyt_ebDs (t addCallbacks(RtdeferredRRR((RRs</usr/lib/python2.7/dist-packages/twisted/trial/_asynctest.pyt assertFailure:sc`s±ddlm‰ˆjƒ‰‡‡‡‡‡fd†}tj|tjdtƒƒ}tˆˆƒ}t j tj ˆj ƒ|ƒ}ˆj ˆ||ƒ‰|j‡fd†ƒ|S(Ni(treactorc`s·tjdˆˆˆfƒ}tj|ƒ}y|j|ƒWnttjk r²ˆjƒtˆ_ˆj ƒ}|dk rŸ|j |ƒrŸˆj ˆ||ƒq³ˆj ˆ|ƒnXdS(Ns %r (%s) still running at %s secs(Rt TimeoutErrorRtFailureterrbacktAlreadyCalledErrortcrashtTruet _timedOuttgetTodotNonetexpectedtaddExpectedFailuretaddError(tdtetfttodo(RRtresultRttimeout(s</usr/lib/python2.7/dist-packages/twisted/trial/_asynctest.pyt onTimeoutRs    tcategoryc`sˆjƒrˆjƒp|S(N(tactivetcancel(tx(tcall(s</usr/lib/python2.7/dist-packages/twisted/trial/_asynctest.pytls(ttwisted.internetRt getTimeoutRtsuppressWarningsRtsuppresstDeprecationWarningtgetattrRt maybeDeferredtrunWithWarningsSuppressedt _getSuppresst callLatertaddBoth(RRR.R0tmethodR*((R5RRR.RR/s</usr/lib/python2.7/dist-packages/twisted/trial/_asynctest.pyt_runOs cO`s|j||ŽS(N(trun(Rtargstkwargs((s</usr/lib/python2.7/dist-packages/twisted/trial/_asynctest.pyt__call__pscC`s>|jd|ƒ}|j|j|jd|fd|fƒ|S(NtsetUpt callbackArgst errbackArgs(RCRtdeferTestMethodt _ebDeferSetUp(RtignoredR.R*((s</usr/lib/python2.7/dist-packages/twisted/trial/_asynctest.pyt deferSetUpts   cC`sp|jtƒr4|j||j|j|jƒƒn,|j||ƒ|jtƒr`|jƒn|j d|ƒS(N( RR taddSkipt_getSkipReasonRHRR)tKeyboardInterrupttstoptdeferRunCleanupsR&(RRR.((s</usr/lib/python2.7/dist-packages/twisted/trial/_asynctest.pyRL|s % cC`sg|j|j|ƒ}|j|j|jd|fd|fƒ|j|j|ƒ|j|j|ƒ|S(NRIRJ(RCt_testMethodNameRt_cbDeferTestMethodt_ebDeferTestMethodRARSt deferTearDown(RRMR.R*((s</usr/lib/python2.7/dist-packages/twisted/trial/_asynctest.pyRK†s  cC`s8|jƒdk r+|j||jƒƒn t|_|S(N(R%R&taddUnexpectedSuccessR#t_passed(RRMR.((s</usr/lib/python2.7/dist-packages/twisted/trial/_asynctest.pyRUs cC`sβ|jƒ}|dk r=|j|ƒr=|j|||ƒn‘|j|jtƒre|j||ƒny|jtƒr‘|j ||ƒ|j ƒnM|jt ƒrΞ|j ||j t||jƒ|jƒƒn|j ||ƒdS(N(R%R&R'R(RRRt addFailureRQR)RRR RORPR<RTR(RR,R.R-((s</usr/lib/python2.7/dist-packages/twisted/trial/_asynctest.pyRV˜s  %cC`s)|jd|ƒ}|j|j|ƒ|S(NttearDown(RCt addErrbackt_ebDeferTearDown(RRMR.R*((s</usr/lib/python2.7/dist-packages/twisted/trial/_asynctest.pyRW©scC`s9|j||ƒ|jtƒr,|jƒnt|_dS(N(R)RRQRRtFalseRY(RRR.((s</usr/lib/python2.7/dist-packages/twisted/trial/_asynctest.pyR]―s cC`s#|jƒ}|j|j|ƒ|S(sd Run any scheduled cleanups and report errors (if any to the result object. (t _runCleanupst addCallbackt_cbDeferRunCleanups(RRMR.R*((s</usr/lib/python2.7/dist-packages/twisted/trial/_asynctest.pyRSΆs cC`sbx[|D]S\}}|tjkr|j||ƒ|jtƒrN|jƒnt|_qqWdS(N(RtFAILURER)RRQRRR^RY(RtcleanupResultsR.tflagR((s</usr/lib/python2.7/dist-packages/twisted/trial/_asynctest.pyRaΐs  cC`s»y.tj||ƒjƒ}|s-t|_nWn&|j|tjƒƒt|_nXx0|jj ƒD]}|j||ƒt|_qgW|j ƒ|j ƒ|jr·|j |ƒndS(N( Rt_JanitortpostCaseCleanupR^RYR)RRt _observert getErrorstflushLoggedErrorst_removeObservert addSuccess(RR.tcleanterror((s</usr/lib/python2.7/dist-packages/twisted/trial/_asynctest.pyt_cleanUpΙs     cC`s>ytj||ƒjƒWn|j|tjƒƒnXdS(N(RRetpostClassCleanupR)RR(RR.((s</usr/lib/python2.7/dist-packages/twisted/trial/_asynctest.pyt _classCleanUpΪsc`s‡‡fd†}|S(s• Create a method which wraps the reactor method C{name}. The new method issues a deprecation warning and calls the original. c`s7tjdˆˆfdddtƒˆjˆ||ŽS(Ns{reactor.%s cannot be used inside unit tests. In the future, using %s will fail the test and may crash or hang the test run.t stackleveliR1(twarningstwarnR;t_reactorMethods(tatkw(tnameR(s</usr/lib/python2.7/dist-packages/twisted/trial/_asynctest.pyt_ζs   ((RRwRx((RwRs</usr/lib/python2.7/dist-packages/twisted/trial/_asynctest.pyt_makeReactorMethodαscC`sVi|_xFdddgD]5}t||ƒ|j| s