Author: Matti Picus <matti.pi...@gmail.com>
Branch: pypy-pyarray
Changeset: r67051:c1a7865243c0
Date: 2013-09-22 09:32 +0300
http://bitbucket.org/pypy/pypy/changeset/c1a7865243c0/

Log:    fix test, change implementation for pendatic exception string,
        improve test

diff --git a/pypy/module/cpyext/ndarrayobject.py 
b/pypy/module/cpyext/ndarrayobject.py
--- a/pypy/module/cpyext/ndarrayobject.py
+++ b/pypy/module/cpyext/ndarrayobject.py
@@ -171,8 +171,16 @@
 
 @cpython_api([PyObject, Py_ssize_t, Py_ssize_t, Py_ssize_t], PyObject)
 def _PyArray_FromObject(space, w_obj, typenum, min_depth, max_depth):
-    return _PyArray_FromAny(space, w_obj, typenum, min_depth, max_depth, 
NPY_BEHAVED);
-
+    try:
+        return _PyArray_FromAny(space, w_obj, typenum, min_depth, max_depth,
+                            0, None);
+    except OperationError, e:
+        if e.match(space, space.w_NotImplementedError):
+            errstr = space.str_w(e.get_w_value(space))
+            errstr = errstr.replace('FromAny','FromObject')
+            raise OperationError(space.w_NotImplementedError, space.wrap(
+                errstr))
+        raise
 
 def get_shape_and_dtype(space, nd, dims, typenum):
     shape = []
diff --git a/pypy/module/cpyext/test/test_api.py 
b/pypy/module/cpyext/test/test_api.py
--- a/pypy/module/cpyext/test/test_api.py
+++ b/pypy/module/cpyext/test/test_api.py
@@ -46,7 +46,7 @@
             raise Exception("DID NOT RAISE")
         if getattr(space, 'w_' + expected_exc.__name__) is not operror.w_type:
             raise Exception("Wrong exception")
-        state.clear_exception()
+        return state.clear_exception()
 
     def setup_method(self, func):
         freeze_refcnts(self)
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
@@ -96,10 +96,11 @@
 
     def test_FromObject(self, space, api):
         a = array(space, [10, 5, 3])
-        assert api._PyArray_FromObject(a, NULL, 0, 0, 0, NULL) is a
-        self.raises(space, api, NotImplementedError, api._PyArray_FromObject,
-                    space.wrap(a), space.w_None, space.wrap(0),
-                    space.wrap(3), space.wrap(0), space.w_None)
+        assert api._PyArray_FromObject(a, None, 0, 0) is a
+        exc = self.raises(space, api, NotImplementedError, 
api._PyArray_FromObject,
+                    space.wrap(a), space.wrap(11), space.wrap(0),
+                    space.wrap(3) )
+        assert exc.errorstr(space).find('FromObject') >= 0
 
     def test_list_from_fixedptr(self, space, api):
         A = lltype.GcArray(lltype.Float)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to