B
    u9a
  ã               @   sx   d dl Z d dlZd dlZd dlZd dlmZmZ eedƒsDe d¡‚dd„ Z	G dd„ dej
ƒZd	d
„ Zedkrteƒ  dS )é    N)Úrun_unittestÚcpython_onlyÚdevpollz$test works only on Solaris OS familyc             C   s,   g }x"| D ]\}}||@ r
|  |¡ q
W |S )N)Úappend)ÚreadyÚflagÚmatchÚfdÚmode© r   ú"/usr/lib/python3.7/test_devpoll.pyÚfind_ready_matching   s
    r   c               @   s@   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zedd„ ƒZ	dS )ÚDevPollTestsc             C   sŽ  t  ¡ }d}d}t|ƒ}g }g }i }i }xft|ƒD ]Z}	t ¡ \}
}| |
¡ | |
t j¡ | |t j	¡ | 
|
¡ | 
|¡ |||
< |
||< q2W g }xâ|rv| ¡ }t|t j	ƒ}|s¾|  d¡ t |¡}t ||¡ | ¡ }t|t jƒ}|sö|  d¡ |  || g|¡ |d }
t |
|¡}|  t|ƒ|¡ | 
|¡ t ||
 ¡ t |
¡ | ||
 ¡ | |
¡ | ||
 ¡ q–W |  ||g| ¡ d S )Né   s    This is a test.zno pipes ready for writingzno pipes ready for readingr   )Úselectr   ÚlenÚrangeÚosÚpipeÚregisterÚmodifyÚPOLLINZPOLLOUTr   Úpollr   ZfailÚrandomÚchoiceÚwriteÚassertEqualÚreadÚcloseÚ
unregisterÚremove)ÚselfÚpZ	NUM_PIPESZMSGZMSG_LENZreadersZwritersZr2wZw2rÚiZrdZwrZbufsr   Zready_writersZready_readersÚbufr   r   r   Útest_devpoll1   sP    






 

zDevPollTests.test_devpoll1c             C   sª   t  ¡ }t ¡ \}}| |¡ | d¡ |  t|jd¡ |  t|jd¡ |  t|jd¡ | d¡ | d¡ | d¡ |  t|jd¡ |  t|jd	¡ |  t|jd
¡ d S )Néÿÿÿÿéþÿÿÿi   €lûÿÿÿ         r   é   i   @l        l            l            )r   r   r   r   r   r   ÚassertRaisesÚOverflowError)r!   ÚpollsterÚwÚrr   r   r   Útest_timeout_overflowJ   s    




z"DevPollTests.test_timeout_overflowc             C   s¸   t tdƒ}|  |j¡ | ¡ }t ¡ }|  | ¡ t¡ |  	|j
¡ | ¡  |  |j
¡ |  t|j¡ | ¡  |  t|j|tj¡ |  t|j¡ |  t|j||tj¡ |  t|j|¡ d S )NÚrb)ÚopenÚ__file__Ú
addCleanupr   Úfilenor   r   ZassertIsInstanceÚintZassertFalseÚclosedZ
assertTruer)   Ú
ValueErrorr   r   r   r   r   )r!   Z	open_filer	   r   r   r   r   Ú
test_close[   s    
zDevPollTests.test_closec             C   s.   t  ¡ }|  |j¡ |  t | ¡ ¡d¡ d S )NF)r   r   r2   r   r   r   Úget_inheritabler3   )r!   r   r   r   r   Útest_fd_non_inheritables   s    z$DevPollTests.test_fd_non_inheritablec             C   sj   t  ¡ }t ¡ \}}| |¡ |  t|jdd¡ |  t|jdd¡ |  t|jdd¡ |  t|jdd¡ d S )Nr   r&   l            r(   )r   r   r   r   r   r)   r*   r   )r!   r+   r,   r-   r   r   r   Útest_events_mask_overflowx   s    
z&DevPollTests.test_events_mask_overflowc             C   sZ   ddl m} t ¡ }t ¡ \}}| |¡ |  t|jd|d ¡ |  t|j	d|d ¡ d S )Nr   )Ú	USHRT_MAXr(   )
Z	_testcapir;   r   r   r   r   r   r)   r*   r   )r!   r;   r+   r,   r-   r   r   r   Ú"test_events_mask_overflow_c_limits‚   s    
z/DevPollTests.test_events_mask_overflow_c_limitsN)
Ú__name__Ú
__module__Ú__qualname__r%   r.   r7   r9   r:   r   r<   r   r   r   r   r      s   2
r   c               C   s   t tƒ d S )N)r   r   r   r   r   r   Ú	test_main   s    r@   Ú__main__)r   r   r   ZunittestZtest.supportr   r   ÚhasattrZSkipTestr   ZTestCaser   r@   r=   r   r   r   r   Ú<module>   s   

w