Author: Matti Picus <[email protected]>
Branch: pypy-pyarray
Changeset: r67009:5352a97e55e8
Date: 2013-09-19 22:33 +0300
http://bitbucket.org/pypy/pypy/changeset/5352a97e55e8/
Log: add test for ndarrayobject.c, no error checking since numpy does not
do error checking either
diff --git a/TODO.txt b/TODO.txt
--- a/TODO.txt
+++ b/TODO.txt
@@ -1,13 +1,9 @@
-Comments by antocuni, rguillebert
-==================================
-
TODO list by mattip
===================
- test "from numpypy import *" esp. get_include()
- test all *.h files under pypy/module/cpyext/include/numpy
- make sure meaningful cpyext changes are tested:
- all ndarrayobject.c
copy_header_files() in api.py (changed)
all ndarrayobject.py (new)
- test, implement use of __array_prepare__()
diff --git a/pypy/module/cpyext/test/test_ndarrayobject.py
b/pypy/module/cpyext/test/test_ndarrayobject.py
--- a/pypy/module/cpyext/test/test_ndarrayobject.py
+++ b/pypy/module/cpyext/test/test_ndarrayobject.py
@@ -1,7 +1,7 @@
import py
-from pypy.module.cpyext.pyobject import PyObject
from pypy.module.cpyext.test.test_api import BaseApiTest
+from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
from rpython.rtyper.lltypesystem import rffi, lltype
from pypy.module.micronumpy.interp_numarray import W_NDimArray
@@ -199,3 +199,42 @@
assert res.get_scalar_value().real == 3.
assert res.get_scalar_value().imag == 4.
+class AppTestCNumber(AppTestCpythonExtensionBase):
+ def test_ndarray_object_c(self):
+ mod = self.import_extension('foo', [
+ ("test_simplenew", "METH_NOARGS",
+ '''
+ npy_intp dims[2] ={2, 3};
+ PyObject * obj = PyArray_SimpleNew(2, dims, 11);
+ return obj;
+ '''
+ ),
+ ("test_fill", "METH_NOARGS",
+ '''
+ npy_intp dims[2] ={2, 3};
+ PyObject * obj = PyArray_SimpleNew(2, dims, 1);
+ PyArray_FILLWBYTE(obj, 42);
+ return obj;
+ '''
+ ),
+ ("test_copy", "METH_NOARGS",
+ '''
+ npy_intp dims1[2] ={2, 3};
+ npy_intp dims2[2] ={3, 2};
+ PyObject * obj1 = PyArray_ZEROS(2, dims1, 11, 0);
+ PyObject * obj2 = PyArray_ZEROS(2, dims2, 11, 0);
+ PyArray_FILLWBYTE(obj2, 42);
+ PyArray_CopyInto(obj2, obj1);
+ return obj2;
+ '''
+ ),
+ ], prologue='#include <numpy/arrayobject.h>')
+ arr = mod.test_simplenew()
+ assert arr.shape == (2, 3)
+ assert arr.dtype.num == 11 #float32 dtype
+ arr = mod.test_fill()
+ assert arr.shape == (2, 3)
+ assert arr.dtype.num == 1 #int8 dtype
+ assert (arr == 42).all()
+ arr = mod.test_copy()
+ assert (arr == 0).all()
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit