<s> """<STR_LIT>""" <EOL> from __future__ import division , absolute_import <EOL> import os , signal , errno <EOL> from twisted . python . runtime import platformType <EOL> from twisted . python . log import msg <EOL> from twisted . trial . unittest import SynchronousTestCase <EOL> if platformType == "<STR_LIT>" : <EOL> from twisted . internet . fdesc import setNonBlocking <EOL> from twisted . internet . _signals import installHandler , isDefaultHandler <EOL> else : <EOL> skip = "<STR_LIT>" <EOL> class SetWakeupSIGCHLDTests ( SynchronousTestCase ) : <EOL> """<STR_LIT>""" <EOL> def pipe ( self ) : <EOL> """<STR_LIT>""" <EOL> read , write = os . pipe ( ) <EOL> self . addCleanup ( os . close , read ) <EOL> self . addCleanup ( os . close , write ) <EOL> setNonBlocking ( read ) <EOL> setNonBlocking ( write ) <EOL> return read , write <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> handler = signal . getsignal ( signal . SIGCHLD ) <EOL> if handler != signal . SIG_DFL : <EOL> self . signalModuleHandler = handler <EOL> signal . signal ( signal . SIGCHLD , signal . SIG_DFL ) <EOL> else : <EOL> self . signalModuleHandler = None <EOL> self . oldFD = installHandler ( - <NUM_LIT:1> ) <EOL> if self . signalModuleHandler is not None and self . oldFD != - <NUM_LIT:1> : <EOL> msg ( "<STR_LIT>" <EOL> % ( self . signalModuleHandler , self . oldFD ) ) <EOL> def tearDown ( self ) : <EOL> """<STR_LIT>""" <EOL> installHandler ( - <NUM_LIT:1> ) <EOL> signal . signal ( signal . SIGCHLD , signal . SIG_DFL ) <EOL> if self . signalModuleHandler is not None : <EOL> signal . signal ( signal . SIGCHLD , self . signalModuleHandler ) <EOL> elif self . oldFD != - <NUM_LIT:1> : <EOL> installHandler ( self . oldFD ) <EOL> def test_isDefaultHandler ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertTrue ( isDefaultHandler ( ) ) <EOL> signal . signal ( signal . SIGCHLD , signal . SIG_IGN ) <EOL> self . assertFalse ( isDefaultHandler ( ) ) <EOL> signal . signal ( signal . SIGCHLD , signal . SIG_DFL ) <EOL> self . assertTrue ( isDefaultHandler ( ) ) <EOL> signal . signal ( signal . SIGCHLD , lambda * args : None ) <EOL> self . assertFalse ( isDefaultHandler ( ) ) <EOL> def test_returnOldFD ( self ) : <EOL> """<STR_LIT>""" <EOL> read , write = self . pipe ( ) <EOL> oldFD = installHandler ( write ) <EOL> self . assertEqual ( installHandler ( oldFD ) , write ) <EOL> def test_uninstallHandler ( self ) : <EOL> """<STR_LIT>""" <EOL> read , write = self . pipe ( ) <EOL> self . assertTrue ( isDefaultHandler ( ) ) <EOL> installHandler ( write ) <EOL> self . assertFalse ( isDefaultHandler ( ) ) <EOL> installHandler ( - <NUM_LIT:1> ) <EOL> self . assertTrue ( isDefaultHandler ( ) ) <EOL> def test_installHandler ( self ) : <EOL> """<STR_LIT>""" <EOL> read , write = self . pipe ( ) <EOL> installHandler ( write ) <EOL> exc = self . assertRaises ( OSError , os . read , read , <NUM_LIT:1> ) <EOL> self . assertEqual ( exc . errno , errno . EAGAIN ) <EOL> os . kill ( os . getpid ( ) , signal . SIGCHLD ) <EOL> self . assertEqual ( len ( os . read ( read , <NUM_LIT:5> ) ) , <NUM_LIT:1> ) </s>
