o
    ¼>h  ã                   @  s~   d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	 edkr3ddl
mZmZ ddlmZ nd	ZG d
d„ de	ƒZdS )zX
Tests for L{twisted.internet._sigchld}, an alternate, superior SIGCHLD
monitoring API.
é    )ÚannotationsN)ÚplatformType)ÚSynchronousTestCaseÚposix)ÚinstallHandlerÚisDefaultHandler)ÚsetNonBlockingz,These tests can only run on POSIX platforms.c                   @  sV   e Zd ZdZddd„Zddd„Zdd	d
„Zddd„Zddd„Zddd„Z	ddd„Z
dS )ÚSetWakeupSIGCHLDTestszy
    Tests for the L{signal.set_wakeup_fd} implementation of the
    L{installHandler} and L{isDefaultHandler} APIs.
    Úreturnútuple[int, int]c                 C  s@   t  ¡ \}}|  t j|¡ |  t j|¡ t|ƒ t|ƒ ||fS )zk
        Create a non-blocking pipe which will be closed after the currently
        running test.
        )ÚosÚpipeÚ
addCleanupÚcloser   ©ÚselfÚreadÚwrite© r   ú‚/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/twisted/internet/test/test_sigchld.pyr      s   zSetWakeupSIGCHLDTests.pipeÚNonec                 C  s   t  t j¡| _tdƒ| _dS )z
        Save the current SIGCHLD handler as reported by L{signal.signal} and
        the current file descriptor registered with L{installHandler}.
        éÿÿÿÿN)ÚsignalÚ	getsignalÚSIGCHLDÚsignalModuleHandlerr   ÚoldFD©r   r   r   r   ÚsetUp*   s   zSetWakeupSIGCHLDTests.setUpc                 C  s   t | jƒ t tj| j¡ dS )zM
        Restore whatever signal handler was present when setUp ran.
        N)r   r   r   r   r   r   r   r   r   ÚtearDown2   s   
zSetWakeupSIGCHLDTests.tearDownc                 C  sf   |   tƒ ¡ t tjtj¡ |  tƒ ¡ t tjtj¡ |   tƒ ¡ t tjdd„ ¡ |  tƒ ¡ dS )zn
        L{isDefaultHandler} returns true if the SIGCHLD handler is SIG_DFL,
        false otherwise.
        c                  W  s   d S )Nr   )Úargsr   r   r   Ú<lambda>D   s    z=SetWakeupSIGCHLDTests.test_isDefaultHandler.<locals>.<lambda>N)Ú
assertTruer   r   r   ÚSIG_IGNÚassertFalseÚSIG_DFLr   r   r   r   Útest_isDefaultHandler:   s   z+SetWakeupSIGCHLDTests.test_isDefaultHandlerc                 C  s(   |   ¡ \}}t|ƒ}|  t|ƒ|¡ dS )zV
        L{installHandler} returns the previously registered file descriptor.
        N)r   r   ÚassertEqual)r   r   r   r   r   r   r   Útest_returnOldFDG   s   z&SetWakeupSIGCHLDTests.test_returnOldFDc                 C  sD   |   ¡ \}}|  tƒ ¡ t|ƒ |  tƒ ¡ tdƒ |  tƒ ¡ dS )zO
        C{installHandler(-1)} removes the SIGCHLD handler completely.
        r   N)r   r"   r   r   r$   r   r   r   r   Útest_uninstallHandlerO   s   z+SetWakeupSIGCHLDTests.test_uninstallHandlerc                 C  sd   |   ¡ \}}t|ƒ |  ttj|d¡}|  |jtj¡ t 	t 
¡ tj¡ |  tt |d¡ƒd¡ dS )zŒ
        The file descriptor passed to L{installHandler} has a byte written to
        it when SIGCHLD is delivered to the process.
        é   é   N)r   r   ÚassertRaisesÚOSErrorr   r   r'   ÚerrnoÚEAGAINÚkillÚgetpidr   r   Úlen)r   r   r   Úexcr   r   r   Útest_installHandlerZ   s   z)SetWakeupSIGCHLDTests.test_installHandlerN)r
   r   )r
   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r&   r(   r)   r4   r   r   r   r   r	      s    





r	   )r8   Ú
__future__r   r.   r   r   Útwisted.python.runtimer   Útwisted.trial.unittestr   Útwisted.internet._signalsr   r   Útwisted.internet.fdescr   Úskipr	   r   r   r   r   Ú<module>   s   