ó
[³XMc           @   sL   d  Z  d d l m Z d d l m Z m Z m Z d e f d „  ƒ  YZ d S(   sw  
Tests for L{twisted.internet.defer.inlineCallbacks}.

These tests are defined in a non-C{test_*} module because they are
syntactically invalid on python < 2.5.  test_inlinecb will conditionally import
these tests on python 2.5 and greater.

Some tests for inlineCallbacks are defined in L{twisted.test.test_defgen} as
well: see U{http://twistedmatrix.com/trac/ticket/4182}.
iÿÿÿÿ(   t   TestCase(   t   Deferredt   returnValuet   inlineCallbackst   NonLocalExitTestsc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s¢  
    It's possible for L{returnValue} to be (accidentally) invoked at a stack
    level below the L{inlineCallbacks}-decorated function which it is exiting.
    If this happens, L{returnValue} should report useful errors.

    If L{returnValue} is invoked from a function not decorated by
    L{inlineCallbacks}, it will emit a warning if it causes an
    L{inlineCallbacks} function further up the stack to exit.
    c         C   s   t  d ƒ d S(   s‹   
        This method mistakenly invokes L{returnValue}, despite the fact that it
        is not decorated with L{inlineCallbacks}.
        i   N(   R   (   t   self(    (    sH   /usr/lib/python2.7/dist-packages/twisted/internet/test/inlinecb_tests.pyt   mistakenMethod   s    c         C   su   |  j  | d g ƒ |  j d |  j g ƒ } |  j  t | ƒ d ƒ |  j | d d t ƒ |  j | d d d ƒ d S(   sc  
        Flush the current warnings and assert that we have been told that
        C{mistakenMethod} was invoked, and that the result from the Deferred
        that was fired (appended to the given list) is C{mistakenMethod}'s
        result.  The warning should indicate that an inlineCallbacks function
        called 'inline' was made to exit.
        i   t   offendingFunctionsi    t   categoryt   messagesŠ   returnValue() in 'mistakenMethod' causing 'inline' to exit: returnValue should only be invoked by functions decorated with inlineCallbacksN(   t   assertEqualt   flushWarningsR   t   lent   assertEqualst   DeprecationWarning(   R   t
   resultListt   warnings(    (    sH   /usr/lib/python2.7/dist-packages/twisted/internet/test/inlinecb_tests.pyt   assertMistakenMethodWarning&   s    c            sE   t  ‡  f d †  ƒ } | ƒ  } g  } | j | j ƒ ˆ  j | ƒ d S(   s–   
        L{returnValue} will emit a non-local exit warning in the simplest case,
        where the offending function is invoked immediately.
        c           3   s   ˆ  j  ƒ  t d ƒ d Vd  S(   Ni   i    (   R   R   (    (   R   (    sH   /usr/lib/python2.7/dist-packages/twisted/internet/test/inlinecb_tests.pyt   inline>   s    

N(   R   t   addCallbackt   appendR   (   R   R   t   dt   results(    (   R   sH   /usr/lib/python2.7/dist-packages/twisted/internet/test/inlinecb_tests.pyt   test_returnValueNonLocalWarning9   s
    	c            sn   t  ƒ  ‰ t ‡  ‡ f d †  ƒ } | ƒ  } g  } | j | j ƒ ˆ  j | g  ƒ ˆ j d ƒ ˆ  j | ƒ d S(   sÛ   
        L{returnValue} will emit a non-local warning in the case where the
        L{inlineCallbacks}-decorated function has already yielded a Deferred
        and therefore moved its generator function along.
        c           3   s   ˆ Vˆ  j  ƒ  t d ƒ d  S(   Ni   (   R   R   (    (   R   t   cause(    sH   /usr/lib/python2.7/dist-packages/twisted/internet/test/inlinecb_tests.pyR   P   s    
i   N(   R   R   R   R   R   t   callbackR   (   R   R   t   effectR   (    (   R   R   sH   /usr/lib/python2.7/dist-packages/twisted/internet/test/inlinecb_tests.pyt    test_returnValueNonLocalDeferredI   s    		(   t   __name__t
   __module__t   __doc__R   R   R   R   (    (    (    sH   /usr/lib/python2.7/dist-packages/twisted/internet/test/inlinecb_tests.pyR      s
   				N(   R   t   twisted.trial.unittestR    t   twisted.internet.deferR   R   R   R   (    (    (    sH   /usr/lib/python2.7/dist-packages/twisted/internet/test/inlinecb_tests.pyt   <module>   s   