ó
ÐH/\c           @   s¬   d  d l  j Z d  d l Z d  d l m Z d  d l Z d Z e j sS e d Z	 n
 e d Z	 d e j
 f d „  ƒ  YZ d e j
 f d	 „  ƒ  YZ e d
 k r¨ e j ƒ  n  d S(   iÿÿÿÿN(   t   get_hubg{®Gáz„?g       @g      4@t   TestDirectRaisec           B   s    e  Z e Z d  „  Z d „  Z RS(   c         C   sF   y t  j ‚ Wn2 t  j k
 rA } | j sB t t | ƒ ƒ ‚ n Xd  S(   N(   t   geventt   Timeoutt   pendingt   AssertionErrort   repr(   t   selft   t(    (    s9   lib/python2.7/site-packages/gevent/tests/test__timeout.pyt   test_direct_raise_class   s    c         C   sm   t  j ƒ  } y
 | ‚ WnP t  j k
 rh } | | k sI t | | f ƒ ‚ | j si t t | ƒ ƒ ‚ n Xd  S(   N(   R   R   R   R   R   (   R   t   timeoutR   (    (    s9   lib/python2.7/site-packages/gevent/tests/test__timeout.pyt   test_direct_raise_instance   s    
(   t   __name__t
   __module__t   Falset   switch_expectedR	   R   (    (    (    s9   lib/python2.7/site-packages/gevent/tests/test__timeout.pyR      s   	t   Testc           B   s‰   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e	 d „ Z
 d „  Z d	 „  Z d
 „  Z d „  Z e j d „  ƒ Z RS(   c         C   sa   y t  ƒ  j ƒ  |  j d ƒ Wn< t j k
 r\ } | | k	 rE ‚  n  | rX | j ƒ  n  | SXd  S(   Ns   Must raise Timeout(   R    t   switcht   failR   R   t   close(   R   R
   R   t   ex(    (    s9   lib/python2.7/site-packages/gevent/tests/test__timeout.pyt   _test!   s    c         C   s4   | j  ƒ  |  j | t ƒ | j  ƒ  |  j | t ƒ S(   N(   t   startR   R   t   True(   R   R
   (    (    s9   lib/python2.7/site-packages/gevent/tests/test__timeout.pyt   _check_expires,   s    

c         C   s    t  j t ƒ } |  j | ƒ d  S(   N(   R   R   t   SHOULD_EXPIRER   (   R   R
   (    (    s9   lib/python2.7/site-packages/gevent/tests/test__timeout.pyt   test_expires3   s    c         C   s#   t  j t t ƒ } |  j | ƒ d  S(   N(   R   R   R   R   R   (   R   R
   (    (    s9   lib/python2.7/site-packages/gevent/tests/test__timeout.pyt   test_expires_false7   s    c         C   sA   t  j t d ƒ } |  j | ƒ } |  j t | ƒ j d ƒ ƒ d  S(   Nt   XXX(   R   R   R   R   t
   assertTruet   strt   endswith(   R   R
   R   (    (    s9   lib/python2.7/site-packages/gevent/tests/test__timeout.pyt   test_expires_str=   s    c         C   s8   |  j  d t | ƒ k p' d t | ƒ k t | ƒ ƒ d  S(   Ns   exceptions must bes   exceptions must derive(   R   R   (   R   R   (    (    s9   lib/python2.7/site-packages/gevent/tests/test__timeout.pyt   assert_type_errD   s    c         C   sê  t  j t t ƒ  ƒ } | j ƒ  y t ƒ  j ƒ  |  j d ƒ Wn  t k
 r_ } |  j	 | ƒ n X| j
 ƒ  d d d „  ƒ  Y} t  j t | ƒ } | j ƒ  y t ƒ  j ƒ  |  j d ƒ Wnl t k
 rì } |  j t j d ƒ |  j	 | ƒ n: |  j t j d ƒ t j ƒ  d } |  j | | ƒ n X| j
 ƒ  t  j t | ƒ  ƒ } | j ƒ  y t ƒ  j ƒ  |  j d ƒ Wnl t k
 r¢} |  j t j d ƒ |  j	 | ƒ n: |  j t j d ƒ t j ƒ  d } |  j | | ƒ n X| j
 ƒ  d  S(	   Ns   Most raise TypeErrort   OldStylec           B   s   e  Z RS(    (   R   R   (    (    (    s9   lib/python2.7/site-packages/gevent/tests/test__timeout.pyR"   R   s   s   Must raise OldStyles-   Py3 raises a TypeError for non-BaseExceptionss+   Old style classes can only be raised on Py2i    (    (   R   R   R   t   objectR   R    R   R   t	   TypeErrorR!   R   R   t	   greentestt   PY3t   PY2t   syst   exc_infot   assertEqual(   R   R
   R   R"   R   (    (    s9   lib/python2.7/site-packages/gevent/tests/test__timeout.pyt   test_expires_non_exceptionH   sF    




c         C   sd   y |  t  ƒ  j ƒ  Wd  QXWn) t j k
 rI } | | k	 rE ‚  n  | SX| r` |  j d ƒ n  d  S(   Ns   Must raise Timeout(   R    R   R   R   R   (   R   R
   t   raisesR   (    (    s9   lib/python2.7/site-packages/gevent/tests/test__timeout.pyt   _check_context_manager_expiresp   s    c         C   s    t  j t ƒ } |  j | ƒ d  S(   N(   R   R   R   R-   (   R   R
   (    (    s9   lib/python2.7/site-packages/gevent/tests/test__timeout.pyt   test_context_manager|   s    c         C   sN   t  j t t ƒ } |  j | d t ƒ|  j t | ƒ j d ƒ t | ƒ ƒ d  S(   NR,   s   (silent)(   R   R   R   R   R-   R   R   R   (   R   R
   (    (    s9   lib/python2.7/site-packages/gevent/tests/test__timeout.pyt   test_context_manager_false€   s    c         C   sJ   t  j t d ƒ } |  j | ƒ } |  j t | ƒ j d ƒ t | ƒ ƒ d  S(   NR   (   R   R   R   R-   R   R   R   (   R   R
   R   (    (    s9   lib/python2.7/site-packages/gevent/tests/test__timeout.pyt   test_context_manager_str†   s    c         C   sQ   t  j t ƒ } | j ƒ  | j ƒ  t  j t ƒ |  j | j | ƒ | j	 ƒ  d  S(   N(
   R   R   R   R   t   cancelt   sleept   SHOULD_NOT_EXPIREt   assertFalseR   R   (   R   R
   (    (    s9   lib/python2.7/site-packages/gevent/tests/test__timeout.pyt   test_cancel‹   s    

c         C   s•   |  j  t j ƒ  t j t t j t ƒ Wd  QXt ƒ  } t j t t j t d | ƒ} |  j | | ƒ t j t t j t d | ƒ} |  j	 | ƒ d  S(   Nt   timeout_value(
   t   assertRaisesR   R   t   with_timeoutR   R2   R3   R#   t   assertIst   assertIsNone(   R   t   Xt   r(    (    s9   lib/python2.7/site-packages/gevent/tests/test__timeout.pyt   test_with_timeout“   s    	(   R   R   R   R   R   R   R    R!   R+   R   R-   R.   R/   R0   R5   R%   t   ignores_leakcheckR=   (    (    (    s9   lib/python2.7/site-packages/gevent/tests/test__timeout.pyR      s   							(				t   __main__(   t   gevent.testingt   testingR%   R   t
   gevent.hubR    R(   R   t   RUNNING_ON_CIR3   t   TestCaseR   R   R   t   main(    (    (    s9   lib/python2.7/site-packages/gevent/tests/test__timeout.pyt   <module>   s   	
