<s> """<STR_LIT>""" <EOL> from twisted . trial . unittest import TestCase <EOL> from twisted . python . runtime import platform <EOL> if platform . supportsINotify ( ) : <EOL> from ctypes import c_int , c_uint32 , c_char_p <EOL> from twisted . python import _inotify <EOL> from twisted . python . _inotify import ( <EOL> INotifyError , initializeModule , init , add ) <EOL> else : <EOL> _inotify = None <EOL> class INotifyTests ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> if _inotify is None : <EOL> skip = "<STR_LIT>" <EOL> def test_missingInit ( self ) : <EOL> """<STR_LIT>""" <EOL> class libc : <EOL> def inotify_add_watch ( self ) : <EOL> pass <EOL> def inotify_rm_watch ( self ) : <EOL> pass <EOL> self . assertRaises ( ImportError , initializeModule , libc ( ) ) <EOL> def test_missingAdd ( self ) : <EOL> """<STR_LIT>""" <EOL> class libc : <EOL> def inotify_init ( self ) : <EOL> pass <EOL> def inotify_rm_watch ( self ) : <EOL> pass <EOL> self . assertRaises ( ImportError , initializeModule , libc ( ) ) <EOL> def test_missingRemove ( self ) : <EOL> """<STR_LIT>""" <EOL> class libc : <EOL> def inotify_init ( self ) : <EOL> pass <EOL> def inotify_add_watch ( self ) : <EOL> pass <EOL> self . assertRaises ( ImportError , initializeModule , libc ( ) ) <EOL> def test_setTypes ( self ) : <EOL> """<STR_LIT>""" <EOL> class libc : <EOL> def inotify_init ( self ) : <EOL> pass <EOL> inotify_init = staticmethod ( inotify_init ) <EOL> def inotify_rm_watch ( self ) : <EOL> pass <EOL> inotify_rm_watch = staticmethod ( inotify_rm_watch ) <EOL> def inotify_add_watch ( self ) : <EOL> pass <EOL> inotify_add_watch = staticmethod ( inotify_add_watch ) <EOL> c = libc ( ) <EOL> initializeModule ( c ) <EOL> self . assertEqual ( c . inotify_init . argtypes , [ ] ) <EOL> self . assertEqual ( c . inotify_init . restype , c_int ) <EOL> self . assertEqual ( c . inotify_rm_watch . argtypes , [ c_int , c_int ] ) <EOL> self . assertEqual ( c . inotify_rm_watch . restype , c_int ) <EOL> self . assertEqual ( <EOL> c . inotify_add_watch . argtypes , [ c_int , c_char_p , c_uint32 ] ) <EOL> self . assertEqual ( c . inotify_add_watch . restype , c_int ) <EOL> def test_failedInit ( self ) : <EOL> """<STR_LIT>""" <EOL> class libc : <EOL> def inotify_init ( self ) : <EOL> return - <NUM_LIT:1> <EOL> self . patch ( _inotify , '<STR_LIT>' , libc ( ) ) <EOL> self . assertRaises ( INotifyError , init ) <EOL> def test_failedAddWatch ( self ) : <EOL> """<STR_LIT>""" <EOL> class libc : <EOL> def inotify_add_watch ( self , fd , path , mask ) : <EOL> return - <NUM_LIT:1> <EOL> self . patch ( _inotify , '<STR_LIT>' , libc ( ) ) <EOL> self . assertRaises ( INotifyError , add , <NUM_LIT:3> , '<STR_LIT>' , <NUM_LIT:0> ) </s>
