σ
P'^c           @@  s΄   d  d l  m Z d  d l Z d  d l m Z d  d l m Z m Z d e f d     YZ	 d e f d     YZ
 d	 e f d
     YZ d e f d     YZ d e f d     YZ d S(   i    (   t   absolute_importN(   t   Event(   t   AppCaset   Mockt   MockProducerc           B@  s2   e  Z e Z d    Z d   Z d   Z d   Z RS(   c         O@  s   g  |  _  d  S(   N(   t   sent(   t   selft   argst   kwargs(    (    sA   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/events/test_events.pyt   __init__   s    c         O@  s)   |  j  r t    n  |  j j |  d  S(   N(   t   raise_on_publisht   KeyErrorR   t   append(   R   t   msgR   R   (    (    sA   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/events/test_events.pyt   publish   s    	c         C@  s   d  S(   N(    (   R   (    (    sA   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/events/test_events.pyt   close   s    c         C@  s,   x% |  j  D] } | d | k r
 | Sq
 Wt S(   Nt   type(   R   t   False(   R   t   kindt   event(    (    sA   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/events/test_events.pyt	   has_event   s    (   t   __name__t
   __module__R   R
   R	   R   R   R   (    (    (    sA   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/events/test_events.pyR   	   s
   			t
   test_Eventc           B@  s   e  Z d    Z RS(   c         C@  s5   t  d  } |  j | d d  |  j | d  d  S(   Ns   world war IIR   t	   timestamp(   R   t   assertEqualt
   assertTrue(   R   R   (    (    sA   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/events/test_events.pyt   test_constructor    s    (   R   R   R   (    (    (    sA   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/events/test_events.pyR      s   t   test_EventDispatcherc           B@  sP   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(   c         C@  sf   t    |  j _ t    } |  j j _ d | j _ |  j j j | d t } |  j	 | j
 j d  d  S(   Nt   redist   enabledt   fanout(   R   t   appt
   connectiont   return_valuet	   transportt   driver_typet   eventst
   DispatcherR   R   t   exchangeR   (   R   t   connt
   dispatcher(    (    sA   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/events/test_events.pyt   test_redis_uses_fanout_exchange(   s
    c         C@  sf   t    |  j _ t    } |  j j _ d | j _ |  j j j | d t } |  j	 | j
 j d  d  S(   Nt   amqpR   t   topic(   R   R    R!   R"   R#   R$   R%   R&   R   R   R'   R   (   R   R(   R)   (    (    sA   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/events/test_events.pyt   test_others_use_topic_exchange0   s
    c         C@  s;   |  j  j j d t    } |  j | j | j j j  d  S(   Nt   channel(   R    R%   R&   R   t   assertIsR!   R.   t   client(   R   t   x(    (    sA   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/events/test_events.pyt   test_takes_channel_connection7   s    c         C@  sA   t    } d | j _ |  j j j d |  } |  j | j  d  S(   Nt   sqlR!   (   R   R#   R$   R    R%   R&   t   assertFalseR   (   R   R(   R1   (    (    sA   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/events/test_events.pyt   test_sql_transports_disabled;   s    	c         C@  s  t    } |  j j   | _ t   } d | j _ |  j j j | d t d t } | | _	 t
 | _ | j d d t
 |  j | j d   t | _ | j d  |  j | j d   d } t
 | _ t
 | j	 _ t | _ |  j t   | j d
  Wd  QXt
 | _ x | D] } | j |  qWt | j	 _ | j   x$ | D] } |  j | j |   qCWt   } | _ t   | j _ | j   d  S(   NR+   R   t   buffer_while_offlines   World War IIt   endeds   World War IIIs   Event 1s   Event 2s   Event 3s   Event X(   s   Event 1s   Event 2s   Event 3(   R   R    R!   R   R#   R$   R%   R&   R   t   producert   TrueR   t   sendR   R   R4   R
   R6   t   assertRaisesR   t   flusht   _outbound_buffert
   IndexErrort   popleftt   side_effect(   R   R8   R!   t   eventert   evst   evt   buf(    (    sA   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/events/test_events.pyt	   test_sendA   s:    									
c      
   C@  sf   |  j  j   Q } |  j  j j |  } t   | _ |  } |  j |  Wd  QX| j j   Wd  QXd  S(   N(   R    R!   R%   R&   R   R   R   t   assert_called_with(   R   R(   t   dt   _d(    (    sA   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/events/test_events.pyt   test_enter_exitb   s    	c      
   C@  s   t    } t    } |  j j   s } |  j j j | d t O } | j j |  | j j |  | j	   | j
   | j   | j
   Wd  QXWd  QXd  S(   NR   (   R   R    R!   R%   R&   R   t
   on_enabledt   addt   on_disabledt   enableRF   t   disable(   R   t	   on_enablet
   on_disableR(   RG   (    (    sA   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/events/test_events.pyt   test_enable_disable_callbacksj   s    		


c         C@  s   |  j  j   } | j   } zY|  j  j j | d t } |  j  j j | d t d | } |  j | j  |  j | j j  |  j	 | j j
 |  j  j j  | j j } | j   | j   | j   |  j | j  |  j | j  |  j | j j d  | j   |  j | j  |  j | j  |  j | j | j  | j d } | _ z |  j	 | j d  Wd  | | _ XWd  | j   | j   X|  j | j  d  S(   NR   R.   s(   does not close manually provided channeli*   (   R    R!   R.   R%   R&   R9   R   R   R8   R   t
   serializert   conft   CELERY_EVENT_SERIALIZERRN   R4   t   assertIsNonet   closedRM   R/   t	   publisherR   (   R   R!   R.   R)   t   dispatcher2t   created_channelt   prev(    (    sA   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/events/test_events.pyt   test_enabled_disablev   s>    		




(
   R   R   R*   R-   R2   R5   RE   RI   RQ   R[   (    (    (    sA   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/events/test_events.pyR   &   s   					!		t   test_EventReceiverc           B@  s5   e  Z d    Z d   Z d   Z d   Z d   Z RS(   c         @  s   i d d 6} t  g     f d   } t   } d | _ |  j j j | d i | d 6d d } | j | t    |  j   d  d  S(	   Ns	   world-warR   c         @  s   t    d <d  S(   Ni    (   R9   (   R   (   t	   got_event(    sA   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/events/test_events.pyt
   my_handler¦   s    t   memoryt   handlerst   node_ids   celery.testsi    (	   R   R   t   transport_clsR    R%   t   Receivert   _receivet   objectR   (   R   t   messageR^   R!   t   r(    (   R]   sA   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/events/test_events.pyt   test_process    s    				c         @  s   i d d 6} t  g     f d   } t   } d | _ |  j j j | d d } | | j d <| j | t    |  j	   d  d  S(	   Ns	   world-warR   c         @  s   t    d <d  S(   Ni    (   R9   (   R   (   R]   (    sA   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/events/test_events.pyR^   Ή   s    R_   Ra   s   celery.testst   *i    (
   R   R   Rb   R    R%   Rc   R`   Rd   Re   R   (   R   Rf   R^   R!   Rg   (    (   R]   sA   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/events/test_events.pyt   test_catch_all_event³   s    			c         C@  s€   |  j  j   } z |  j  j j | d d } | j d d d t  } |  j t j   t	 |  Wd  QX|  j t j   | j
 d d  Wd  QXWd  | j   Xd  S(   NRa   s   celery.testst   timeoutg-Cλβ6?t   wakeupgρhγ΅ψδ>(   R    R!   R%   Rc   t   itercaptureR   R;   t   socketRk   t   nextt   captureR   (   R   R!   Rg   t   it(    (    sA   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/events/test_events.pyt   test_itercaptureΓ   s    c         C@  s~   |  j  j j t   d d } t   | _ t   } | j i d d 6d d 6d t d | |  j | j  | j j	 d  d  S(	   NRa   s   celery.testss   worker-onlineR   i9  t   clockt   localizet   adjust_timestamp(
   R    R%   Rc   R   t   adjust_clockt   event_from_messageR   R4   t   calledRF   (   R   Rg   t	   ts_adjust(    (    sA   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/events/test_events.pyt)   test_event_from_message_localize_disabledΡ   s    	c   	      @  s  |  j  j   } | j   } zΨ d g     f d   } |  j  j j | d t d | } |  j  j j | d i | d 6d d } d	 d
 d d d g } x | D] } | j |  q W| j d d d t  } t	 |  t
 |  |  j   d d  Wd  | j   | j   Xd  S(   Ni    c         @  s     d c d 7<d  S(   Ni    i   (    (   R   (   t   events_received(    sA   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/events/test_events.pyt   handlerδ   s    R   R.   R`   Ri   Ra   s   celery.testst   ev1t   ev2t   ev3t   ev4t   ev5t   limiti   Rl   (   R    R!   R.   R%   R&   R9   Rc   R:   Rm   Ro   t   listR   R   (	   R   R!   R.   R|   R8   Rg   RB   RC   Rq   (    (   R{   sA   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/events/test_events.pyt   test_itercapture_limitή   s(    		


(   R   R   Rh   Rj   Rr   Rz   R   (    (    (    sA   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/events/test_events.pyR\      s
   				t	   test_miscc           B@  s   e  Z d    Z d   Z RS(   c         C@  s/   |  j  j j   } |  j t | j  i   d  S(   N(   R    R%   t   Statet   assertDictEqualt   dictt   workers(   R   t   state(    (    sA   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/events/test_events.pyt
   test_Stateύ   s    c         C@  s<   |  j  j j   $ } |  j |  |  j | j  Wd  QXd  S(   N(   R    R%   t   default_dispatcherR   R!   (   R   RG   (    (    sA   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/events/test_events.pyt   test_default_dispatcher  s    (   R   R   R   R   (    (    (    sA   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/events/test_events.pyR   ϋ   s   	(   t
   __future__R    Rn   t   celery.eventsR   t   celery.tests.caseR   R   Re   R   R   R   R\   R   (    (    (    sA   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/events/test_events.pyt   <module>   s   x]