home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- from ctypes import *
- import unittest
- import sys
-
- def callback_func(arg):
- 42 / arg
- raise ValueError(arg)
-
- if sys.platform == 'win32':
-
- class call_function_TestCase(unittest.TestCase):
-
- def test(self):
- call_function = call_function
- import _ctypes
- windll.kernel32.LoadLibraryA.restype = c_void_p
- windll.kernel32.GetProcAddress.argtypes = (c_void_p, c_char_p)
- windll.kernel32.GetProcAddress.restype = c_void_p
- hdll = windll.kernel32.LoadLibraryA('kernel32')
- funcaddr = windll.kernel32.GetProcAddress(hdll, 'GetModuleHandleA')
- self.failUnlessEqual(call_function(funcaddr, (None,)), windll.kernel32.GetModuleHandleA(None))
-
-
-
-
- class CallbackTracbackTestCase(unittest.TestCase):
-
- def capture_stderr(self, func, *args, **kw):
- import StringIO
- old_stderr = sys.stderr
- logger = sys.stderr = StringIO.StringIO()
-
- try:
- func(*args, **kw)
- finally:
- sys.stderr = old_stderr
-
- return logger.getvalue()
-
-
- def test_ValueError(self):
- cb = CFUNCTYPE(c_int, c_int)(callback_func)
- out = self.capture_stderr(cb, 42)
- self.failUnlessEqual(out.splitlines()[-1], 'ValueError: 42')
-
-
- def test_IntegerDivisionError(self):
- cb = CFUNCTYPE(c_int, c_int)(callback_func)
- out = self.capture_stderr(cb, 0)
- self.failUnlessEqual(out.splitlines()[-1][:19], 'ZeroDivisionError: ')
-
-
- def test_FloatDivisionError(self):
- cb = CFUNCTYPE(c_int, c_double)(callback_func)
- out = self.capture_stderr(cb, 0)
- self.failUnlessEqual(out.splitlines()[-1][:19], 'ZeroDivisionError: ')
-
-
- def test_TypeErrorDivisionError(self):
- cb = CFUNCTYPE(c_int, c_char_p)(callback_func)
- out = self.capture_stderr(cb, 'spam')
- self.failUnlessEqual(out.splitlines()[-1], "TypeError: unsupported operand type(s) for /: 'int' and 'str'")
-
-
- if __name__ == '__main__':
- unittest.main()
-
-