summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorHan Genuit <hangenuit@gmail.com>2012-09-30 21:09:19 +0200
committerHan Genuit <hangenuit@gmail.com>2012-09-30 21:09:19 +0200
commit92ecbdde33f6f61712d7d1a0e4500c76a65aac7a (patch)
tree21d47be9e23a62b66625dc58d077cb33eb9a21cd /numpy
parentde3075f5484a6e71273633bc1202c0971f8889e2 (diff)
downloadnumpy-92ecbdde33f6f61712d7d1a0e4500c76a65aac7a.tar.gz
TST: Add more tests.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/tests/test_multiarray.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index f2a38c079..e281a3ecd 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -2810,19 +2810,30 @@ if sys.version_info >= (2, 6):
assert_raises(AttributeError, delattr, a, s)
def test_array_interface():
+ # Test scalar coercion within the array interface
class Foo(object):
def __init__(self, value):
self.value = value
+ self.iface = {'typestr' : '=f8'}
def __float__(self):
return float(self.value)
@property
def __array_interface__(self):
- return {'typestr' : '=f8',
- 'shape' : ()}
+ return self.iface
f = Foo(0.5)
- assert_equal(np.array(f), [0.5])
+ assert_equal(np.array(f), 0.5)
+ assert_equal(np.array([f]), [0.5])
assert_equal(np.array([f, f]), [0.5, 0.5])
assert_equal(np.array(f).dtype, np.dtype('=f8'))
+ # Test various shape definitions
+ f.iface['shape'] = ()
+ assert_equal(np.array(f), 0.5)
+ f.iface['shape'] = None
+ assert_raises(TypeError, np.array, f)
+ f.iface['shape'] = (1,1)
+ assert_equal(np.array(f), [[0.5]])
+ f.iface['shape'] = (2,)
+ assert_raises(ValueError, np.array, f)
def test_flat_element_deletion():
it = np.ones(3).flat