ó K9•Qc@sŠdZddlZddlmZmZddlmZmZddddd gZda d „Z e ƒ\Z Z d „Z dd „ZdS( sv Twisted integration ------------------- This module provides a very simple way to integrate your tests with the Twisted_ event loop. You must import this module *before* importing anything from Twisted itself! Example:: from nose.twistedtools import reactor, deferred @deferred() def test_resolve(): return reactor.resolve("www.python.org") Or, more realistically:: @deferred(timeout=5.0) def test_resolve(): d = reactor.resolve("www.python.org") def check_ip(ip): assert ip == "67.15.36.43" d.addCallback(check_ip) return d .. _Twisted: http://twistedmatrix.com/trac/ iÿÿÿÿN(tQueuetEmpty(tmake_decoratort TimeExpiredtthreaded_reactortreactortdeferredRt stop_reactorcs‹yddlm‰Wntk r(dSXtsddlm}ddlm}|d‡fd†ƒatj t ƒtj ƒnˆtfS( s³ Start the Twisted reactor in a separate thread, if not already done. Returns the reactor. The thread will automatically be destroyed when all the tests are done. iÿÿÿÿ(R(t threadable(tThreadttargetcsˆjdtƒS(NtinstallSignalHandlers(truntFalse((R(s5/sys/lib/python2.7/site-packages/nose/twistedtools.pyt8s N(NN( ttwisted.internetRt ImportErrortNonet_twisted_threadttwisted.pythonRt threadingR t setDaemontTruetstart(RR ((Rs5/sys/lib/python2.7/site-packages/nose/twistedtools.pyR*s   cCsZd„}tj|ƒtjƒx-tjƒD]}|jƒr-|jƒq-q-WdadS(sStop the reactor and join the reactor thread until it stops. Call this function in teardown at the module or package level to reset the twisted system after your tests. You *must* do this if you mix tests using these tools and tests using twisted.trial. cSstjƒdS(s0Helper for calling stop from withing the thread.N(Rtstop(((s5/sys/lib/python2.7/site-packages/nose/twistedtools.pyRJsN( RtcallFromThreadtreactor_threadtjointgetDelayedCallstactivetcancelRR(Rtp((s5/sys/lib/python2.7/site-packages/nose/twistedtools.pyRBs    csxtƒ\‰}ˆdkr*tdƒ‚nyˆdkp@ˆdWntk ratdƒ‚nX‡‡fd†}|S(s By wrapping a test function with this decorator, you can return a twisted Deferred and the test will wait for the deferred to be triggered. The whole test function will run inside the Twisted event loop. The optional timeout parameter specifies the maximum duration of the test. The difference with timed() is that timed() will still wait for the test to end, while deferred() will stop the test when its timeout has expired. The latter is more desireable when dealing with network tests, because the result may actually never arrive. If the callback is triggered, the test has passed. If the errback is triggered or the timeout expires, the test has failed. Example:: @deferred(timeout=5.0) def test_resolve(): return reactor.resolve("www.python.org") Attention! If you combine this decorator with other decorators (like "raises"), deferred() must be called *first*! In other words, this is good:: @raises(DNSLookupError) @deferred() def test_error(): return reactor.resolve("xxxjhjhj.biz") and this is bad:: @deferred() @raises(DNSLookupError) def test_error(): return reactor.resolve("xxxjhjhj.biz") s1twisted is not available or could not be importedis+'timeout' argument must be a number or Nonecs+‡‡‡fd†}tˆƒ|ƒ}|S(Ncsºtƒ‰‡fd†‰‡fd†‰‡‡‡‡‡‡fd†}ˆj|ƒyˆjdˆƒ}Wn!tk r‹tdˆƒ‚nX|dk r¶|\}}}|||‚ndS(NcsˆjdƒdS(N(tputR(tvalue(tq(s5/sys/lib/python2.7/site-packages/nose/twistedtools.pytcallbackŠscs/y|jƒWnˆjtjƒƒnXdS(N(traiseExceptionR tsystexc_info(tfailure(R"(s5/sys/lib/python2.7/site-packages/nose/twistedtools.pyterrbackŒscshyGˆˆˆŽ}y|jˆˆƒWntk rEtdƒ‚nXWnˆjtjƒƒnXdS(Ns7you must return a twisted Deferred from your test case!(t addCallbackstAttributeErrort TypeErrorR R%R&(td(targsR#R(tfunctkargsR"(s5/sys/lib/python2.7/site-packages/nose/twistedtools.pytg’s ttimeouts*timeout expired before end of test (%f s.)(RRtgetRRR(R-R/R0terrortexc_typet exc_valuettb(R.RR1(R-R#R(R/R"s5/sys/lib/python2.7/site-packages/nose/twistedtools.pytwrapperˆs    (R(R.R7(RR1(R.s5/sys/lib/python2.7/site-packages/nose/twistedtools.pytdecorate‡s"N(RRRR+(R1RR8((RR1s5/sys/lib/python2.7/site-packages/nose/twistedtools.pyRVs&  %(t__doc__R%RRt nose.toolsRRt__all__RRRRRRR(((s5/sys/lib/python2.7/site-packages/nose/twistedtools.pyts