ó
­ŤY]c           @   sř   d  d l  Z  d  d l Z d  d l Z y d  d l Z Wn e k
 rM d Z n Xd  d l Z d  d l Z d  d l m	 Z	 m
 Z
 m Z m Z y e j Wn e k
 r˛ e j d  n Xd   Z d e j f d     YZ d   Z e d k rô e   n  d S(	   i˙˙˙˙N(   t   TESTFNt   run_unittestt   reap_threadst   cpython_onlys-   select.poll not defined -- skipping test_pollc         C   s;   g  } x. |  D]& \ } } | | @r | j  |  q q W| S(   N(   t   append(   t   readyt   flagt   matcht   fdt   mode(    (    s   lib/python2.7/test/test_poll.pyt   find_ready_matching   s
    
t	   PollTestsc           B   s}   e  Z d    Z d   Z d   Z d   Z e d    Z e j	 e
 d  e d     Z e j	 e
 d  e d     Z RS(   c         C   s  t  j   } d } d } t |  } g  } g  } i  } i  } x t |  D]y }	 t j   \ }
 } | j |
  | j |
 t  j  | j | t  j	  | j
 |
  | j
 |  | | |
 <|
 | | <qI Wg  } x| rč| j   } t | t  j	  } | st d  n  t j |  } t j | |  | j   } t | t  j  } | sTt d  n  t j |  }
 t j |
 |  } |  j t |  |  | j
 |  t j | |
  t j |
  | j | |
  | j |
  | j | |
  qĎ W|  j | | g |  d  S(   Ni   s    This is a test.s   no pipes ready for writings   no pipes ready for reading(   t   selectt   pollt   lent   ranget   ost   pipet   registert   modifyt   POLLINt   POLLOUTR   R
   t   RuntimeErrort   randomt   choicet   writet   readt   assertEqualt   closet
   unregistert   remove(   t   selft   pt	   NUM_PIPESt   MSGt   MSG_LENt   readerst   writerst   r2wt   w2rt   it   rdt   wrt   bufsR   t   ready_writerst   ready_readerst   buf(    (    s   lib/python2.7/test/test_poll.pyt
   test_poll1   sN    
	 c   	      C   sÍ  d } y t  j |  Wn t k
 r* n Xt j   } | j |  | j   } |  j | d | t j f  t t	 d  } | j
   } t j   } | j |  | j   } |  j | d d |  | j   | j   } |  j | d | t j f  t  j t	  t j   } |  j t | j |  |  j t | j |  t j   } |  j t | j d  t j   } d d	 d     Y} d d
 d     Y} |  j t | j |   d  |  j t | j |   d  d  S(   Ni*   i    t   wi   t   Nopec           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s   lib/python2.7/test/test_poll.pyR1   p   s   t   Almostc           B   s   e  Z d    Z RS(   c         S   s   d S(   Nt   fileno(    (   R   (    (    s   lib/python2.7/test/test_poll.pyR5   t   s    (   R2   R3   R5   (    (    (    s   lib/python2.7/test/test_poll.pyR4   s   s   (    (    (   R   R   t   OSErrorR   R   R   R   t   POLLNVALt   openR    R5   t   unlinkt   assertRaisest	   TypeErrorR   t   KeyError(	   R   t   FDR    t   rt   fR   t   pollsterR1   R4   (    (    s   lib/python2.7/test/test_poll.pyt   poll_unit_testsN   s:    
c   	      C   s   d } t  j | d  } t j   } | j | t j  x¸ d d D]Ź } | j |  } | g  k ri qB n  | d \ } } | t j @r´ | j   } | d k rB |  j d  qB qB qB | t j @rÝ | j   } | sB PqB qB qB |  j d |  qB W| j	   d  S(   Ns?   for i in 0 1 2 3 4 5 6 7 8 9; do echo testing...; sleep 1; doneR>   i    ič  iĐ  i   i@  i>  i˙˙˙˙i
   t    s6   error: pipe seems to be closed, but still returns datas,   Unexpected return value from select.poll: %s(   i    ič  iĐ  i   i@  i>  (   i˙˙˙˙(
   i˙˙˙˙i˙˙˙˙i˙˙˙˙i˙˙˙˙i˙˙˙˙i˙˙˙˙i˙˙˙˙i˙˙˙˙i˙˙˙˙i˙˙˙˙(
   R   t   popenR   R   R   R   t   POLLHUPt   readlinet   failR   (	   R   t   cmdR    R@   t   toutt   fdlistR   t   flagst   line(    (    s   lib/python2.7/test/test_poll.pyt
   test_poll2}   s*    c         C   sš   t  j   } | j d  |  j t | j d
  d } | d k rQ |  j d  n  |  j t | j d d	  |  j t | j d d  |  j t | j d d	  |  j t | j d d  d  S(   Ni   l    i@   i   i   i   s   Overflow must have occurredi    i˙˙˙˙l            i   l            l            (   R   R   R   R:   t   OverflowErrorRF   R   (   R   R@   t   x(    (    s   lib/python2.7/test/test_poll.pyt
   test_poll3   s    c         C   s§   d d l  m } m } m } t j   } | j d  |  j t | j d | d  |  j t | j	 d | d  |  j t | j | d  |  j t | j | d  d  S(   Ni˙˙˙˙(   t	   USHRT_MAXt   INT_MAXt   UINT_MAXi   i    (
   t	   _testcapiRP   RQ   RR   R   R   R   R:   RM   R   (   R   RP   RQ   RR   R@   (    (    s   lib/python2.7/test/test_poll.pyt   test_poll_c_limits§   s    s!   Threading required for this test.c         C   sJ  t  j   \ } } |  j t  j |  |  j t  j |  g  } xC t d  D]5 } t  j |  } |  j t  j |  | j |  qK Wt j   } x! | D] } | j	 | t j
  q Wt j d | j  } | j   zU t j d  x | D] } | j |  qę W| j	 | t j  |  j t | j  Wd  t  j | d  | j   Xd  S(   Ni
   t   targetg      ŕ?t   spam(   R   R   t
   addCleanupR   R   t   dupR   R   R   R   R   t	   threadingt   Threadt   startt   timet   sleepR   R   R:   R   R   t   join(   R   R>   R0   t   rfdsR(   R   R@   t   t(    (    s   lib/python2.7/test/test_poll.pyt   test_threaded_pollł   s*    
c         C   sä   xÝ d  d d d g D]É } t j   \ } } t j   } | j | t j  t j d | j d | f  } | j	   | j
 d d  |  j | j    t j | d  | j
   |  j | j    t j |  t j |  q Wd  S(	   Niü˙˙i˙˙˙˙g      đżRU   t   argst   timeoutgš?RV   (   t   NoneR   R   R   R   R   R   RY   RZ   R[   R^   t
   assertTruet   is_aliveR   t   assertFalseR   (   R   t
   timeout_msR>   R0   R@   t   poll_thread(    (    s   lib/python2.7/test/test_poll.pyt!   test_poll_blocks_with_negative_msĐ   s    

(   R2   R3   R/   RA   RL   RO   R   RT   t   unittestt
   skipUnlessRY   R   Ra   Rj   (    (    (    s   lib/python2.7/test/test_poll.pyR      s   	1	/		c           C   s   t  t  d  S(   N(   R   R   (    (    (    s   lib/python2.7/test/test_poll.pyt	   test_mainç   s    t   __main__(   R   R   R   RY   t   ImportErrorRd   R\   Rk   t   test.test_supportR    R   R   R   R   t   AttributeErrort   SkipTestR
   t   TestCaseR   Rm   R2   (    (    (    s   lib/python2.7/test/test_poll.pyt   <module>   s$   
"	Ě	