[pypy-commit] pypy default: add passing tests, searching why np.ndarray(np.int64()) fails on win32
mattip
pypy.commits at gmail.com
Mon Jul 25 10:02:57 EDT 2016
Author: mattip <matti.picus at gmail.com>
Branch:
Changeset: r85855:419c923b6e54
Date: 2016-07-25 17:00 -0500
http://bitbucket.org/pypy/pypy/changeset/419c923b6e54/
Log: add passing tests, searching why np.ndarray(np.int64()) fails on
win32
diff --git a/pypy/module/cpyext/test/test_number.py b/pypy/module/cpyext/test/test_number.py
--- a/pypy/module/cpyext/test/test_number.py
+++ b/pypy/module/cpyext/test/test_number.py
@@ -144,3 +144,15 @@
assert tupl[0] == 3.
assert tupl[1] == 1.
assert isinstance(tupl[0], float)'''
+
+ def test_PyNumber_Check(self):
+ mod = self.import_extension('foo', [
+ ("test_PyNumber_Check", "METH_VARARGS",
+ '''
+ PyObject *obj = PyTuple_GET_ITEM(args, 0);
+ int val = PyNumber_Check(obj);
+ Py_DECREF(obj);
+ return PyInt_FromLong(val);
+ ''')])
+ val = mod.test_PyNumber_Check(10)
+ assert val == 1
diff --git a/pypy/module/cpyext/test/test_typeobject.py b/pypy/module/cpyext/test/test_typeobject.py
--- a/pypy/module/cpyext/test/test_typeobject.py
+++ b/pypy/module/cpyext/test/test_typeobject.py
@@ -729,7 +729,7 @@
x = list(it)
assert x == [1]
- def test_bool(self):
+ def test_intlike(self):
module = self.import_extension('foo', [
("newInt", "METH_VARARGS",
"""
@@ -739,10 +739,6 @@
if (!PyArg_ParseTuple(args, "i", &intval))
return NULL;
- IntLike_Type.tp_flags |= Py_TPFLAGS_DEFAULT;
- IntLike_Type.tp_as_number = &intlike_as_number;
- intlike_as_number.nb_nonzero = intlike_nb_nonzero;
- if (PyType_Ready(&IntLike_Type) < 0) return NULL;
intObj = PyObject_New(IntLikeObject, &IntLike_Type);
if (!intObj) {
return NULL;
@@ -750,8 +746,23 @@
intObj->value = intval;
return (PyObject *)intObj;
- """)],
- """
+ """),
+ ("check", "METH_VARARGS", """
+ IntLikeObject *intObj;
+ int intval, isint;
+
+ if (!PyArg_ParseTuple(args, "i", &intval))
+ return NULL;
+ intObj = PyObject_New(IntLikeObject, &IntLike_Type);
+ if (!intObj) {
+ return NULL;
+ }
+ intObj->value = intval;
+ isint = PyNumber_Check((PyObject*)intObj);
+ Py_DECREF((PyObject*)intObj);
+ return PyInt_FromLong(isint);
+ """),
+ ], prologue= """
typedef struct
{
PyObject_HEAD
@@ -770,6 +781,13 @@
return v->value;
}
+ static PyObject*
+ intlike_nb_int(PyObject* o)
+ {
+ IntLikeObject *v = (IntLikeObject*)o;
+ return PyInt_FromLong(v->value);
+ }
+
PyTypeObject IntLike_Type = {
PyObject_HEAD_INIT(0)
/*ob_size*/ 0,
@@ -777,11 +795,19 @@
/*tp_basicsize*/ sizeof(IntLikeObject),
};
static PyNumberMethods intlike_as_number;
+ """, more_init="""
+ IntLike_Type.tp_flags |= Py_TPFLAGS_DEFAULT;
+ IntLike_Type.tp_as_number = &intlike_as_number;
+ intlike_as_number.nb_nonzero = intlike_nb_nonzero;
+ intlike_as_number.nb_int = intlike_nb_int;
+ if (PyType_Ready(&IntLike_Type) < 0) return NULL;
""")
assert not bool(module.newInt(0))
assert bool(module.newInt(1))
raises(SystemError, bool, module.newInt(-1))
raises(ValueError, bool, module.newInt(-42))
+ val = module.check(10);
+ assert val == 1
def test_mathfunc(self):
module = self.import_extension('foo', [
More information about the pypy-commit
mailing list