home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_382 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  3.0 KB  |  71 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from ctypes import *
  5. import unittest
  6. import sys
  7.  
  8. def callback_func(arg):
  9.     42 / arg
  10.     raise ValueError(arg)
  11.  
  12. if sys.platform == 'win32':
  13.     
  14.     class call_function_TestCase(unittest.TestCase):
  15.         
  16.         def test(self):
  17.             call_function = call_function
  18.             import _ctypes
  19.             windll.kernel32.LoadLibraryA.restype = c_void_p
  20.             windll.kernel32.GetProcAddress.argtypes = (c_void_p, c_char_p)
  21.             windll.kernel32.GetProcAddress.restype = c_void_p
  22.             hdll = windll.kernel32.LoadLibraryA('kernel32')
  23.             funcaddr = windll.kernel32.GetProcAddress(hdll, 'GetModuleHandleA')
  24.             self.failUnlessEqual(call_function(funcaddr, (None,)), windll.kernel32.GetModuleHandleA(None))
  25.  
  26.  
  27.  
  28.  
  29. class CallbackTracbackTestCase(unittest.TestCase):
  30.     
  31.     def capture_stderr(self, func, *args, **kw):
  32.         import StringIO
  33.         old_stderr = sys.stderr
  34.         logger = sys.stderr = StringIO.StringIO()
  35.         
  36.         try:
  37.             func(*args, **kw)
  38.         finally:
  39.             sys.stderr = old_stderr
  40.  
  41.         return logger.getvalue()
  42.  
  43.     
  44.     def test_ValueError(self):
  45.         cb = CFUNCTYPE(c_int, c_int)(callback_func)
  46.         out = self.capture_stderr(cb, 42)
  47.         self.failUnlessEqual(out.splitlines()[-1], 'ValueError: 42')
  48.  
  49.     
  50.     def test_IntegerDivisionError(self):
  51.         cb = CFUNCTYPE(c_int, c_int)(callback_func)
  52.         out = self.capture_stderr(cb, 0)
  53.         self.failUnlessEqual(out.splitlines()[-1][:19], 'ZeroDivisionError: ')
  54.  
  55.     
  56.     def test_FloatDivisionError(self):
  57.         cb = CFUNCTYPE(c_int, c_double)(callback_func)
  58.         out = self.capture_stderr(cb, 0)
  59.         self.failUnlessEqual(out.splitlines()[-1][:19], 'ZeroDivisionError: ')
  60.  
  61.     
  62.     def test_TypeErrorDivisionError(self):
  63.         cb = CFUNCTYPE(c_int, c_char_p)(callback_func)
  64.         out = self.capture_stderr(cb, 'spam')
  65.         self.failUnlessEqual(out.splitlines()[-1], "TypeError: unsupported operand type(s) for /: 'int' and 'str'")
  66.  
  67.  
  68. if __name__ == '__main__':
  69.     unittest.main()
  70.  
  71.