B
    u9aÉ
  ã               @   sf   d dl Z d dlZd dlZd dlZd dlZd dlZG dd„ deƒZG dd„ dejƒZ	e
dkrbe ¡  dS )é    Nc               @   s   e Zd ZdS )ÚSIGUSR1ExceptionN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú+/usr/lib/python3.7/signalinterproctester.pyr   	   s   r   c               @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚInterProcessSignalTestsc             C   s   ddddœ| _ d S )Nr   )ÚSIGHUPÚSIGUSR1ÚSIGALRM)Úgot_signals)Úselfr   r   r   ÚsetUp   s    zInterProcessSignalTests.setUpc             C   s   | j d  d7  < d S )Nr	   é   )r   )r   ÚsignumÚframer   r   r   Úsighup_handler   s    z&InterProcessSignalTests.sighup_handlerc             C   s   | j d  d7  < t‚d S )Nr
   r   )r   r   )r   r   r   r   r   r   Úsigusr1_handler   s    z'InterProcessSignalTests.sigusr1_handlerc             C   s^   |d k	r|  ¡  d}t ¡ | }x&t ¡ |k rF| j| r<d S t ¡  q"W |  d||f ¡ d S )Ng      $@z'signal %s not received after %s seconds)ÚwaitÚtimeZ	monotonicr   ÚsignalÚpauseZfail)r   ÚchildÚsignameZtimeoutZdeadliner   r   r   Úwait_signal   s    
z#InterProcessSignalTests.wait_signalc             C   s$   d||f }t jdd|g}t |¡S )Nz)import os, signal; os.kill(%s, signal.%s)z-Iz-c)ÚsysÚ
executableÚ
subprocessÚPopen)r   Úpidr   ÚcodeÚargsr   r   r   Úsubprocess_send_signal)   s    z.InterProcessSignalTests.subprocess_send_signalc          
   C   sN  t   t j| j¡ t   t j| j¡ t   t jt j¡ t   t jt j¡ t	t
 ¡ ƒ}|  |d¡}|  |d¡ W d Q R X |  | jddddœ¡ |  t¡* |  |d¡}|  |d¡ W d Q R X W d Q R X |  | jddddœ¡ |  |d¡}| ¡  W d Q R X zF|  t¡ t  d¡ |  d d¡ W d Q R X |  | jddddœ¡ W d t  d¡ X d S )Nr	   r   r   )r	   r
   r   r
   ÚSIGUSR2r   )r   r	   r   r
   r   r#   ÚSIG_IGNr   Údefault_int_handlerÚstrÚosÚgetpidr"   r   ZassertEqualr   ZassertRaisesr   r   ÚKeyboardInterruptÚalarm)r   r   r   r   r   r   Útest_interprocess_signal.   s.    
 

z0InterProcessSignalTests.test_interprocess_signalN)	r   r   r   r   r   r   r   r"   r+   r   r   r   r   r      s   r   Ú__main__)r'   r   r   r   r   ZunittestÚ	Exceptionr   ZTestCaser   r   Úmainr   r   r   r   Ú<module>   s   E