<s> from ctypes import * <EOL> import unittest , sys <EOL> def callback_func ( arg ) : <EOL> <NUM_LIT> / arg <EOL> raise ValueError , arg <EOL> if sys . platform == "<STR_LIT:win32>" : <EOL> class call_function_TestCase ( unittest . TestCase ) : <EOL> def test ( self ) : <EOL> from _ctypes import call_function <EOL> hdll = windll . kernel32 . LoadLibraryA ( "<STR_LIT>" ) <EOL> funcaddr = windll . kernel32 . GetProcAddress ( hdll , "<STR_LIT>" ) <EOL> self . failUnlessEqual ( call_function ( funcaddr , ( None , ) ) , <EOL> windll . kernel32 . GetModuleHandleA ( None ) ) <EOL> class CallbackTracbackTestCase ( unittest . TestCase ) : <EOL> def capture_stderr ( self , func , * args , ** kw ) : <EOL> import StringIO <EOL> old_stderr = sys . stderr <EOL> logger = sys . stderr = StringIO . StringIO ( ) <EOL> try : <EOL> func ( * args , ** kw ) <EOL> finally : <EOL> sys . stderr = old_stderr <EOL> return logger . getvalue ( ) <EOL> def test_ValueError ( self ) : <EOL> cb = CFUNCTYPE ( c_int , c_int ) ( callback_func ) <EOL> out = self . capture_stderr ( cb , <NUM_LIT> ) <EOL> self . failUnlessEqual ( out . splitlines ( ) [ - <NUM_LIT:1> ] , <EOL> "<STR_LIT>" ) <EOL> def test_IntegerDivisionError ( self ) : <EOL> cb = CFUNCTYPE ( c_int , c_int ) ( callback_func ) <EOL> out = self . capture_stderr ( cb , <NUM_LIT:0> ) <EOL> self . failUnlessEqual ( out . splitlines ( ) [ - <NUM_LIT:1> ] [ : <NUM_LIT> ] , <EOL> "<STR_LIT>" ) <EOL> def test_FloatDivisionError ( self ) : <EOL> cb = CFUNCTYPE ( c_int , c_double ) ( callback_func ) <EOL> out = self . capture_stderr ( cb , <NUM_LIT:0.0> ) <EOL> self . failUnlessEqual ( out . splitlines ( ) [ - <NUM_LIT:1> ] [ : <NUM_LIT> ] , <EOL> "<STR_LIT>" ) <EOL> def test_TypeErrorDivisionError ( self ) : <EOL> cb = CFUNCTYPE ( c_int , c_char_p ) ( callback_func ) <EOL> out = self . capture_stderr ( cb , "<STR_LIT>" ) <EOL> self . failUnlessEqual ( out . splitlines ( ) [ - <NUM_LIT:1> ] , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
