summaryrefslogtreecommitdiff
path: root/numpy/array_api/tests
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/array_api/tests')
-rw-r--r--numpy/array_api/tests/test_array_object.py30
-rw-r--r--numpy/array_api/tests/test_creation_functions.py15
2 files changed, 24 insertions, 21 deletions
diff --git a/numpy/array_api/tests/test_array_object.py b/numpy/array_api/tests/test_array_object.py
index 088e09b9f..7959f92b4 100644
--- a/numpy/array_api/tests/test_array_object.py
+++ b/numpy/array_api/tests/test_array_object.py
@@ -1,3 +1,5 @@
+import operator
+
from numpy.testing import assert_raises
import numpy as np
@@ -255,15 +257,31 @@ def test_operators():
def test_python_scalar_construtors():
- a = asarray(False)
- b = asarray(0)
- c = asarray(0.0)
+ b = asarray(False)
+ i = asarray(0)
+ f = asarray(0.0)
- assert bool(a) == bool(b) == bool(c) == False
- assert int(a) == int(b) == int(c) == 0
- assert float(a) == float(b) == float(c) == 0.0
+ assert bool(b) == False
+ assert int(i) == 0
+ assert float(f) == 0.0
+ assert operator.index(i) == 0
# bool/int/float should only be allowed on 0-D arrays.
assert_raises(TypeError, lambda: bool(asarray([False])))
assert_raises(TypeError, lambda: int(asarray([0])))
assert_raises(TypeError, lambda: float(asarray([0.0])))
+ assert_raises(TypeError, lambda: operator.index(asarray([0])))
+
+ # bool/int/float should only be allowed on arrays of the corresponding
+ # dtype
+ assert_raises(ValueError, lambda: bool(i))
+ assert_raises(ValueError, lambda: bool(f))
+
+ assert_raises(ValueError, lambda: int(b))
+ assert_raises(ValueError, lambda: int(f))
+
+ assert_raises(ValueError, lambda: float(b))
+ assert_raises(ValueError, lambda: float(i))
+
+ assert_raises(TypeError, lambda: operator.index(b))
+ assert_raises(TypeError, lambda: operator.index(f))
diff --git a/numpy/array_api/tests/test_creation_functions.py b/numpy/array_api/tests/test_creation_functions.py
index 2ee23a47b..c13bc4262 100644
--- a/numpy/array_api/tests/test_creation_functions.py
+++ b/numpy/array_api/tests/test_creation_functions.py
@@ -8,30 +8,15 @@ from .._creation_functions import (
empty,
empty_like,
eye,
- from_dlpack,
full,
full_like,
linspace,
- meshgrid,
ones,
ones_like,
zeros,
zeros_like,
)
from .._array_object import Array
-from .._dtypes import (
- _all_dtypes,
- _boolean_dtypes,
- _floating_dtypes,
- _integer_dtypes,
- _integer_or_boolean_dtypes,
- _numeric_dtypes,
- int8,
- int16,
- int32,
- int64,
- uint64,
-)
def test_asarray_errors():