σ
L]c           @@  s  d  d l  m Z y d  d l Z Wn e k
 r9 d Z n Xd  d l Z d  d l Z d  d l Z d  d l Z d  d l	 Z	 d  d l
 m Z m Z y* d  d l m Z d  d l m Z e Z Wn e k
 rΟ e Z n Xe Z e r	d  d l Z e j d k r	e r	e Z q	n  d   Z d e j f d	     YZ d
 e f d     YZ e r{e r{d  d l j j j Z d e f d     YZ  n  d S(   i    (   t   absolute_importN(   t   BaseZMQTestCaset   have_gevent(   t   IOLoop(   t   ioloopi   c           C@  s"   t  j d  t  t j   GHd  S(   Ns	   say hello(   t   ost   systemt	   Exceptiont   time(    (    (    s4   lib/python2.7/site-packages/zmq/tests/test_ioloop.pyt   printer    s    t   Delayc           B@  s&   e  Z d  d  Z d   Z d   Z RS(   i   c         C@  sA   | |  _  | |  _ t |  _ t j   |  _ t t |   j	   d  S(   N(
   t   ft   delayt   Falset   abortedt	   threadingt	   Conditiont   condt   superR
   t   __init__(   t   selfR   R   (    (    s4   lib/python2.7/site-packages/zmq/tests/test_ioloop.pyR   '   s
    			c         C@  sG   |  j  j   |  j  j |  j  |  j  j   |  j sC |  j   n  d  S(   N(   R   t   acquiret   waitR   t   releaseR   R   (   R   (    (    s4   lib/python2.7/site-packages/zmq/tests/test_ioloop.pyt   run.   s
    	c         C@  s4   t  |  _ |  j j   |  j j   |  j j   d  S(   N(   t   TrueR   R   R   t   notifyR   (   R   (    (    s4   lib/python2.7/site-packages/zmq/tests/test_ioloop.pyt   abort5   s    	(   t   __name__t
   __module__R   R   R   (    (    (    s4   lib/python2.7/site-packages/zmq/tests/test_ioloop.pyR
   &   s   	t
   TestIOLoopc           B@  sP   e  Z e r e j Z n  d    Z d   Z d   Z d   Z d   Z	 d   Z
 RS(   c         C@  sI   t  s t j d  n  t t |   j   t rE t j t j    n  d  S(   Ns   tornado required(	   t   _tornadot   pytestt   skipR   R   t   setUpt   asynciot   set_event_loopt   new_event_loop(   R   (    (    s4   lib/python2.7/site-packages/zmq/tests/test_ioloop.pyR"   @   s
    c         C@  s+   t  t |   j   t j   t j   d  S(   N(   R   R   t   tearDownt
   BaseIOLoopt   clear_currentt   clear_instance(   R   (    (    s4   lib/python2.7/site-packages/zmq/tests/test_ioloop.pyR&   G   s    
c         C@  s€   |  j    } | j   t j | j d  } t j d   d  } | j   | j   t | j d  } | j   | j   | j   r | j   n |  j	 d  d S(   s   simple IOLoop creation testiΘ   c           S@  s   d  S(   N(   t   None(    (    (    s4   lib/python2.7/site-packages/zmq/tests/test_ioloop.pyt   <lambda>Q   t    i
   i   s   IOLoop failed to exitN(
   R   t   make_currentR   t   PeriodicCallbackt   stopt   startR
   t   isAliveR   t   fail(   R   t   loopt   dct   pct   t(    (    s4   lib/python2.7/site-packages/zmq/tests/test_ioloop.pyt   test_simpleL   s    




c         C@  sR   |  j  j   } t s0 t | |  j   s0 t  n  t j   } | | k sN t  d S(   s(   IOLoop.instance returns the right objectN(   R   t   instancet	   t5asynciot
   isinstancet   AssertionErrorR'   (   R   R3   t	   base_loop(    (    s4   lib/python2.7/site-packages/zmq/tests/test_ioloop.pyt   test_instance\   s
    c         C@  sR   t  j j   } t s0 t | |  j  s0 t  n  t j   } | | k sN t  d S(   s'   IOLoop.current returns the right objectN(   R   R   t   currentR9   R:   R;   R'   (   R   R3   R<   (    (    s4   lib/python2.7/site-packages/zmq/tests/test_ioloop.pyt   test_currentd   s
    c         C@  sΕ   |  j  j   } |  j t j t j  \ } } | j | d   t j  j  | j | d   t j  j  |  j	 | j
 t  |  j	 | j
 t  | j d t  |  j	 | j
 t  |  j	 | j
 t  d S(   s   Test close(all_fds=True)c         S@  s   |  S(   N(    (   t   msg(    (    s4   lib/python2.7/site-packages/zmq/tests/test_ioloop.pyR+   p   R,   c         S@  s   |  S(   N(    (   R@   (    (    s4   lib/python2.7/site-packages/zmq/tests/test_ioloop.pyR+   q   R,   t   all_fdsN(   R   R>   t   create_bound_pairt   zmqt   REQt   REPt   add_handlerR   t   READt   assertEqualt   closedR   t   closeR   (   R   R3   t   reqt   rep(    (    s4   lib/python2.7/site-packages/zmq/tests/test_ioloop.pyt   test_close_alll   s    (   R   R   R   R   R   R"   R&   R7   R=   R?   RM   (    (    (    s4   lib/python2.7/site-packages/zmq/tests/test_ioloop.pyR   <   s   					t   TestIOLoopGreenc           B@  s#   e  Z e j Z d    Z d   Z RS(   c         C@  sR   |  j  j   } t s0 t | |  j   s0 t  n  t j   } | | k sN t  d S(   s.   Green IOLoop.instance returns the right objectN(   R   R8   R9   R:   R;   R'   (   R   R3   R<   (    (    s4   lib/python2.7/site-packages/zmq/tests/test_ioloop.pyt   xtest_instance~   s
    c         C@  sR   |  j  j   } t s0 t | |  j   s0 t  n  t j   } | | k sN t  d S(   s-   Green IOLoop.current returns the right objectN(   R   R>   R9   R:   R;   R'   (   R   R3   R<   (    (    s4   lib/python2.7/site-packages/zmq/tests/test_ioloop.pyt   xtest_current   s
    (   R   R   t   green_ioloopR   RO   RP   (    (    (    s4   lib/python2.7/site-packages/zmq/tests/test_ioloop.pyRN   |   s   		(   i   (!   t
   __future__R    R#   t   ImportErrorR*   R   R   R   R    RC   t	   zmq.testsR   R   t   tornado.ioloopR   R'   t   zmq.eventloopR   R   R   R   R9   t   tornadot   version_infoR	   t   ThreadR
   R   t   zmq.green.eventloop.ioloopt   greent	   eventloopRQ   RN   (    (    (    s4   lib/python2.7/site-packages/zmq/tests/test_ioloop.pyt   <module>   s6   


	=