ó
[³XMc           @   s  d  Z  d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l m	 Z	 d d l
 m Z m Z d d l
 m Z m Z d d l
 m Z m Z m Z d	 d d
 „  ƒ  YZ d e e f d „  ƒ  YZ d e e f d „  ƒ  YZ d e e f d „  ƒ  YZ d e e f d „  ƒ  YZ d S(   sX   
Tests for L{twisted.internet._sigchld}, an alternate, superior SIGCHLD
monitoring API.
iÿÿÿÿN(   t   msg(   t   TestCase(   t   setNonBlocking(   t   installHandlert   isDefaultHandler(   t   _extInstallHandlert   _extIsDefaultHandler(   t   _installHandlerUsingSetWakeupt   _installHandlerUsingSignalt   _isDefaultHandlert   SIGCHLDTestsMixinc           B   s€   e  Z d  Z e e d d ƒ d k r- d Z n  d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d	 „  Z d
 „  Z d „  Z RS(   s  
    Mixin for L{TestCase} subclasses which defines several tests for
    I{installHandler} and I{isDefaultHandler}.  Subclasses are expected to
    define C{self.installHandler} and C{self.isDefaultHandler} to invoke the
    implementation to be tested.
    t   SIGCHLDs   Platform does not have SIGCHLDc         C   s   t  ƒ  ‚ d S(   sº   
        Override in a subclass to install a SIGCHLD handler which writes a byte
        to the given file descriptor.  Return the previously registered file
        descriptor.
        N(   t   NotImplementedError(   t   selft   fd(    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_sigchld.pyR      s    c         C   s   t  ƒ  ‚ d S(   sŸ   
        Override in a subclass to determine if the current SIGCHLD handler is
        SIG_DFL or not.  Return True if it is SIG_DFL, False otherwise.
        N(   R   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_sigchld.pyR   (   s    c         C   sV   t  j ƒ  \ } } |  j t  j | ƒ |  j t  j | ƒ t | ƒ t | ƒ | | f S(   sk   
        Create a non-blocking pipe which will be closed after the currently
        running test.
        (   t   ost   pipet
   addCleanupt   closeR   (   R   t   readt   write(    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_sigchld.pyR   0   s    

c         C   s©   t  j t  j ƒ } | t  j k rC | |  _ t  j  t  j t  j ƒ n	 d |  _ |  j d ƒ |  _ |  j d k	 r¥ |  j d k r¥ t d |  j |  j f ƒ t	 d ƒ ‚ n  d S(   s   
        Save the current SIGCHLD handler as reported by L{signal.signal} and
        the current file descriptor registered with L{installHandler}.
        iÿÿÿÿs   SIGCHLD setup issue: %r %rs,   You used some signal APIs wrong!  Try again.N(
   t   signalt	   getsignalR   t   SIG_DFLt   signalModuleHandlert   NoneR   t   oldFDR    t   RuntimeError(   R   t   handler(    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_sigchld.pyt   setUp=   s    		c         C   sq   |  j  d ƒ t j t j t j ƒ |  j d k	 rK t j t j |  j ƒ n" |  j d k rm |  j  |  j ƒ n  d S(   sM   
        Restore whatever signal handler was present when setUp ran.
        iÿÿÿÿN(   R   R   R   R   R   R   R   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_sigchld.pyt   tearDownP   s    c         C   s’   |  j  |  j ƒ  ƒ t j t j t j ƒ |  j |  j ƒ  ƒ t j t j t j ƒ |  j  |  j ƒ  ƒ t j t j d „  ƒ |  j |  j ƒ  ƒ d S(   sn   
        L{isDefaultHandler} returns true if the SIGCHLD handler is SIG_DFL,
        false otherwise.
        c          W   s   d  S(   N(   R   (   t   args(    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_sigchld.pyt   <lambda>i   s    N(   t
   assertTrueR   R   R   t   SIG_IGNt   assertFalseR   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_sigchld.pyt   test_isDefaultHandler_   s    c         C   s>   |  j  ƒ  \ } } |  j | ƒ } |  j |  j | ƒ | ƒ d S(   sV   
        L{installHandler} returns the previously registered file descriptor.
        N(   R   R   t   assertEqual(   R   R   R   R   (    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_sigchld.pyt   test_returnOldFDm   s    c         C   si   |  j  ƒ  \ } } |  j |  j ƒ  ƒ |  j | ƒ |  j |  j ƒ  ƒ |  j d ƒ |  j |  j ƒ  ƒ d S(   sO   
        C{installHandler(-1)} removes the SIGCHLD handler completely.
        iÿÿÿÿN(   R   R!   R   R   R#   (   R   R   R   (    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_sigchld.pyt   test_uninstallHandlerv   s    c         C   s   |  j  ƒ  \ } } |  j | ƒ |  j t t j | d ƒ } |  j | j t j ƒ t j	 t j
 ƒ  t j ƒ |  j t t j | d ƒ ƒ d ƒ d S(   sŒ   
        The file descriptor passed to L{installHandler} has a byte written to
        it when SIGCHLD is delivered to the process.
        i   i   N(   R   R   t   assertRaisest   OSErrorR   R   R%   t   errnot   EAGAINt   killt   getpidR   R   t   len(   R   R   R   t   exc(    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_sigchld.pyt   test_installHandler‚   s    N(   t   __name__t
   __module__t   __doc__t   getattrR   R   t   skipR   R   R   R   R   R$   R&   R'   R0   (    (    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_sigchld.pyR
      s   											t   DefaultSIGCHLDTestsc           B   s&   e  Z d  Z e e ƒ Z e e ƒ Z RS(   ss   
    Tests for whatever implementation is selected for the L{installHandler}
    and L{isDefaultHandler} APIs.
    (   R1   R2   R3   t   staticmethodR   R   (    (    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_sigchld.pyR6   “   s   t   ExtensionSIGCHLDTestsc           B   sD   e  Z d  Z y d d l Z Wn e k
 r5 d Z n Xe Z e	 Z
 RS(   s~   
    Tests for the L{twisted.internet._sigchld} implementation of the
    L{installHandler} and L{isDefaultHandler} APIs.
    iÿÿÿÿNs*   twisted.internet._sigchld is not available(   R1   R2   R3   t   twisted.internet._sigchldt   twistedt   ImportErrorR5   R   R   R   R   (    (    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_sigchld.pyR8      s   
t   SetWakeupSIGCHLDTestsc           B   s_   e  Z d  Z e e d d ƒ d k s< e e d d ƒ d k rE d Z n  e e ƒ Z	 e e
 ƒ Z RS(   sy   
    Tests for the L{signal.set_wakeup_fd} implementation of the
    L{installHandler} and L{isDefaultHandler} APIs.
    t   set_wakeup_fdt   siginterrupts%   signal.set_wakeup_fd is not availableN(   R1   R2   R3   R4   R   R   R5   R7   R   R   R	   R   (    (    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_sigchld.pyR<   ¬   s   	t   PlainSignalModuleSIGCHLDTestsc           B   s&   e  Z d  Z e e ƒ Z e e ƒ Z RS(   sr   
    Tests for the L{signal.signal} implementation of the L{installHandler}
    and L{isDefaultHandler} APIs.
    (   R1   R2   R3   R7   R   R   R	   R   (    (    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_sigchld.pyR?   ¼   s   (    (   R3   R   R   R*   t   twisted.python.logR    t   twisted.trial.unittestR   t   twisted.internet.fdescR   t   twisted.internet._signalsR   R   R   R   R   R   R	   R
   R6   R8   R<   R?   (    (    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_sigchld.pyt   <module>   s   $
