Plan 9 from Bell Labs’s /usr/web/sources/contrib/jas/root/sys/lib/python2.7/site-packages/nose/twistedtools.pyc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�9�c@s�dZddlZddlmZmZddlmZmZddddd	gZda	d
�Z
e
�\ZZ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_decoratortTimeExpiredtthreaded_reactortreactortdeferredRtstop_reactorcs�yddlm�Wntk
r(dSXts�ddlm}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.pyt<lambda>8s	N(NN(ttwisted.internetRtImportErrortNonet_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.pyt<module>s			

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.