Back to index

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

List of all members.

Public Member Functions

def test_native_types
def test_endian_types

Detailed Description

Definition at line 20 of file test_pep3118.py.


Member Function Documentation

Definition at line 49 of file test_pep3118.py.

00049 
00050     def test_endian_types(self):
00051         for tp, fmt, shape, itemtp in endian_types:
00052             ob = tp()
00053             v = memoryview(ob)
00054             try:
00055                 self.assertEqual(v.format, fmt)
00056                 if shape is not None:
00057                     self.assertEqual(len(v), shape[0])
00058                 else:
00059                     self.assertEqual(len(v) * sizeof(itemtp), sizeof(ob))
00060                 self.assertEqual(v.itemsize, sizeof(itemtp))
00061                 self.assertEqual(v.shape, shape)
00062                 # ctypes object always have a non-strided memory block
00063                 self.assertEqual(v.strides, None)
00064                 # they are always read/write
00065                 self.assertFalse(v.readonly)
00066 
00067                 if v.shape:
00068                     n = 1
00069                     for dim in v.shape:
00070                         n = n * dim
00071                     self.assertEqual(n, len(v))
00072             except:
00073                 # so that we can see the failing type
00074                 print(tp)
00075                 raise
00076 
00077 # define some structure classes

Here is the call graph for this function:

Definition at line 22 of file test_pep3118.py.

00022 
00023     def test_native_types(self):
00024         for tp, fmt, shape, itemtp in native_types:
00025             ob = tp()
00026             v = memoryview(ob)
00027             try:
00028                 self.assertEqual(normalize(v.format), normalize(fmt))
00029                 if shape is not None:
00030                     self.assertEqual(len(v), shape[0])
00031                 else:
00032                     self.assertEqual(len(v) * sizeof(itemtp), sizeof(ob))
00033                 self.assertEqual(v.itemsize, sizeof(itemtp))
00034                 self.assertEqual(v.shape, shape)
00035                 # ctypes object always have a non-strided memory block
00036                 self.assertEqual(v.strides, None)
00037                 # they are always read/write
00038                 self.assertFalse(v.readonly)
00039 
00040                 if v.shape:
00041                     n = 1
00042                     for dim in v.shape:
00043                         n = n * dim
00044                     self.assertEqual(n * v.itemsize, len(v.tobytes()))
00045             except:
00046                 # so that we can see the failing type
00047                 print(tp)
00048                 raise

Here is the call graph for this function:


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