Back to index

python3.2  3.2.2
Public Member Functions
ctypes.test.test_arrays.ArrayTestCase Class Reference

List of all members.

Public Member Functions

def test_simple
def test_numeric_arrays
def test_classcache
def test_from_address
def test_from_addressW
def test_cache

Detailed Description

Definition at line 9 of file test_arrays.py.


Member Function Documentation

Definition at line 116 of file test_arrays.py.

00116 
00117     def test_cache(self):
00118         # Array types are cached internally in the _ctypes extension,
00119         # in a WeakValueDictionary.  Make sure the array type is
00120         # removed from the cache when the itemtype goes away.  This
00121         # test will not fail, but will show a leak in the testsuite.
00122 
00123         # Create a new type:
00124         class my_int(c_int):
00125             pass
00126         # Create a new array type based on it:
00127         t1 = my_int * 1
00128         t2 = my_int * 1
00129         self.assertTrue(t1 is t2)

Definition at line 86 of file test_arrays.py.

00086 
00087     def test_classcache(self):
00088         self.assertTrue(not ARRAY(c_int, 3) is ARRAY(c_int, 4))
00089         self.assertTrue(ARRAY(c_int, 3) is ARRAY(c_int, 3))

Here is the call graph for this function:

Definition at line 90 of file test_arrays.py.

00090 
00091     def test_from_address(self):
00092         # Failed with 0.9.8, reported by JUrner
00093         p = create_string_buffer(b"foo")
00094         sz = (c_char * 3).from_address(addressof(p))
00095         self.assertEqual(sz[:], b"foo")
00096         self.assertEqual(sz[::], b"foo")
00097         self.assertEqual(sz[::-1], b"oof")
00098         self.assertEqual(sz[::3], b"f")
00099         self.assertEqual(sz[1:4:2], b"o")
00100         self.assertEqual(sz.value, b"foo")

Here is the call graph for this function:

Definition at line 106 of file test_arrays.py.

00106 
00107         def test_from_addressW(self):
00108             p = create_unicode_buffer("foo")
00109             sz = (c_wchar * 3).from_address(addressof(p))
00110             self.assertEqual(sz[:], "foo")
00111             self.assertEqual(sz[::], "foo")
00112             self.assertEqual(sz[::-1], "oof")
00113             self.assertEqual(sz[::3], "f")
00114             self.assertEqual(sz[1:4:2], "o")
00115             self.assertEqual(sz.value, "foo")

Here is the call graph for this function:

Definition at line 64 of file test_arrays.py.

00064 
00065     def test_numeric_arrays(self):
00066 
00067         alen = 5
00068 
00069         numarray = ARRAY(c_int, alen)
00070 
00071         na = numarray()
00072         values = [na[i] for i in range(alen)]
00073         self.assertEqual(values, [0] * alen)
00074 
00075         na = numarray(*[c_int()] * alen)
00076         values = [na[i] for i in range(alen)]
00077         self.assertEqual(values, [0]*alen)
00078 
00079         na = numarray(1, 2, 3, 4, 5)
00080         values = [i for i in na]
00081         self.assertEqual(values, [1, 2, 3, 4, 5])
00082 
00083         na = numarray(*map(c_int, (1, 2, 3, 4, 5)))
00084         values = [i for i in na]
00085         self.assertEqual(values, [1, 2, 3, 4, 5])

Here is the call graph for this function:

Definition at line 10 of file test_arrays.py.

00010 
00011     def test_simple(self):
00012         # create classes holding simple numeric types, and check
00013         # various properties.
00014 
00015         init = list(range(15, 25))
00016 
00017         for fmt in formats:
00018             alen = len(init)
00019             int_array = ARRAY(fmt, alen)
00020 
00021             ia = int_array(*init)
00022             # length of instance ok?
00023             self.assertEqual(len(ia), alen)
00024 
00025             # slot values ok?
00026             values = [ia[i] for i in range(len(init))]
00027             self.assertEqual(values, init)
00028 
00029             # change the items
00030             from operator import setitem
00031             new_values = list(range(42, 42+alen))
00032             [setitem(ia, n, new_values[n]) for n in range(alen)]
00033             values = [ia[i] for i in range(len(init))]
00034             self.assertEqual(values, new_values)
00035 
00036             # are the items initialized to 0?
00037             ia = int_array()
00038             values = [ia[i] for i in range(len(init))]
00039             self.assertEqual(values, [0] * len(init))
00040 
00041             # Too many initializers should be caught
00042             self.assertRaises(IndexError, int_array, *range(alen*2))
00043 
00044         CharArray = ARRAY(c_char, 3)
00045 
00046         ca = CharArray(b"a", b"b", b"c")
00047 
00048         # Should this work? It doesn't:
00049         # CharArray("abc")
00050         self.assertRaises(TypeError, CharArray, "abc")
00051 
00052         self.assertEqual(ca[0], b"a")
00053         self.assertEqual(ca[1], b"b")
00054         self.assertEqual(ca[2], b"c")
00055         self.assertEqual(ca[-3], b"a")
00056         self.assertEqual(ca[-2], b"b")
00057         self.assertEqual(ca[-1], b"c")
00058 
00059         self.assertEqual(len(ca), 3)
00060 
00061         # cannot delete items
00062         from operator import delitem
00063         self.assertRaises(TypeError, delitem, ca, 0)

Here is the call graph for this function:


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