ó
[³XMc           @   sø   d  d l  m Z d  d l m Z d  d l m Z m Z m Z m Z m	 Z	 e j
 Z
 d  d l m Z d e j f d „  ƒ  YZ d e f d „  ƒ  YZ d	 e j f d
 „  ƒ  YZ d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   set(   t   unittest(   t
   interfacest   taskt   reactort   defert   error(   t   failuret   TestableLoopingCallc           B   s   e  Z d  „  Z RS(   c         O   s&   t  t |  ƒ j | | Ž  | |  _ d  S(   N(   t   superR   t   __init__t   clock(   t   selfR   t   at   kw(    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR
      s    (   t   __name__t
   __module__R
   (    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR      s   t   TestExceptionc           B   s   e  Z RS(    (   R   R   (    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR      s   t   ClockTestCasec           B   s•   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s<   
    Test the non-wallclock based clock implementation.
    c         C   s&   t  j ƒ  } |  j | j ƒ  d ƒ d S(   sV   
        Test that the L{seconds} method of the fake clock returns fake time.
        i    N(   R   t   Clockt   assertEqualst   seconds(   R   t   c(    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   testSeconds    s    c         C   sp   t  j ƒ  } | j d d „  d d d ƒ} |  j t j j | ƒ ƒ |  j | j ƒ  d ƒ |  j | j	 ƒ  ƒ d S(   s{   
        Test that calls can be scheduled for later with the fake clock and
        hands back an L{IDelayedCall}.
        i   c         S   s   d  S(   N(   t   None(   R   t   b(    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   <lambda>.   s    R   i   N(
   R   R   t	   callLatert
   failUnlessR   t   IDelayedCallt
   providedByR   t   getTimet   active(   R   R   t   call(    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   testCallLater(   s
    c         C   sK   t  j ƒ  } | j d d „  d d d ƒ} | j ƒ  |  j | j ƒ  ƒ d S(   s3   
        Test that calls can be cancelled.
        i   c         S   s   d  S(   N(   R   (   R   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR   9   s    R   i   N(   R   R   R   t   cancelt   failIfR    (   R   R   R!   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   testCallLaterCancelled4   s    
c         C   s_   t  j ƒ  } | j d d „  d d d ƒ} | j d d „  d d d ƒ} |  j | | k ƒ d	 S(
   s[   
        Test that the DelayedCall returned is not one previously
        created.
        i
   c         S   s   d  S(   N(   R   (   R   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR   D   s    i   R   i   c         S   s   d  S(   N(   R   (   R   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR   E   s    i   i   N(   R   R   R   R$   (   R   R   t   call1t   call2(    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   test_callLaterOrdering>   s    c            s   g  ‰  t  j ƒ  } | j d ‡  f d †  ƒ } | j d ƒ |  j ˆ  g  ƒ | j d ƒ |  j ˆ  d g ƒ |  j | j ƒ  ƒ d S(   sE   
        Test that advancing the clock will fire some calls.
        i   c              s   ˆ  j  d  ƒ S(   N(   t   appendR   (    (   t   events(    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR   O   s    i   N(   R   R   R   t   advanceR   R   R$   R    (   R   R   R!   (    (   R*   s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   testAdvanceI   s    c            sA   t  j ƒ  } ‡  ‡ f d †  } | j d | ƒ ‰ | j d ƒ d S(   s  
        Test attemping to cancel the call in a callback.

        AlreadyCalled should be raised, not for example a ValueError from
        removing the call from Clock.calls. This requires call.called to be
        set before the callback is called.
        c              s   ˆ  j  t j ˆ j ƒ d  S(   N(   t   assertRaisesR   t   AlreadyCalledR#   (    (   R   R!   (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   cb`   s    i   N(   R   R   R   R+   (   R   R   R/   (    (   R   R!   s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   testAdvanceCancelW   s    c            sš   g  ‰  t  j ƒ  } | j d ‡  f d †  d d d ƒ} | j d ƒ |  j | j ƒ  d ƒ | j d ƒ |  j ˆ  g  ƒ | j d ƒ |  j ˆ  d g ƒ d S(	   s1   
        Test that calls can be delayed.
        i   c            s   ˆ  j  |  | f ƒ S(   N(   R)   (   R   R   (   R*   (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR   l   s    R   i   g      ø?g      ð?N(   i   i   (   R   R   R   t   delayR   R   R+   (   R   R   R!   (    (   R*   s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   testCallLaterDelayedf   s    $c            s§   g  ‰  t  j ƒ  } | j d ‡  f d †  d d d ƒ} | j d ƒ | j d ƒ |  j | j ƒ  d ƒ | j d ƒ |  j ˆ  g  ƒ | j d ƒ |  j ˆ  d g ƒ d S(	   sL   
        Test that calls can have their time reset to a later time.
        i   c            s   ˆ  j  |  | f ƒ S(   N(   R)   (   R   R   (   R*   (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR   {   s    i   R   i   i   N(   i   i   (   R   R   R   R+   t   resetR   R   (   R   R   R!   (    (   R*   s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   testCallLaterResetLateru   s    $c            s}   g  ‰  t  j ƒ  } | j d ‡  f d †  d d d ƒ} | j d ƒ |  j | j ƒ  d ƒ | j d ƒ |  j ˆ  d g ƒ d S(	   sO   
        Test that calls can have their time reset to an earlier time.
        i   c            s   ˆ  j  |  | f ƒ S(   N(   R)   (   R   R   (   R*   (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR   ‹   s    i   R   i   i   N(   i   i   (   R   R   R   R3   R   R   R+   (   R   R   R!   (    (   R*   s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   testCallLaterResetSooner…   s    $c         C   sh   t  j ƒ  } | j d d „  ƒ } | j d d „  ƒ } | j ƒ  } |  j t | | g ƒ t | ƒ ƒ d S(   sB   
        Test that we can get a list of all delayed calls
        i   c         S   s   d  S(   N(   R   (   t   x(    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR   —   s    i   c         S   s   d  S(   N(   R   (   R6   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR   ˜   s    N(   R   R   R   t   getDelayedCallsR   R    (   R   R   R!   R'   t   calls(    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   test_getDelayedCalls’   s
    c         C   s&   t  j ƒ  } |  j | j ƒ  g  ƒ d S(   sk   
        Test that we get an empty list from getDelayedCalls on a newly
        constructed Clock.
        N(   R   R   R   R7   (   R   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   test_getDelayedCallsEmptyŸ   s    c         C   s,   t  j ƒ  } |  j t j j | ƒ d ƒ d  S(   Ns#   Clock does not provide IReactorTime(   R   R   R   R   t   IReactorTimeR   (   R   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   test_providesIReactorTime¨   s    c            s   g  ‰ d
 d g } t  j ƒ  ‰  ‡  ‡ f d †  } ˆ  j d | d ƒ } | j d ƒ ˆ  j d | d ƒ ˆ  j d g d ƒ |  j ˆ | ƒ d	 S(   s4  
        The order of calls scheduled by L{task.Clock.callLater} is honored when
        adding a new call via calling L{task.Clock.callLater} again.

        For example, if L{task.Clock.callLater} is invoked with a callable "A"
        and a time t0, and then the L{IDelayedCall} which results from that is
        C{reset} to a later time t2 which is greater than t0, and I{then}
        L{task.Clock.callLater} is invoked again with a callable "B", and time
        t1 which is less than t2 but greater than t0, "B" will be invoked before
        "A".
        R   g       @R   g      @c            s   ˆ j  |  ˆ  j ƒ  f ƒ S(   N(   R)   R   (   t   n(   R   t   result(    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR   ½   s    g      ð?i   i   N(   R   g       @(   R   g      @(   R   R   R   R3   t   pumpt   assertEqual(   R   t   expectedt   logtimet   call_a(    (   R   R>   s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   test_callLaterKeepsCallsOrdered®   s    c            s   g  ‰ d
 d g } t  j ƒ  ‰  ‡  ‡ f d †  } ˆ  j d | d ƒ } ˆ  j d | d ƒ | j d ƒ ˆ  j d g d ƒ |  j ˆ | ƒ d	 S(   s:  
        The order of calls scheduled by L{task.Clock.callLater} is honored when
        re-scheduling an existing call via L{IDelayedCall.reset} on the result
        of a previous call to C{callLater}.

        For example, if L{task.Clock.callLater} is invoked with a callable "A"
        and a time t0, and then L{task.Clock.callLater} is invoked again with a
        callable "B", and time t1 greater than t0, and finally the
        L{IDelayedCall} for "A" is C{reset} to a later time, t2, which is
        greater than t1, "B" will be invoked before "A".
        R   g       @R   g      @c            s   ˆ j  |  ˆ  j ƒ  f ƒ S(   N(   R)   R   (   R=   (   R   R>   (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR   Ö   s    g      ð?i   i   N(   R   g       @(   R   g      @(   R   R   R   R3   R?   R@   (   R   RA   RB   RC   (    (   R   R>   s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt$   test_callLaterResetKeepsCallsOrderedÇ   s    c            sŸ   g  ‰ d d g } t  j ƒ  ‰  ‡  ‡ f d †  } ˆ  j d | d ƒ ‰ ‡ f d †  } ˆ  j d | ƒ ˆ  j d | d ƒ ˆ  j d	 g d
 ƒ |  j ˆ | ƒ d S(   s9  
        The order of calls scheduled by L{task.Clock.callLater} is honored when
        re-scheduling an existing call via L{IDelayedCall.reset} on the result
        of a previous call to C{callLater}, even when that call to C{reset}
        occurs within the callable scheduled by C{callLater} itself.
        R   g      @R   g      @c            s   ˆ j  |  ˆ  j ƒ  f ƒ S(   N(   R)   R   (   R=   (   R   R>   (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR   ê   s    g       @c              s   ˆ  j  d ƒ d  S(   Ng      @(   R3   (    (   t   call_b(    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR   í   s    g      ð?g      à?i
   N(   R   g      @(   R   g      @(   R   R   R   R?   R@   (   R   RA   RB   R   (    (   R   RF   R>   s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt.   test_callLaterResetInsideCallKeepsCallsOrderedà   s    (   R   R   t   __doc__R   R"   R%   R(   R,   R0   R2   R4   R5   R9   R:   R<   RD   RE   RG   (    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR      s    			
												t   LoopTestCasec           B   sq   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z RS(   s[   
    Tests for L{task.LoopingCall} based on a fake L{IReactorTime}
    implementation.
    c         C   s)   t  j d „  ƒ } |  j | j t ƒ d S(   sG   
        L{LoopingCall}'s default clock should be the reactor.
        c           S   s   d  S(   N(   R   (    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR     s    N(   R   t   LoopingCallR@   R   R   (   R   R!   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   test_defaultClocký   s    c            sI  g  ‰ d	 ‰ t j ƒ  ‰  ‡  ‡ ‡ f d †  } t j | ƒ } ˆ  | _ d ‰ | j d ƒ |  j ˆ d g ƒ |  j ˆ  j ƒ  ˆ ƒ ˆ  j d ƒ |  j ˆ d g ƒ d ‰ ˆ  j d ƒ |  j ˆ d d g ƒ |  j ˆ  j ƒ  d ƒ ˆ  j d ƒ |  j ˆ d d g ƒ d ‰ ˆ  j d ƒ |  j ˆ d d d g ƒ |  j ˆ  j ƒ  d ƒ d	 S(
   sÖ   
        When more time than the defined interval passes during the execution
        of a callback, L{LoopingCall} should schedule the next call for the
        next interval which is still in the future.
        c              s$   ˆ j  ˆ  j ƒ  ƒ ˆ  j ˆ ƒ d  S(   N(   R)   R   R+   (    (   R   t   callDurationt   times(    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt	   aCallback  s    i   g      à?i    i   g      @g      @i   N(	   R   R   R   RJ   R   t   startR@   R   R+   (   R   RN   R!   (    (   R   RL   RM   s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   test_callbackTimeSkips  s,    	c            sÏ   g  ‰ t  j ƒ  ‰  ‡  ‡ f d †  } t  j | ƒ } ˆ  | _ | j d ƒ |  j ˆ d g ƒ ˆ  j d ƒ |  j ˆ d d g ƒ ˆ  j d ƒ |  j ˆ d d d g ƒ ˆ  j d ƒ |  j ˆ d d d g ƒ d S(   s	  
        When more time than the defined interval passes between when
        L{LoopingCall} schedules itself to run again and when it actually
        runs again, it should schedule the next call for the next interval
        which is still in the future.
        c              s   ˆ j  ˆ  j ƒ  ƒ d  S(   N(   R)   R   (    (   R   RM   (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyRN   A  s    g      à?i    i   i   i   N(   R   R   RJ   R   RO   R@   R+   (   R   RN   R!   (    (   R   RM   s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   test_reactorTimeSkips8  s    	c            s,  g  ‰ t  j ƒ  ‰  ‡  ‡ f d †  } t  j j | ƒ } ˆ  | _ d } d } | j | ƒ |  j ˆ d
 g ƒ ˆ  j | | ƒ |  j ˆ d | | d f g ƒ ˆ  j d | | ƒ |  j ˆ d | | d f d | d | d f g ƒ ˆ  j d ƒ |  j ˆ d | | d f d | d | d f g ƒ d	 S(   s­  
        When L{LoopingCall} schedules itself to run again, if more than the
        specified interval has passed, it should schedule the next call for the
        next interval which is still in the future. If it was created
        using L{LoopingCall.withCount}, a positional argument will be
        inserted at the beginning of the argument list, indicating the number
        of calls that should have been made. 
        c            s   ˆ j  ˆ  j ƒ  |  f ƒ d  S(   N(   R)   R   (   t   numCalls(   R   RM   (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyRN   e  s    g      à?g{®Gáz„?i    i   i   i   i   N(   i    i   (   i    i   (   i    i   (   i    i   (   R   R   RJ   t	   withCountR   RO   R@   R+   (   R   RN   R!   t   INTERVALt   REALISTIC_DELAY(    (   R   RM   s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   test_reactorTimeCountSkipsZ  s&    		 		c            s  g  ‰ t  j ƒ  ‰  ‡  ‡ f d †  } t  j j | ƒ } ˆ  | _ d } d } | j | ƒ |  j ˆ j ƒ  d ƒ ˆ  j | | ƒ |  j ˆ j ƒ  | | d f ƒ ˆ  j | d ƒ |  j ˆ j ƒ  d | | d f ƒ ˆ  j | d ƒ |  j ˆ j ƒ  d	 | | d f ƒ d
 S(   s1  
        L{LoopingCall.withCount} counts only calls that were expected to be
        made.  So, if more than one, but less than two intervals pass between
        invocations, it won't increase the count above 1.  For example, a
        L{LoopingCall} with interval T expects to be invoked at T, 2T, 3T, etc.
        However, the reactor takes some time to get around to calling it, so in
        practice it will be called at T+something, 2T+something, 3T+something;
        and due to other things going on in the reactor, "something" is
        variable.  It won't increase the count unless "something" is greater
        than T.  So if the L{LoopingCall} is invoked at T, 2.75T, and 3T,
        the count has not increased, even though the distance between
        invocation 1 and invocation 2 is 1.75T.
        c            s   ˆ j  ˆ  j ƒ  |  f ƒ d  S(   N(   R)   R   (   t   count(   R   RM   (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyRN   š  s    g      à?g{®Gáz„?i    i   g      ü?g      @g      Ð?g      @N(   i    i   (	   R   R   RJ   RS   R   RO   R@   t   popR+   (   R   RN   R!   RT   RU   (    (   R   RM   s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   test_countLengthyIntervalCountsŠ  s    	 $c            sD  d d d g } t  j ƒ  } g  ‰ d  d  ‡ f d † } t | | d d d d ƒ} | j d ƒ } g  ‰  ‡  f d †  } | j | ƒ | j | ƒ |  j t ˆ ƒ d d	 t ˆ ƒ f ƒ xZ ˆ D]R \ } } }	 }
 |  j | d ƒ |  j | d ƒ |  j |	 d  ƒ |  j |
 d ƒ q¼ W| j	 ƒ  |  j
 ˆ  d
 | ƒ |  j | j ƒ d  S(   Ngš™™™™™©?gš™™™™™¹?c            s   ˆ  j  |  | | | f ƒ d  S(   N(   R)   (   R   R   R   t   d(   t   L(    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   foo½  s    R   R   RZ   c            s   ˆ  j  |  ƒ d  S(   N(   R)   (   R>   (   t	   theResult(    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt
   saveResultÄ  s    i   s   got %d iterations, not 3i    (   R   R   R   R   RO   t   addCallbackR?   R   t   lent   stopt   assertIdenticalR$   R8   (   R   t   timingsR   R\   t   lct   DR^   R   R   R   RZ   (    (   R]   R[   s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   testBasicFunction³  s(    
c            sÒ   d d d g } t  j ƒ  } g  } t | | j d  ƒ } | j d d t ƒ} g  ‰  ‡  f d †  } | j | ƒ | j | ƒ |  j	 t
 | ƒ d d t
 | ƒ f ƒ | j ƒ  |  j ˆ  d | ƒ |  j | j ƒ d  S(   Ngš™™™™™©?gš™™™™™¹?t   nowc            s   ˆ  j  |  ƒ d  S(   N(   R)   (   R>   (   R]   (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR^   ä  s    i   s   got %d iterations, not 2i    (   R   R   R   R)   R   RO   t   FalseR_   R?   R   R`   Ra   Rb   R$   R8   (   R   Rc   R   R[   Rd   RZ   R^   (    (   R]   s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   testDelayedStartÚ  s    
c         C   s,   t  j d „  ƒ } |  j t | j d ƒ d  S(   Nc           S   s   d  S(   N(   R   (    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR   ó  s    iÿÿÿÿ(   R   RJ   R-   t
   ValueErrorRO   (   R   Rd   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   testBadDelayò  s    c            sn   g  ‰  ‡  f d †  } t  j ƒ  } t | | ƒ } | j | d t ƒ| j ƒ  |  j ˆ  ƒ |  j | j ƒ d  S(   Nc              s   ˆ  j  d  ƒ d  S(   N(   R)   R   (    (   t   ran(    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR\   ú  s    Rg   (   R   R   R   RO   Rh   Ra   R$   R8   (   R   R1   R\   R   Rd   (    (   Rl   s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   _stoppingTestø  s    
c         C   s   |  j  d ƒ S(   Ni    (   Rm   (   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   testStopAtOnce  s    c         C   s   |  j  d ƒ S(   Ni
   (   Rm   (   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   testStoppingBeforeDelayedStart	  s    (   R   R   RH   RK   RP   RQ   RV   RY   Rf   Ri   Rk   Rm   Rn   Ro   (    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyRI   ø   s   		3	"	0	)	'				t   ReactorLoopTestCasec           B   sP   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   c         C   s4   d „  } t  j | d ƒ } |  j | j d ƒ t ƒ S(   Nc         S   s   t  |  ƒ ‚ d  S(   N(   R   (   R6   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR\     s    t   bargš™™™™™¹?(   R   RJ   t   assertFailureRO   R   (   R   R\   Rd   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   testFailure  s    	c            s:   ‡  f d †  } t  j | d ƒ ‰  |  j ˆ  j d ƒ t ƒ S(   Nc            s   ˆ  j  ƒ  t |  ƒ ‚ d  S(   N(   Ra   R   (   R6   (   Rd   (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR\     s    
Rq   gš™™™™™¹?(   R   RJ   Rr   RO   R   (   R   R\   (    (   Rd   s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   testFailAndStop  s    c            sU   g  ‰  ‡  ‡ f d †  } t  j | ƒ ‰ ˆ j d ƒ } ‡  ‡ f d †  } | j | ƒ S(   Nc              s0   ˆ  j  d  ƒ t ˆ  ƒ d k r, ˆ j ƒ  n  d  S(   Ni   (   R)   R   R`   Ra   (    (   Rl   Rd   (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR\   %  s    i    c            s   ˆ j  t ˆ  ƒ d ƒ d  S(   Ni   (   R   R`   (   t   ign(   Rl   R   (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   stopped,  s    (   R   RJ   RO   R_   (   R   R\   RZ   Rv   (    (   Rl   R   Rd   s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   testEveryIteration"  s    c            s]   t  j ƒ  ‰  ‡  f d †  } t j | ƒ |  _ |  j j d d t ƒt j d |  j	 ˆ  ƒ ˆ  S(   Nc              s   ˆ  j  t j d ƒ ƒ d  S(   Ns'   This task also should never get called.(   t   errbackR   t   DefaultException(    (   RZ   (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR\   5  s    i   Rg   i    (
   R   t   DeferredR   RJ   t   _lcRO   Rh   R   R   t!   _callback_for_testStopAtOnceLater(   R   R\   (    (   RZ   s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   testStopAtOnceLater1  s    c         C   s'   |  j  j ƒ  t j d | j d ƒ d  S(   Ni    t   success(   R{   Ra   R   R   t   callback(   R   RZ   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR|   >  s    c            sg   d d g } t  j ƒ  ‰ ‡  ‡ f d †  } t ˆ | ƒ ‰  ˆ  j d ƒ ˆ j | ƒ |  j ˆ j ƒ d  S(   Ngš™™™™™É?gš™™™™™é?c             s<   t  j ƒ  }  |  j ‡  f d †  ƒ ˆ j d |  j d  ƒ |  S(   Nc            s
   ˆ  j  ƒ  S(   N(   Ra   (   t   _(   Rd   (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR   J  s    i   (   R   Rz   R_   R   R   R   (   RZ   (   Rd   R   (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR\   H  s    (   R   R   R   RO   R?   R$   R8   (   R   Rc   R\   (    (   Rd   R   s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   testWaitDeferredB  s    c            ss   d g } t  j ƒ  ‰  ‡  f d †  } t ˆ  | ƒ } | j d ƒ } |  j | t ƒ ˆ  j | ƒ |  j ˆ  j ƒ | S(   Ng333333Ó?c             s)   t  j ƒ  }  ˆ  j d |  j t ƒ  ƒ |  S(   Ng333333Ó?(   R   Rz   R   Rx   R   (   RZ   (   R   (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR\   ]  s    i   (	   R   R   R   RO   Rr   R   R?   R$   R8   (   R   Rc   R\   Rd   RZ   (    (   R   s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   testFailurePropagationS  s    	c            sæ   t  j ƒ  } t j ƒ  ‰  g  ‰ ‡ ‡  f d †  } t  j j | ƒ } | | _ | j d d t ƒ‰  |  j	 ˆ g  ƒ | j
 d d g ƒ |  j	 t ˆ ƒ d ƒ ˆ  j d ƒ | j
 d g ƒ |  j	 t ˆ ƒ d ƒ |  j	 ˆ d d g ƒ d S(	   s?  
        In the case that the function passed to L{LoopingCall.withCount}
        returns a deferred, which does not fire before the next interval
        elapses, the function should not be run again. And if a function call
        is skipped in this fashion, the appropriate count should be
        provided.
        c            s+   ˆ  j  |  ƒ t ˆ  ƒ d k r# ˆ Sd  Sd  S(   Ni   (   R)   R`   R   (   t   possibleCount(   t   deferredCountsRZ   (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   countTrackerw  s    gš™™™™™É?Rg   gš™™™™™Ù?i   i   i   N(   R   R   R   Rz   RJ   RS   R   RO   Rh   R   R?   R`   R   R   (   R   t	   testClockR…   Rd   (    (   RZ   R„   s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   test_deferredWithCountk  s    	(
   R   R   Rs   Rt   Rw   R}   R|   R   R‚   R‡   (    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyRp     s   								t   DeferLaterTestsc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s'   
    Tests for L{task.deferLater}.
    c            sŸ   g  ‰  t  ƒ  ‰ ‡ ‡  f d †  } t j ƒ  } t j | d | d d d ƒ} | j |  j ˆ ƒ | j d ƒ |  j ˆ  g  ƒ | j d ƒ |  j ˆ  d g ƒ | S(   sœ   
        The L{Deferred} returned by L{task.deferLater} is called back after
        the specified delay with the result of the function passed in.
        c            s   ˆ j  |  | f ƒ ˆ  S(   N(   R)   (   R\   Rq   (   t   flagt   results(    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   callable¤  s    i   R\   Rq   i   i   (   s   fooRq   (   t   objectR   R   t
   deferLaterR_   Rb   R+   R@   (   R   R‹   R   RZ   (    (   RŠ   R‰   s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   test_callback  s    	c         C   sG   d „  } t  j ƒ  } t  j | d | ƒ } | j d ƒ |  j | t ƒ S(   sƒ   
        The L{Deferred} returned by L{task.deferLater} is errbacked if the
        supplied function raises an exception.
        c           S   s   t  ƒ  ‚ d  S(   N(   R   (    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR‹   ·  s    i   (   R   R   R   R+   Rr   R   (   R   R‹   R   RZ   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   test_errback²  s
    	c            sp   g  ‰ t  j ƒ  ‰  t  j ˆ  d ˆ j d ƒ } | j ƒ  ‡ ‡ ‡  f d †  } ˆ j | t j ƒ | j	 | ƒ | S(   sŒ   
        The L{Deferred} returned by L{task.deferLater} can be
        cancelled to prevent the call from actually being performed.
        i   c            s'   ˆ  j  g  ˆ j ƒ  ƒ ˆ  j ˆ ƒ d  S(   N(   R   R7   t   assertFalse(   t   ignored(   R   t   calledR   (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   cbCancelledÉ  s    N(
   R   R   R   R)   R   R#   Rr   R   t   CancelledErrorR_   (   R   RZ   R“   (    (   R   R   R’   s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   test_cancelÀ  s    
(   R   R   RH   RŽ   R   R•   (    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyRˆ   ™  s   		N(   t   twisted.python.compatR    t   twisted.trialR   t   twisted.internetR   R   R   R   R   R   t   twisted.pythonR   RJ   R   t	   ExceptionR   t   TestCaseR   RI   Rp   Rˆ   (    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt   <module>   s   (	Üÿ ‹