From: Matěj Laitl Date: Thu, 29 Nov 2012 21:50:08 +0000 (+0100) Subject: Add test for memoryview of extension type X-Git-Tag: 0.19b1~272^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=de9050401929751af0af2d792ecf5390f4381fc1;p=platform%2Fupstream%2Fpython-cython.git Add test for memoryview of extension type A test for a bug fixed in commit 478b939a4c99a77c0863cfd. v2: add commit link above v3: # tag: instead of # tags:, drop cpp tag as it means something different that I originally thought There was a bug that produced C code where gcc emitted warnings: extension_type_memoryview.c: In function ‘__pyx_pf_25extension_type_memoryview_test_getitem’: extension_type_memoryview.c:1468:15: warning: assignment from incompatible pointer type extension_type_memoryview.c: In function ‘__pyx_pf_25extension_type_memoryview_2test_getitem_typed’: extension_type_memoryview.c:1565:15: warning: assignment from incompatible pointer type extension_type_memoryview.c:1568:18: warning: assignment from incompatible pointer type And g++ failed with errors: extension_type_memoryview.c: In function ‘PyObject* __pyx_pf_25extension_type_memoryview_test_getitem(PyObject*)’: extension_type_memoryview.c:1468:213: error: cannot convert ‘__pyx_obj_25extension_type_memoryview_ExtensionType*’ to ‘PyObject*’ in assignment extension_type_memoryview.c: In function ‘PyObject* __pyx_pf_25extension_type_memoryview_2test_getitem_typed(PyObject*)’: extension_type_memoryview.c:1565:213: error: cannot convert ‘__pyx_obj_25extension_type_memoryview_ExtensionType*’ to ‘PyObject*’ in assignment extension_type_memoryview.c:1568:20: error: cannot convert ‘PyObject*’ to ‘__pyx_obj_25extension_type_memoryview_ExtensionType*’ in assignment --- diff --git a/tests/memoryview/extension_type_memoryview.pyx b/tests/memoryview/extension_type_memoryview.pyx new file mode 100644 index 0000000..eae2130 --- /dev/null +++ b/tests/memoryview/extension_type_memoryview.pyx @@ -0,0 +1,35 @@ +# mode: run +# tag: numpy + +import numpy as np + + +cdef class ExtensionType(object): + cdef public int dummy + + def __init__(self, n): + self.dummy = n + +items = [ExtensionType(1), ExtensionType(2)] +cdef ExtensionType[:] view = np.array(items, dtype=ExtensionType) + +def test_getitem(): + """ + >>> test_getitem() + 1 + 2 + """ + for i in range(view.shape[0]): + item = view[i] + print item.dummy + +def test_getitem_typed(): + """ + >>> test_getitem_typed() + 1 + 2 + """ + cdef ExtensionType item + for i in range(view.shape[0]): + item = view[i] + print item.dummy