Back to index

python3.2  3.2.2
Classes | Functions | Variables
ctypes.test.test_callbacks Namespace Reference

Classes

class  Callbacks
class  StdcallCallbacks
class  SampleCallbacksTestCase

Functions

def callback
 def tearDown(self): import gc gc.collect()
def check_type
def test_byte
def test_ubyte
def test_short
def test_ushort
def test_int
def test_uint
def test_long
def test_ulong
def test_longlong
def test_ulonglong
def test_float
def test_double
def test_longdouble
def test_char
def test_pyobject
 def test_char_p(self): self.check_type(c_char_p, "abc") self.check_type(c_char_p, "def")
def test_unsupported_restype_1
def test_unsupported_restype_2
def test_issue_7959

Variables

 got_args
 v

Function Documentation

def ctypes.test.test_callbacks.callback (   self,
  args 
)

def tearDown(self): import gc gc.collect()

Definition at line 12 of file test_callbacks.py.

00012 
00013     def callback(self, *args):
00014         self.got_args = args
00015         return args[-1]

Here is the caller graph for this function:

def ctypes.test.test_callbacks.check_type (   self,
  typ,
  arg 
)

Definition at line 16 of file test_callbacks.py.

00016 
00017     def check_type(self, typ, arg):
00018         PROTO = self.functype.__func__(typ, typ)
00019         result = PROTO(self.callback)(arg)
00020         if typ == c_float:
00021             self.assertAlmostEqual(result, arg, places=5)
00022         else:
00023             self.assertEqual(self.got_args, (arg,))
00024             self.assertEqual(result, arg)
00025 
00026         PROTO = self.functype.__func__(typ, c_byte, typ)
00027         result = PROTO(self.callback)(-3, arg)
00028         if typ == c_float:
00029             self.assertAlmostEqual(result, arg, places=5)
00030         else:
00031             self.assertEqual(self.got_args, (-3, arg))
00032             self.assertEqual(result, arg)

Definition at line 35 of file test_callbacks.py.

00035 
00036     def test_byte(self):
00037         self.check_type(c_byte, 42)
00038         self.check_type(c_byte, -42)

Definition at line 84 of file test_callbacks.py.

00084 
00085     def test_char(self):
00086         self.check_type(c_char, b"x")
00087         self.check_type(c_char, b"a")

Definition at line 76 of file test_callbacks.py.

00076 
00077     def test_double(self):
00078         self.check_type(c_double, 3.14)
00079         self.check_type(c_double, -3.14)

Definition at line 70 of file test_callbacks.py.

00070 
00071     def test_float(self):
00072         # only almost equal: double -> float -> double
00073         import math
00074         self.check_type(c_float, math.e)
00075         self.check_type(c_float, -math.e)

Definition at line 49 of file test_callbacks.py.

00049 
00050     def test_int(self):
00051         self.check_type(c_int, 42)
00052         self.check_type(c_int, -42)

Definition at line 121 of file test_callbacks.py.

00121 
00122     def test_issue_7959(self):
00123         proto = self.functype.__func__(None)
00124 
00125         class X(object):
00126             def func(self): pass
00127             def __init__(self):
00128                 self.v = proto(self.func)
00129 
00130         import gc
00131         for i in range(32):
00132             X()
00133         gc.collect()
00134         live = [x for x in gc.get_objects()
00135                 if isinstance(x, X)]
00136         self.assertEqual(len(live), 0)
00137 
try:

Here is the call graph for this function:

Definition at line 56 of file test_callbacks.py.

00056 
00057     def test_long(self):
00058         self.check_type(c_long, 42)
00059         self.check_type(c_long, -42)

Definition at line 80 of file test_callbacks.py.

00080 
00081     def test_longdouble(self):
00082         self.check_type(c_longdouble, 3.14)
00083         self.check_type(c_longdouble, -3.14)

Definition at line 63 of file test_callbacks.py.

00063 
00064     def test_longlong(self):
00065         self.check_type(c_longlong, 42)
00066         self.check_type(c_longlong, -42)

def test_char_p(self): self.check_type(c_char_p, "abc") self.check_type(c_char_p, "def")

Definition at line 95 of file test_callbacks.py.

00095 
00096     def test_pyobject(self):
00097         o = ()
00098         from sys import getrefcount as grc
00099         for o in (), [], object():
00100             initial = grc(o)
00101             # This call leaks a reference to 'o'...
00102             self.check_type(py_object, o)
00103             before = grc(o)
00104             # ...but this call doesn't leak any more.  Where is the refcount?
00105             self.check_type(py_object, o)
00106             after = grc(o)
00107             self.assertEqual((after, o), (before, o))

Definition at line 42 of file test_callbacks.py.

00042 
00043     def test_short(self):
00044         self.check_type(c_short, 42)
00045         self.check_type(c_short, -42)

Definition at line 39 of file test_callbacks.py.

00039 
00040     def test_ubyte(self):
00041         self.check_type(c_ubyte, 42)

Definition at line 53 of file test_callbacks.py.

00053 
00054     def test_uint(self):
00055         self.check_type(c_uint, 42)

Definition at line 60 of file test_callbacks.py.

00060 
00061     def test_ulong(self):
00062         self.check_type(c_ulong, 42)

Definition at line 67 of file test_callbacks.py.

00067 
00068     def test_ulonglong(self):
00069         self.check_type(c_ulonglong, 42)

Definition at line 108 of file test_callbacks.py.

00108 
00109     def test_unsupported_restype_1(self):
00110         # Only "fundamental" result types are supported for callback
00111         # functions, the type must have a non-NULL stgdict->setfunc.
00112         # POINTER(c_double), for example, is not supported.
00113 
00114         prototype = self.functype.__func__(POINTER(c_double))
00115         # The type is checked when the prototype is called
00116         self.assertRaises(TypeError, prototype, lambda: None)

Definition at line 117 of file test_callbacks.py.

00117 
00118     def test_unsupported_restype_2(self):
00119         prototype = self.functype.__func__(object)
00120         self.assertRaises(TypeError, prototype, lambda: None)

Definition at line 46 of file test_callbacks.py.

00046 
00047     def test_ushort(self):
00048         self.check_type(c_ushort, 42)


Variable Documentation

Definition at line 13 of file test_callbacks.py.

Definition at line 127 of file test_callbacks.py.