ó
ÐH/\c           @   sö   d  d l  j Z d  d l Z d  d l m Z d  d l m Z d  d l Z y d  d l	 m Z
 Wn! e k
 r~ d  d l m Z
 n Xd e j f d „  ƒ  YZ d e j f d „  ƒ  YZ e j d ƒ d	 e j f d
 „  ƒ  Yƒ Z e d k rò e j ƒ  n  d S(   iÿÿÿÿN(   t	   Semaphore(   t   allocate_lockt   TestSemaphorec           B   s>   e  Z d  „  Z d „  Z d „  Z d „  Z e e _ d „  Z RS(   c         C   sC   t  d d ƒ } | j d d ƒ } | t k s? t t | ƒ ƒ ‚ d  S(   Nt   valuei    t   timeoutg{®Gáz„?(   R    t   acquiret   Falset   AssertionErrort   repr(   t   selft   st   result(    (    s;   lib/python2.7/site-packages/gevent/tests/test__semaphore.pyt(   test_acquire_returns_false_after_timeout   s    c            s|   t  ƒ  } g  ‰  | j ‡  f d †  ƒ | j ƒ  | j ‡  f d †  ƒ | j ƒ  t j d ƒ |  j t ˆ  ƒ d d g ƒ d  S(   Nc            s   ˆ  j  d ƒ S(   Nt   a(   t   append(   R
   (   R   (    s;   lib/python2.7/site-packages/gevent/tests/test__semaphore.pyt   <lambda>   s    c            s   ˆ  j  d ƒ S(   Nt   b(   R   (   R
   (   R   (    s;   lib/python2.7/site-packages/gevent/tests/test__semaphore.pyR      s    gü©ñÒMbP?R   R   (   R    t   rawlinkt   releaset   geventt   sleept   assertEqualt   sorted(   R	   R
   (    (   R   s;   lib/python2.7/site-packages/gevent/tests/test__semaphore.pyt   test_release_twice   s    	

c         C   s/   t  ƒ  } t j | ƒ } |  j | | ƒ  ƒ d  S(   N(   R    t   weakreft   refR   (   R	   R
   t   r(    (    s;   lib/python2.7/site-packages/gevent/tests/test__semaphore.pyt   test_semaphore_weakref    s    	c         C   sA   d t  f d „  ƒ  Y} | ƒ  d d  l } | j ƒ  | j ƒ  d  S(   Nt   Xc           B   s   e  Z d  „  Z d „  Z RS(   c         S   s   t  ƒ  |  _ d  S(   N(   R    R
   (   R	   (    (    s;   lib/python2.7/site-packages/gevent/tests/test__semaphore.pyt   __init__*   s    c         S   s   |  j  j ƒ  d  S(   N(   R
   R   (   R	   (    (    s;   lib/python2.7/site-packages/gevent/tests/test__semaphore.pyt   __del__-   s    (   t   __name__t
   __module__R   R   (    (    (    s;   lib/python2.7/site-packages/gevent/tests/test__semaphore.pyR   )   s   	iÿÿÿÿ(   t   objectt   gct   collect(   R	   R   R"   (    (    s;   lib/python2.7/site-packages/gevent/tests/test__semaphore.pyt    test_semaphore_in_class_with_del%   s
    
c         C   s   t  ƒ  } t j | g ƒ d  S(   N(   R    R   t   wait(   R	   R
   (    (    s;   lib/python2.7/site-packages/gevent/tests/test__semaphore.pyt)   test_rawlink_on_unacquired_runs_notifiers7   s    	(	   R   R    R   R   R   R$   t   Truet   ignore_leakcheckR&   (    (    (    s;   lib/python2.7/site-packages/gevent/tests/test__semaphore.pyR      s   					t   TestLockc           B   s   e  Z d  „  Z RS(   c         C   sš   t  ƒ  } t ƒ  } y | j ƒ  |  j d ƒ Wn t k
 rH } | } n Xy | j ƒ  |  j d ƒ Wn t k
 r } | } n X|  j | t | ƒ ƒ d  S(   Ns   Should have thrown an exception(   t   std_allocate_lockR   R   t   failt	   Exceptiont   assertIsInstancet   type(   R	   t   std_lockt   g_lockt   et   std_exct   g_exc(    (    s;   lib/python2.7/site-packages/gevent/tests/test__semaphore.pyt   test_release_unheld_lockA   s    		



(   R   R    R4   (    (    (    s;   lib/python2.7/site-packages/gevent/tests/test__semaphore.pyR)   ?   s   s   Needs C extensiont   TestCExtc           B   s   e  Z d  „  Z RS(   c         C   s   |  j  t j d ƒ d  S(   Ns   gevent.__semaphore(   R   R    R    (   R	   (    (    s;   lib/python2.7/site-packages/gevent/tests/test__semaphore.pyt   test_c_extensionU   s    (   R   R    R6   (    (    (    s;   lib/python2.7/site-packages/gevent/tests/test__semaphore.pyR5   R   s   t   __main__(   t   gevent.testingt   testingt	   greentestR   t   gevent.lockR    t   gevent.threadR   R   t   _threadR*   t   ImportErrort   threadt   TestCaseR   R)   t   skipOnPurePythonR5   R   t   main(    (    (    s;   lib/python2.7/site-packages/gevent/tests/test__semaphore.pyt   <module>   s   2