summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2017-05-09 18:07:44 +0100
committerEric Wieser <wieser.eric@gmail.com>2017-05-09 18:21:49 +0100
commitdb0041d3a8db8594ddbeed654103a036f5aaa35c (patch)
treedb5cb49cbaa8d721d3d782d45405d7c9733aa0e5 /numpy
parent59fbc7d17a9e3a29ea7359891bd52b84cabb670f (diff)
downloadnumpy-db0041d3a8db8594ddbeed654103a036f5aaa35c.tar.gz
TST: Add missing tests for bool scalar conversion
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/tests/test_multiarray.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index 745c6ca5c..3171e5480 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -6404,6 +6404,28 @@ class TestConversion(TestCase):
assert_(np.array(-1, dtype=dt1) == np.array(-1, dtype=dt2),
"type %s and %s failed" % (dt1, dt2))
+ def test_to_bool_scalar(self):
+ assert_equal(bool(np.array([False])), False)
+ assert_equal(bool(np.array([True])), True)
+ assert_equal(bool(np.array([[42]])), True)
+ assert_raises(ValueError, bool, np.array([1, 2]))
+
+ class NotConvertible(object):
+ def __bool__(self):
+ raise NotImplementedError
+ __nonzero__ = __bool__ # python 2
+
+ assert_raises(NotImplementedError, bool, np.array(NotConvertible()))
+ assert_raises(NotImplementedError, bool, np.array([NotConvertible()]))
+
+ self_containing = np.array([None])
+ self_containing[0] = self_containing
+ try:
+ Error = RecursionError
+ except NameError:
+ Error = RuntimeError # python < 3.5
+ assert_raises(Error, bool, self_containing) # previously stack overflow
+
class TestWhere(TestCase):
def test_basic(self):