Back to index

python3.2  3.2.2
Public Member Functions
ctypes.test.test_values.ValuesTestCase.Win_ValuesTestCase Class Reference

List of all members.

Public Member Functions

def test_optimizeflag
def test_frozentable
def test_undefined

Detailed Description

This test only works when python itself is a dll/shared library

Definition at line 30 of file test_values.py.


Member Function Documentation

Definition at line 49 of file test_values.py.

00049 
00050         def test_frozentable(self):
00051             # Python exports a PyImport_FrozenModules symbol. This is a
00052             # pointer to an array of struct _frozen entries.  The end of the
00053             # array is marked by an entry containing a NULL name and zero
00054             # size.
00055 
00056             # In standard Python, this table contains a __hello__
00057             # module, and a __phello__ package containing a spam
00058             # module.
00059             class struct_frozen(Structure):
00060                 _fields_ = [("name", c_char_p),
00061                             ("code", POINTER(c_ubyte)),
00062                             ("size", c_int)]
00063             FrozenTable = POINTER(struct_frozen)
00064 
00065             ft = FrozenTable.in_dll(pydll, "PyImport_FrozenModules")
00066             # ft is a pointer to the struct_frozen entries:
00067             items = []
00068             for entry in ft:
00069                 # This is dangerous. We *can* iterate over a pointer, but
00070                 # the loop will not terminate (maybe with an access
00071                 # violation;-) because the pointer instance has no size.
00072                 if entry.name is None:
00073                     break
00074                 items.append((entry.name, entry.size))
00075             import sys
00076             if sys.version_info[:2] >= (2, 3):
00077                 expected = [("__hello__", 104), ("__phello__", -104), ("__phello__.spam", 104)]
00078             else:
00079                 expected = [("__hello__", 100), ("__phello__", -100), ("__phello__.spam", 100)]
00080             self.assertEqual(items, expected)
00081 
00082             from ctypes import _pointer_type_cache
00083             del _pointer_type_cache[struct_frozen]

Here is the call graph for this function:

Definition at line 33 of file test_values.py.

00033 
00034         def test_optimizeflag(self):
00035             # This test accesses the Py_OptimizeFlag intger, which is
00036             # exported by the Python dll.
00037 
00038             # It's value is set depending on the -O and -OO flags:
00039             # if not given, it is 0 and __debug__ is 1.
00040             # If -O is given, the flag is 1, for -OO it is 2.
00041             # docstrings are also removed in the latter case.
00042             opt = c_int.in_dll(pydll, "Py_OptimizeFlag").value
00043             if __debug__:
00044                 self.assertEqual(opt, 0)
00045             elif ValuesTestCase.__doc__ is not None:
00046                 self.assertEqual(opt, 1)
00047             else:
00048                 self.assertEqual(opt, 2)

Here is the call graph for this function:

Definition at line 84 of file test_values.py.

00084 
00085         def test_undefined(self):
00086             self.assertRaises(ValueError, c_int.in_dll, pydll, "Undefined_Symbol")

Here is the call graph for this function:


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