Author: Matti Picus <[email protected]>
Branch: pypy-pyarray
Changeset: r67029:61c630f73ba3
Date: 2013-09-20 11:50 +0300
http://bitbucket.org/pypy/pypy/changeset/61c630f73ba3/

Log:    add tests for __array_prepare__, __array_wrap__

diff --git a/pypy/module/micronumpy/test/test_subtype.py 
b/pypy/module/micronumpy/test/test_subtype.py
--- a/pypy/module/micronumpy/test/test_subtype.py
+++ b/pypy/module/micronumpy/test/test_subtype.py
@@ -244,3 +244,31 @@
             assert isinstance(b, D)
         c = array(a, float)
         assert c.dtype is dtype(float)
+
+    def test___array_wrap__(self):
+        from numpypy import ndarray, add, ones
+        class with_wrap(object):
+            called_wrap = False
+            def __array__(self):
+                return ones(1)
+            def __array_wrap__(self, arr, context):
+                self.called_wrap = True
+                return arr
+        a = with_wrap()
+        x = add(a, a)
+        assert x == 2
+        assert type(x) == ndarray
+        assert a.called_wrap
+
+    def test___array_prepare__(self):
+        from numpypy import ndarray, array, add, ones
+        class with_prepare(ndarray):
+            called_prepare = False
+            def __array_prepare__(self, arr, context):
+                self.called_prepare = True
+                return array(arr).view(type=with_prepare)
+        a = array(1).view(type=with_prepare)
+        x = add(a, a)
+        assert x == 2
+        assert type(x) == with_prepare
+        assert a.called_prepare
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to