ó
O'—^c           @@  sh  d  d l  m Z d  d l Z d  d l m Z d  d l m Z d  d l m Z m	 Z	 m
 Z
 m Z m Z m Z m Z m Z d d l m Z m Z m Z 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 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   RecoverableConnectionError(   t   common(   t	   Broadcastt   maybe_declaret
   send_replyt   collect_repliest   declaration_cachedt   ignore_errorst   QoSt   PREFETCH_COUNT_MAXi   (   t   Caset   ContextMockt   Mockt   MockPoolt   patcht   test_ignore_errorsc           B@  s   e  Z d  „  Z RS(   c      
   C@  s™   t  ƒ  } t f | _ t f | _ t | ƒ  t ƒ  ‚ Wd  QXd „  } t | | ƒ d | _ | _ |  j t ƒ ! t | ƒ  t ƒ  ‚ Wd  QXWd  QXd  S(   Nc           S@  s   t  ƒ  ‚ d  S(   N(   t   KeyError(    (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt   raising   s    (    (   R   R   t   channel_errorst   connection_errorsR   t   assertRaises(   t   selft
   connectionR   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt   test_ignored   s    		(   t   __name__t
   __module__R   (    (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyR      s   t   test_declaration_cachedc           B@  s   e  Z d  „  Z d „  Z RS(   c         C@  s5   t  ƒ  } d g | j j _ |  j t d | ƒ ƒ d  S(   Nt   foo(   R   R   t   clientt   declared_entitiest
   assertTrueR   (   R   t   chan(    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt   test_when_cached+   s    	c         C@  s5   t  ƒ  } d g | j j _ |  j t d | ƒ ƒ d  S(   Nt   barR   (   R   R   R   R   t   assertFalseR   (   R   R    (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt   test_when_not_cached0   s    	(   R   R   R!   R$   (    (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyR   )   s   	t   test_Broadcastc           B@  s   e  Z d  „  Z RS(   c         C@  sØ   t  d d ƒ } |  j | j j d ƒ ƒ |  j | j d ƒ |  j | j ƒ |  j | j j d ƒ |  j | j j d ƒ t  d d ƒ } |  j | j d ƒ |  j | j j d ƒ | t	 ƒ  ƒ } |  j | j | j ƒ d  S(   Nt   nameR%   s   bcast.t   fanoutt   explicit_queue_name(
   R   R   R&   t
   startswitht   assertEqualt   aliast   auto_deletet   exchanget   typeR   (   R   t   qt   q2(    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt   test_arguments8   s    (   R   R   R1   (    (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyR%   6   s   t   test_maybe_declarec           B@  s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C@  sê   t  ƒ  } t  ƒ  } | j _ t ƒ  | _ t  ƒ  } t | _ t | _ t | _	 | | _
 t | | ƒ |  j | j j d ƒ |  j t | ƒ | j j j ƒ t | | ƒ |  j | j j d ƒ d  | j
 _ |  j t ƒ  t | ƒ Wd  QXd  S(   Ni   (   R   R   R   t   setR   t   Truet   can_cache_declarationt   FalseR,   t   is_boundt   channelR   R*   t   declaret
   call_countt   assertInt   hasht   NoneR   R   (   R   R8   R   t   entity(    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt   test_cacheableJ   s"    						c         C@  sr   t  ƒ  } t ƒ  | j j _ t  ƒ  } t | _ t | _ | | j	 _
 | | j	 j
 _ t | | ƒ | j	 j | ƒ d  S(   N(   R   R3   R   R   R   R4   R5   R6   R7   t   bindt   return_valueR8   R   t   assert_called_with(   R   R8   R>   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt   test_binds_entitiesa   s    				c         C@  s|   t  ƒ  } t  ƒ  } | j _ t ƒ  | _ t  ƒ  } t | _ t | _ | | _ t	 | | d t ƒ|  j
 | j j j j ƒ d  S(   Nt   retry(   R   R   R   R3   R   R4   R5   R7   R8   R   R   t   ensureR:   (   R   R8   R   R>   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt   test_with_retrym   s    					(   R   R   R?   RC   RF   (    (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyR2   H   s   		t   test_repliesc           B@  sP   e  Z d  „  Z e d ƒ d „  ƒ Z e d ƒ d „  ƒ Z e d ƒ d „  ƒ Z RS(   c         C@  s  t  ƒ  } d | _ d | _ i d d 6d d 6| _ t  ƒ  } t  ƒ  } t | _ | | _ t  ƒ  } | | _ t ƒ  | j j j	 _
 t | | i d d 6| ƒ |  j | j j ƒ | j j } |  j | d d i d d 6ƒ |  j | d i | d	 6d d
 6d d 6d d 6t d 6d  d 6d d 6ƒ d  S(   Ns   application/jsont   binaryt   hellot   reply_tot   worldt   correlation_idi    i   R-   t   routing_keyt   jsont
   serializerRD   t   retry_policyt   content_encoding(   R   t   content_typeRQ   t
   propertiesR4   R7   R8   R3   R   R   R   R   R   t   publishR:   t	   call_argst   assertDictEqualR6   R=   (   R   t   reqR8   R-   t   producert   args(    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt   test_send_reply|   s.    			
						s   kombu.common.itermessagesc   	      C@  sÓ   t  ƒ  t  ƒ  t  ƒ  } } } t  ƒ  t  ƒ  } } | | f g | _ t | | | d t ƒ} t | ƒ } |  j | | ƒ | j | | | d t ƒ| j j ƒ  |  j t	 ƒ  t | ƒ Wd  QX| j
 j | j ƒ d  S(   Nt   no_ack(   R   RA   R   R6   t   nextt   assertIsRB   t   ackR   t   StopIterationt   after_reply_message_receivedR&   (	   R   t   itermessagest   connR8   t   queuet   bodyt   messaget   itt   m(    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt   test_collect_replies_with_ack–   s    c   	      C@  s    t  ƒ  t  ƒ  t  ƒ  } } } t  ƒ  t  ƒ  } } | | f g | _ t | | | ƒ } t | ƒ } |  j | | ƒ | j | | | d t ƒ|  j | j j	 ƒ d  S(   NR[   (
   R   RA   R   R\   R]   RB   R4   R#   R^   t   called(	   R   Ra   Rb   R8   Rc   Rd   Re   Rf   Rg   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt   test_collect_replies_no_ack¦   s    c         C@  so   t  ƒ  t  ƒ  t  ƒ  } } } g  | _ t | | | ƒ } |  j t ƒ  t | ƒ Wd  QX|  j | j j ƒ d  S(   N(	   R   RA   R   R   R_   R\   R#   R`   Ri   (   R   Ra   Rb   R8   Rc   Rf   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt   test_collect_replies_no_replies±   s    	(   R   R   RZ   R   Rh   Rj   Rk   (    (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyRG   z   s   	t   test_insuredc           B@  sD   e  Z e d  ƒ d „  ƒ Z d „  Z d d „ Z d „  Z d „  Z RS(	   s   kombu.common.loggerc         C@  s'   t  j d d ƒ |  j | j j ƒ d  S(   NR   i   (   R   t   _ensure_errbackR   t   errorRi   (   R   t   logger(    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt   test_ensure_errback¾   s    c         C@  sO   t  ƒ  } t  ƒ  } t j t  ƒ  | | ƒ | j | ƒ t j t  ƒ  | d  ƒ d  S(   N(   R   R   t   revive_connectionRB   R=   (   R   t	   on_reviveR8   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt   test_revive_connectionÃ   s
    		t   workst   ignoredc         C@  sJ   t  ƒ  } t | ƒ } t ƒ  } t ƒ  } | j _ | | _ | | | | f S(   N(   R   R   R   t	   autoretryRA   (   R   t   insured_returnsRb   t   poolt   funt   insured(    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt   get_insured_mocksË   s    			c   
      C@  s  |  j  ƒ  \ } } } } t j | | d i d d 6ƒ } |  j | d ƒ | j j d t j ƒ |  j | j ƒ | j	 \ } } |  j
 | d	 ƒ |  j | i d d 6| d 6ƒ |  j | j j ƒ | j j	 \ } }	 |  j
 | | | j f ƒ |  j |	 j d ƒ ƒ |  j |	 j d ƒ ƒ d  S(
   Ni   R"   R   Rt   t   errbackR   Rr   (   i   i   (   i   i   (   R{   R   Rz   R*   t   ensure_connectionRB   Rm   R   Ri   RU   t   assertTupleEqualRV   Rv   t   default_channelt   get(
   R   Rb   Rx   Ry   Rz   t   rett   i_argst   i_kwargst   ar_argst	   ar_kwargs(    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyRl   Ó   s    
c         C@  s[   |  j  ƒ  \ } } } } t ƒ  } t j | | d i d d 6d | ƒ| j j d | ƒ d  S(   Ni   R"   R   R|   (   i   i   (   R{   R   R   Rz   R}   RB   (   R   Rb   Rx   Ry   Rz   t   custom_errback(    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt   test_insured_custom_errbackè   s
    	(   Rt   Ru   (   R   R   R   Rp   Rs   R{   Rl   R‡   (    (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyRl   ¼   s
   		t   MockConsumerc           B@  s2   e  Z e ƒ  Z d d d  „ Z d „  Z d „  Z RS(   c         K@  s   | |  _  | |  _ | |  _ d  S(   N(   R8   t   queuest	   callbacks(   R   R8   R‰   RŠ   t   kwargs(    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt   __init__ô   s    		c         C@  s   |  j  j |  ƒ |  S(   N(   t	   consumerst   add(   R   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt	   __enter__ù   s    c         G@  s   |  j  j |  ƒ d  S(   N(   R   t   discard(   R   t   exc_info(    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt   __exit__ý   s    N(   R   R   R3   R   R=   RŒ   R   R’   (    (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyRˆ   ñ   s   		t   test_itermessagesc           B@  sE   e  Z d  e f d „  ƒ  YZ d „  Z d „  Z e d ƒ d „  ƒ Z RS(   t   MockConnectionc           B@  s   e  Z e Z d  „  Z RS(   c         K@  sQ   |  j  r t j ƒ  ‚ n  x2 t j D]' } x | j D] } | d d ƒ q2 Wq" Wd  S(   NRd   Re   (   t   should_raise_timeoutt   sockett   timeoutRˆ   R   RŠ   (   R   R‹   t   consumert   callback(    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt   drain_events  s
    	(   R   R   R6   R•   Rš   (    (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyR”     s   c         C@  s…   |  j  ƒ  } t ƒ  } | | j _ t | _ t j | | d d d ƒ} t | ƒ } |  j	 | d ƒ |  j
 t ƒ  t | ƒ Wd  QXd  S(   NR/   t   limiti   Rd   Re   (   Rd   Re   (   R”   R   R   R   Rˆ   t   ConsumerR   Ra   R\   R~   R   R_   (   R   Rb   R8   Rf   R   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt   test_default  s    		c         C@  sr   |  j  ƒ  } t | _ t ƒ  } | | j _ t | _ t j	 | | d d d ƒ} |  j
 t ƒ  t | ƒ Wd  QXd  S(   NR/   R›   i   (   R”   R4   R•   R   R   R   Rˆ   Rœ   R   Ra   R   R_   R\   (   R   Rb   R8   Rf   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt   test_when_raises_socket_timeout  s    			s   kombu.common.dequec         C@  s|   t  ƒ  } | _ t ƒ  | j _ |  j ƒ  } t  ƒ  } t | _ t j	 | | d d d ƒ} |  j
 t ƒ  t | ƒ Wd  QXd  S(   NR/   R›   i   (   R   RA   t
   IndexErrort   popleftt   side_effectR”   Rˆ   Rœ   R   Ra   R   R_   R\   (   R   t   dequet   deque_instanceRb   R8   Rf   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt   test_when_raises_IndexError%  s    		(   R   R   t   objectR”   R   Rž   R   R¤   (    (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyR“     s   
		t   test_QoSc           B@  sf   e  Z d  e f d „  ƒ  YZ d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z RS(
   t   _QoSc           B@  s   e  Z d  „  Z d „  Z RS(   c         C@  s    | |  _  t j |  d  | ƒ d  S(   N(   t   valueR	   RŒ   R=   (   R   R¨   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyRŒ   5  s    	c         C@  s   | S(   N(    (   R   R¨   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyR3   9  s    (   R   R   RŒ   R3   (    (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyR§   4  s   	c         C@  sj   t  d ƒ X } t ƒ  } t | d ƒ } d | _ | j d ƒ |  j | j j ƒ | j d d ƒ Wd  QXd  S(   Ns   kombu.common.loggeri
   id   I       t   prefetch_counti    (	   R   R   R	   t   prevR3   R   t   warnRi   RB   (   R   Ro   R™   t   qos(    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt   test_qos_exceeds_16bit<  s    		c         C@  sŠ   |  j  d ƒ } |  j | j ƒ  d ƒ |  j | j d ƒ d ƒ |  j | j d ƒ d ƒ |  j | j d ƒ d ƒ |  j | j ƒ  d ƒ d  S(   Ni
   i   i   i   iâÿÿÿi   i   (   R§   R*   t   increment_eventuallyt   decrement_eventually(   R   R¬   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt   test_qos_increment_decrementG  s    c         C@  s£   |  j  d ƒ } |  j | j ƒ  d ƒ |  j | j d ƒ d ƒ |  j | j d ƒ d ƒ |  j | j d ƒ d ƒ |  j | j ƒ  d ƒ |  j | j d ƒ d ƒ d  S(   Ni    i   iâÿÿÿi   i
   (   R§   R*   R®   R¯   (   R   R¬   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt%   test_qos_disabled_increment_decrementO  s    c         @  s‰   |  j  d ƒ ‰  ‡  f d †  } ‡  f d †  } d „  } | | | g ƒ |  j ˆ  j d ƒ d ˆ  _ | | | g ƒ |  j ˆ  j d ƒ d  S(   Ni
   c          @  s%   x t  d ƒ D] }  ˆ  j ƒ  q Wd  S(   Niè  (   t   rangeR®   (   t   i(   R¬   (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyRŽ   [  s    c          @  s%   x t  d ƒ D] }  ˆ  j ƒ  q Wd  S(   Niè  (   R²   R¯   (   R³   (   R¬   (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt   sub_  s    c         S@  sl   d d l  m } g  |  D] } | d | ƒ ^ q } x | D] } | j ƒ  q9 Wx | D] } | j ƒ  qT Wd  S(   Ni    (   t   Threadt   target(   t	   threadingRµ   t   startt   join(   t   funsRµ   Ry   t   threadst   thread(    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt   threadedc  s    "iÚ  iè  (   R§   R*   R¨   (   R   RŽ   R´   R½   (    (   R¬   s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt   test_qos_thread_safeX  s    		c         C@  s·   t  t ƒ  t d ƒ } | j ƒ  |  j | j t d ƒ | j ƒ  |  j | j t ƒ | j ƒ  |  j | j t d ƒ | j ƒ  |  j | j t ƒ | j ƒ  |  j | j t d ƒ d  S(   Ni   (   R	   R   R
   t   updateR*   R¨   R®   R¯   (   R   R¬   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt   test_exceeds_shortr  s    




c         C@  s  t  ƒ  } t | j d ƒ } | j ƒ  |  j | j d ƒ | j j d d ƒ | j ƒ  | j ƒ  |  j | j d ƒ | j j d d ƒ | j ƒ  |  j | j d ƒ | j j d d ƒ |  j i d d 6| j j	 ƒ d | _ | j ƒ  |  j | j d ƒ | j
 ƒ  |  j | j d ƒ d  S(   Ni
   R©   i	   i   i    (   R   R	   R¬   R¿   R*   R¨   RB   R¯   R;   RU   R®   (   R   t	   mconsumerR¬   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt!   test_consumer_increment_decrement  s$    	



	

c         C@  sb   t  ƒ  } t | j d ƒ } | j ƒ  |  j | j d ƒ d | _ | j ƒ  |  j | j d ƒ d  S(   Ni
   i	   i    (   R   R	   R¬   R¯   R*   R¨   (   R   RÁ   R¬   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt"   test_consumer_decrement_eventually•  s    	
	
c         C@  sO   t  ƒ  } t | j d ƒ } | j d ƒ |  j | j d ƒ | j | j ƒ d  S(   Ni
   i   (   R   R	   R¬   R3   R*   Rª   (   R   RÁ   R¬   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt   test_setž  s
    	(   R   R   R	   R§   R­   R°   R±   R¾   RÀ   RÂ   RÃ   RÄ   (    (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyR¦   2  s   									(    t
   __future__R    R–   t   amqpR   t   kombuR   t   kombu.commonR   R   R   R   R   R   R	   R
   t   caseR   R   R   R   R   R   R   R%   R2   RG   Rl   R¥   Rˆ   R“   R¦   (    (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/tests/test_common.pyt   <module>   s   :(2B51