Back to index

python3.2  3.2.2
Public Member Functions
ctypes.test.test_python_api.PythonAPITestCase Class Reference

List of all members.

Public Member Functions

def test_PyBytes_FromStringAndSize
def test_PyString_FromString
def test_PyLong_Long
def test_PyObj_FromPtr
def test_PyOS_snprintf
def test_pyobject_repr

Detailed Description

Definition at line 18 of file test_python_api.py.


Member Function Documentation

Definition at line 20 of file test_python_api.py.

00020 
00021     def test_PyBytes_FromStringAndSize(self):
00022         PyBytes_FromStringAndSize = pythonapi.PyBytes_FromStringAndSize
00023 
00024         PyBytes_FromStringAndSize.restype = py_object
00025         PyBytes_FromStringAndSize.argtypes = c_char_p, c_py_ssize_t
00026 
00027         self.assertEqual(PyBytes_FromStringAndSize(b"abcdefghi", 3), b"abc")

Here is the call graph for this function:

Definition at line 44 of file test_python_api.py.

00044 
00045         def test_PyLong_Long(self):
00046             ref42 = grc(42)
00047             pythonapi.PyLong_FromLong.restype = py_object
00048             self.assertEqual(pythonapi.PyLong_FromLong(42), 42)
00049 
00050             self.assertEqual(grc(42), ref42)
00051 
00052             pythonapi.PyLong_AsLong.argtypes = (py_object,)
00053             pythonapi.PyLong_AsLong.restype = c_long
00054 
00055             res = pythonapi.PyLong_AsLong(42)
00056             self.assertEqual(grc(res), ref42 + 1)
00057             del res
00058             self.assertEqual(grc(42), ref42)

Here is the call graph for this function:

Definition at line 59 of file test_python_api.py.

00059 
00060     def test_PyObj_FromPtr(self):
00061         s = "abc def ghi jkl"
00062         ref = grc(s)
00063         # id(python-object) is the address
00064         pyobj = PyObj_FromPtr(id(s))
00065         self.assertTrue(s is pyobj)
00066 
00067         self.assertEqual(grc(s), ref + 1)
00068         del pyobj
00069         self.assertEqual(grc(s), ref)

Here is the call graph for this function:

Definition at line 84 of file test_python_api.py.

00084 
00085     def test_pyobject_repr(self):
00086         self.assertEqual(repr(py_object()), "py_object(<NULL>)")
00087         self.assertEqual(repr(py_object(42)), "py_object(42)")
00088         self.assertEqual(repr(py_object(object)), "py_object(%r)" % object)

Here is the call graph for this function:

Definition at line 70 of file test_python_api.py.

00070 
00071     def test_PyOS_snprintf(self):
00072         PyOS_snprintf = pythonapi.PyOS_snprintf
00073         PyOS_snprintf.argtypes = POINTER(c_char), c_size_t, c_char_p
00074 
00075         buf = c_buffer(256)
00076         PyOS_snprintf(buf, sizeof(buf), b"Hello from %s", b"ctypes")
00077         self.assertEqual(buf.value, b"Hello from ctypes")
00078 
00079         PyOS_snprintf(buf, sizeof(buf), b"Hello from %s (%d, %d, %d)", b"ctypes", 1, 2, 3)
00080         self.assertEqual(buf.value, b"Hello from ctypes (1, 2, 3)")
00081 
00082         # not enough arguments
00083         self.assertRaises(TypeError, PyOS_snprintf, buf)

Here is the call graph for this function:

Definition at line 28 of file test_python_api.py.

00028 
00029     def test_PyString_FromString(self):
00030         pythonapi.PyBytes_FromString.restype = py_object
00031         pythonapi.PyBytes_FromString.argtypes = (c_char_p,)
00032 
00033         s = b"abc"
00034         refcnt = grc(s)
00035         pyob = pythonapi.PyBytes_FromString(s)
00036         self.assertEqual(grc(s), refcnt)
00037         self.assertEqual(s, pyob)
00038         del pyob
00039         self.assertEqual(grc(s), refcnt)

Here is the call graph for this function:


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