ó
L]c           @   s¨   d  d l  Z  d  d l m Z d  d l Z d  d l m Z d  d l m Z m Z m Z d  d l	 m
 Z
 e s| e j ƒ  d
 k rŽ e j e j _ n  d e f d	 „  ƒ  YZ d S(   iÿÿÿÿN(   t   TestCase(   t   devices(   t   BaseZMQTestCaset   SkipTestt   PYPY(   t   unicodei   i   t   TestMonitoredQueuec           B   sq   e  Z g  Z d  d d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d	 „  Z	 d
 „  Z
 d „  Z d „  Z RS(   t    t   int   outc   
      C   sM  t  j t j t j t j | | ƒ |  _ |  j j t j ƒ } |  j j t j ƒ } |  j j t j ƒ } | j	 d ƒ } | j	 d ƒ } | j	 d ƒ }	 | j
 t j | ƒ |  j j d | ƒ |  j j d | ƒ |  j j d |	 ƒ |  j j ƒ  t j d ƒ y | j t j ƒ Wn t j k
 r&n X|  j j | | | g ƒ | | | f S(   Ns   tcp://127.0.0.1s   tcp://127.0.0.1:%igš™™™™™É?(   R   t   ThreadMonitoredQueuet   zmqt   PAIRt   PUBt   devicet   contextt   sockett   SUBt   bind_to_random_portt
   setsockoptt	   SUBSCRIBEt
   connect_int   connect_outt   connect_mont   startt   timet   sleept   recv_multipartt   NOBLOCKt   ZMQErrort   socketst   extend(
   t   selft   mon_subt	   in_prefixt
   out_prefixt   alicet   bobt   mont   aportt   bportt   mport(    (    s6   lib/python2.7/site-packages/zmq/tests/test_monqueue.pyt   build_device   s(    c         C   s+   x |  j  D] } | j ƒ  ~ q
 W|  ` d  S(   N(   R   t   closeR   (   R    R   (    (    s6   lib/python2.7/site-packages/zmq/tests/test_monqueue.pyt   teardown_device2   s    
c         C   s“   |  j  ƒ  \ } } } d j ƒ  } | j | ƒ |  j | ƒ } |  j | | ƒ d j ƒ  } | j | ƒ |  j | ƒ } |  j | | ƒ |  j ƒ  d  S(   Ns	   hello bobs   hello alice(   R*   t   splitt   send_multipartR   t   assertEqualR,   (   R    R$   R%   R&   t   alicest   bobs(    (    s6   lib/python2.7/site-packages/zmq/tests/test_monqueue.pyt
   test_reply8   s    c         C   s  |  j  ƒ  \ } } } d j ƒ  } | j | ƒ d j ƒ  } | j | ƒ d j ƒ  } | j | ƒ |  j | ƒ } |  j | | ƒ |  j | ƒ } |  j | | ƒ |  j | ƒ } |  j | | ƒ d j ƒ  } | j | ƒ |  j | ƒ } |  j | | ƒ |  j ƒ  d  S(   Ns	   hello bobs   hello agains   hello again and agains   hello alice(   R*   R-   R.   R   R/   R,   (   R    R$   R%   R&   R0   t   alices2t   alices3R1   (    (    s6   lib/python2.7/site-packages/zmq/tests/test_monqueue.pyt
   test_queueD   s$    c   	      C   s›  |  j  ƒ  \ } } } d j ƒ  } | j | ƒ d j ƒ  } | j | ƒ d j ƒ  } | j | ƒ |  j | ƒ } |  j | | ƒ |  j | ƒ } |  j d g | | ƒ |  j | ƒ } |  j | | ƒ |  j | ƒ } |  j | | ƒ |  j | ƒ } |  j d g | | ƒ d j ƒ  } | j | ƒ |  j | ƒ } |  j | | ƒ |  j | ƒ } |  j d g | | ƒ |  j | ƒ } |  j d g | | ƒ |  j ƒ  d  S(   Ns	   hello bobs   hello agains   hello again and againR   s   hello aliceR	   (   R*   R-   R.   R   R/   R,   (	   R    R$   R%   R&   R0   R3   R4   R1   t   mons(    (    s6   lib/python2.7/site-packages/zmq/tests/test_monqueue.pyt   test_monitorX   s4    c   	      C   s¤  |  j  d d d ƒ \ } } } d j ƒ  } | j | ƒ d j ƒ  } | j | ƒ d j ƒ  } | j | ƒ |  j | ƒ } |  j | | ƒ |  j | ƒ } |  j d g | | ƒ |  j | ƒ } |  j | | ƒ |  j | ƒ } |  j | | ƒ |  j | ƒ } |  j d g | | ƒ d j ƒ  } | j | ƒ |  j | ƒ } |  j | | ƒ |  j | ƒ } |  j d g | | ƒ |  j | ƒ } |  j d g | | ƒ |  j ƒ  d  S(   NR   t   foot   bars	   hello bobs   hello agains   hello again and agains   hello alice(   R*   R-   R.   R   R/   R,   (	   R    R$   R%   R&   R0   R3   R4   R1   R6   (    (    s6   lib/python2.7/site-packages/zmq/tests/test_monqueue.pyt   test_prefixt   s4    c   	      C   s,  |  j  d ƒ \ } } } d j ƒ  } | j | ƒ d j ƒ  } | j | ƒ d j ƒ  } | j | ƒ |  j | ƒ } |  j | | ƒ |  j | ƒ } |  j | | ƒ |  j | ƒ } |  j | | ƒ d j ƒ  } | j | ƒ |  j | ƒ } |  j | | ƒ |  j | ƒ } |  j d g | | ƒ |  j ƒ  d  S(   NR	   s	   hello bobs   hello agains   hello again and agains   hello alice(   R*   R-   R.   R   R/   R,   (	   R    R$   R%   R&   R0   R3   R4   R1   R6   (    (    s6   lib/python2.7/site-packages/zmq/tests/test_monqueue.pyt   test_monitor_subscribe   s(    c         C   s  t  j t j t j t j d d ƒ } | |  _ | j t j d ƒ | j t j d ƒ | j	 t j d ƒ | j
 d ƒ } | j d ƒ } |  j j t j ƒ } d | _ |  j j t j ƒ } d | _ |  j j | | g ƒ | j d | ƒ | j d | ƒ | j ƒ  t j d ƒ t j ƒ  d k rd
 d g } xO | | f D]> } | j | ƒ y | j t j ƒ Wq:t j k
 rwq:Xq:Wn  d d g } | j d g | ƒ |  j | ƒ }	 |  j |	 d g | ƒ | j |	 ƒ |  j | ƒ }
 |  j |
 d g | ƒ |  j ƒ  d S(   s   test router-router MQ devicesR   R	   i    s   tcp://127.0.0.1t   at   bs   tcp://127.0.0.1:%ii   i   t   pingt   pongt   hellot   thereN(   i   i   i    (   R   R
   R   t   ROUTERR   R   t   setsockopt_int   LINGERt   setsockopt_outt   setsockopt_mont   bind_in_to_random_portt   bind_out_to_random_portR   R   t   DEALERt   identityR   R   t   connectR   R   R   t   zmq_version_infoR.   t   recvR   R   R   R/   R,   (   R    t   devt   portat   portbR<   R=   t   ping_msgt   st   msgt   bmsgt   amsg(    (    s6   lib/python2.7/site-packages/zmq/tests/test_monqueue.pyt   test_router_router¦   s@    $			
c         C   sv   t  j t j t j t j ƒ |  _ } | j t j d ƒ | j	 t j d ƒ | j
 t j d ƒ | j ƒ  |  j ƒ  d  S(   Ni    (   R   R
   R   RB   RI   R   R   RC   RD   RE   RF   R   R,   (   R    RN   (    (    s6   lib/python2.7/site-packages/zmq/tests/test_monqueue.pyt   test_default_mq_argsÌ   s    %
c         C   s   |  j  j t j ƒ } |  j  j t j ƒ } |  j  j t j ƒ } |  j j | | | g ƒ t d ƒ } t d ƒ } |  j	 t
 t j | | | ƒ d  S(   NR   R	   (   R   R   R   RB   RI   R   R   R   R   t   assertRaisest	   TypeErrorR   t   monitoredqueue(   R    t   inst   outsR6   (    (    s6   lib/python2.7/site-packages/zmq/tests/test_monqueue.pyt   test_mq_check_prefixÕ   s    (   t   __name__t
   __module__R   R*   R,   R2   R5   R7   R:   R;   RV   RW   R]   (    (    (    s6   lib/python2.7/site-packages/zmq/tests/test_monqueue.pyR      s   							&		(   i   i   (   R   t   unittestR    R   R   t	   zmq.testsR   R   R   t   zmq.utils.strtypesR   RL   t   Contextt   Devicet   context_factoryR   (    (    (    s6   lib/python2.7/site-packages/zmq/tests/test_monqueue.pyt   <module>   s   