Back to index

python3.2  3.2.2
Public Member Functions
ctypes.test.test_frombuffer.Test Class Reference

List of all members.

Public Member Functions

def test_fom_buffer
def test_fom_buffer_with_offset
def test_from_buffer_copy
def test_fom_buffer_copy_with_offset

Detailed Description

Definition at line 12 of file test_frombuffer.py.


Member Function Documentation

Definition at line 13 of file test_frombuffer.py.

00013 
00014     def test_fom_buffer(self):
00015         a = array.array("i", range(16))
00016         x = (c_int * 16).from_buffer(a)
00017 
00018         y = X.from_buffer(a)
00019         self.assertEqual(y.c_int, a[0])
00020         self.assertFalse(y.init_called)
00021 
00022         self.assertEqual(x[:], a.tolist())
00023 
00024         a[0], a[-1] = 200, -200
00025         self.assertEqual(x[:], a.tolist())
00026 
00027         self.assertTrue(a in x._objects.values())
00028 
00029         self.assertRaises(ValueError,
00030                           c_int.from_buffer, a, -1)
00031 
00032         expected = x[:]
00033         del a; gc.collect(); gc.collect(); gc.collect()
00034         self.assertEqual(x[:], expected)
00035 
00036         self.assertRaises(TypeError,
00037                           (c_char * 16).from_buffer, "a" * 16)

Here is the call graph for this function:

Definition at line 70 of file test_frombuffer.py.

00070 
00071     def test_fom_buffer_copy_with_offset(self):
00072         a = array.array("i", range(16))
00073         x = (c_int * 15).from_buffer_copy(a, sizeof(c_int))
00074 
00075         self.assertEqual(x[:], a.tolist()[1:])
00076         self.assertRaises(ValueError,
00077                           (c_int * 16).from_buffer_copy, a, sizeof(c_int))
00078         self.assertRaises(ValueError,
00079                           (c_int * 1).from_buffer_copy, a, 16 * sizeof(c_int))

Here is the call graph for this function:

Definition at line 38 of file test_frombuffer.py.

00038 
00039     def test_fom_buffer_with_offset(self):
00040         a = array.array("i", range(16))
00041         x = (c_int * 15).from_buffer(a, sizeof(c_int))
00042 
00043         self.assertEqual(x[:], a.tolist()[1:])
00044         self.assertRaises(ValueError, lambda: (c_int * 16).from_buffer(a, sizeof(c_int)))
00045         self.assertRaises(ValueError, lambda: (c_int * 1).from_buffer(a, 16 * sizeof(c_int)))

Here is the call graph for this function:

Definition at line 46 of file test_frombuffer.py.

00046 
00047     def test_from_buffer_copy(self):
00048         a = array.array("i", range(16))
00049         x = (c_int * 16).from_buffer_copy(a)
00050 
00051         y = X.from_buffer_copy(a)
00052         self.assertEqual(y.c_int, a[0])
00053         self.assertFalse(y.init_called)
00054 
00055         self.assertEqual(x[:], list(range(16)))
00056 
00057         a[0], a[-1] = 200, -200
00058         self.assertEqual(x[:], list(range(16)))
00059 
00060         self.assertEqual(x._objects, None)
00061 
00062         self.assertRaises(ValueError,
00063                           c_int.from_buffer, a, -1)
00064 
00065         del a; gc.collect(); gc.collect(); gc.collect()
00066         self.assertEqual(x[:], list(range(16)))
00067 
00068         x = (c_char * 16).from_buffer_copy(b"a" * 16)
00069         self.assertEqual(x[:], b"a" * 16)

Here is the call graph for this function:


The documentation for this class was generated from the following file: