Skip to content

update tests affected by changing TypeError to ValueError in dpctl #1662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 33 additions & 11 deletions tests/test_mathematical.py
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,9 @@ def test_invalid_dtype(self, dtype):
dp_array = dpnp.arange(10, dtype=dpnp_dtype)
dp_out = dpnp.empty(10, dtype=dtype)

with pytest.raises(TypeError):
# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
dpnp.ceil(dp_array, out=dp_out)

@pytest.mark.parametrize("dtype", get_float_dtypes())
Expand Down Expand Up @@ -1200,7 +1202,9 @@ def test_invalid_dtype(self, dtype):
dp_array = dpnp.arange(10, dtype=dpnp_dtype)
dp_out = dpnp.empty(10, dtype=dtype)

with pytest.raises(TypeError):
# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
dpnp.floor(dp_array, out=dp_out)

@pytest.mark.parametrize("dtype", get_float_dtypes())
Expand Down Expand Up @@ -1240,7 +1244,9 @@ def test_invalid_dtype(self, dtype):
dp_array = dpnp.arange(10, dtype=dpnp_dtype)
dp_out = dpnp.empty(10, dtype=dtype)

with pytest.raises(TypeError):
# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
dpnp.trunc(dp_array, out=dp_out)

@pytest.mark.parametrize("dtype", get_float_dtypes())
Expand Down Expand Up @@ -1291,7 +1297,9 @@ def test_out_dtypes(self, dtype):
dp_out = dpnp.empty(size, dtype=dpnp.complex64)
if dtype != dpnp.complex64:
# dtype of out mismatches types of input arrays
with pytest.raises(TypeError):
# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
dpnp.add(dp_array1, dp_array2, out=dp_out)

# allocate new out with expected type
Expand Down Expand Up @@ -1388,7 +1396,9 @@ def test_out_dtypes(self, dtype):
check_dtype = True
if dtype != dpnp.complex64:
# dtype of out mismatches types of input arrays
with pytest.raises(TypeError):
# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
dpnp.divide(dp_array1, dp_array2, out=dp_out)

# allocate new out with expected type
Expand Down Expand Up @@ -1489,7 +1499,9 @@ def test_out_dtypes(self, dtype):
dp_out = dpnp.empty(size, dtype=dpnp.complex64)
if dtype != dpnp.complex64:
# dtype of out mismatches types of input arrays
with pytest.raises(TypeError):
# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
dpnp.floor_divide(dp_array1, dp_array2, out=dp_out)

# allocate new out with expected type
Expand Down Expand Up @@ -1749,7 +1761,9 @@ def test_out_dtypes(self, dtype):
dp_out = dpnp.empty(size, dtype=dpnp.float32)
if dtype != dpnp.float32:
# dtype of out mismatches types of input arrays
with pytest.raises(TypeError):
# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
dpnp.hypot(dp_array1, dp_array2, out=dp_out)

# allocate new out with expected type
Expand Down Expand Up @@ -1917,7 +1931,9 @@ def test_out_dtypes(self, dtype):
dp_out = dpnp.empty(size, dtype=dpnp.complex64)
if dtype != dpnp.complex64:
# dtype of out mismatches types of input arrays
with pytest.raises(TypeError):
# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
dpnp.maximum(dp_array1, dp_array2, out=dp_out)

# allocate new out with expected type
Expand Down Expand Up @@ -1998,7 +2014,9 @@ def test_out_dtypes(self, dtype):
dp_out = dpnp.empty(size, dtype=dpnp.complex64)
if dtype != dpnp.complex64:
# dtype of out mismatches types of input arrays
with pytest.raises(TypeError):
# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
dpnp.minimum(dp_array1, dp_array2, out=dp_out)

# allocate new out with expected type
Expand Down Expand Up @@ -2079,7 +2097,9 @@ def test_out_dtypes(self, dtype):
dp_out = dpnp.empty(size, dtype=dpnp.complex64)
if dtype != dpnp.complex64:
# dtype of out mismatches types of input arrays
with pytest.raises(TypeError):
# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
dpnp.multiply(dp_array1, dp_array2, out=dp_out)

# allocate new out with expected type
Expand Down Expand Up @@ -2174,7 +2194,9 @@ def test_out_dtypes(self, dtype):
dp_out = dpnp.empty(size, dtype=dpnp.complex64)
if dtype != dpnp.complex64:
# dtype of out mismatches types of input arrays
with pytest.raises(TypeError):
# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
dpnp.power(dp_array1, dp_array2, out=dp_out)

# allocate new out with expected type
Expand Down
28 changes: 21 additions & 7 deletions tests/test_umath.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ def test_invalid_dtype(self, func_params, dtype):
dp_array = dpnp.arange(10, dtype=dpnp_dtype)
dp_out = dpnp.empty(10, dtype=dtype)

with pytest.raises(TypeError):
# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
getattr(dpnp, func_name)(dp_array, out=dp_out)

@pytest.mark.parametrize(
Expand Down Expand Up @@ -250,7 +252,9 @@ def test_invalid_dtype(self, dtype):
dp_array = dpnp.arange(10, dtype=dpnp_dtype)
dp_out = dpnp.empty(10, dtype=dtype)

with pytest.raises(TypeError):
# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
dpnp.cbrt(dp_array, out=dp_out)

@pytest.mark.parametrize(
Expand Down Expand Up @@ -296,7 +300,9 @@ def test_invalid_dtype(self, dtype):
dp_array = dpnp.arange(10, dtype=dpnp_dtype)
dp_out = dpnp.empty(10, dtype=dtype)

with pytest.raises(TypeError):
# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
dpnp.rsqrt(dp_array, out=dp_out)

@pytest.mark.parametrize(
Expand Down Expand Up @@ -337,7 +343,9 @@ def test_invalid_dtype(self, dtype):
dp_array = dpnp.arange(10, dtype=dpnp_dtype)
dp_out = dpnp.empty(10, dtype=dtype)

with pytest.raises(TypeError):
# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
dpnp.square(dp_array, out=dp_out)

@pytest.mark.parametrize(
Expand Down Expand Up @@ -385,7 +393,9 @@ def test_invalid_dtype(self, dtype):
dp_array = dpnp.arange(10, dtype=dpnp_dtype)
dp_out = dpnp.empty(10, dtype=dtype)

with pytest.raises(TypeError):
# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
dpnp.arctan2(dp_array, dp_array, out=dp_out)

@pytest.mark.parametrize(
Expand Down Expand Up @@ -421,7 +431,9 @@ def test_invalid_dtype(self, dtype):
dpnp_dtype = get_all_dtypes(no_complex=True, no_none=True)[-1]
dp_array = dpnp.arange(10, dtype=dpnp_dtype)
dp_out = dpnp.empty(10, dtype=dtype)
with pytest.raises(TypeError):
# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
dpnp.copysign(dp_array, dp_array, out=dp_out)

@pytest.mark.parametrize(
Expand Down Expand Up @@ -457,7 +469,9 @@ def test_invalid_dtype(self, dtype):
dpnp_dtype = get_all_dtypes(no_complex=True, no_none=True)[-1]
dp_array = dpnp.arange(10, dtype=dpnp_dtype)
dp_out = dpnp.empty(10, dtype=dtype)
with pytest.raises(TypeError):
# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
dpnp.logaddexp(dp_array, dp_array, out=dp_out)

@pytest.mark.parametrize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,14 @@ def test_invert_array(self):
@testing.numpy_cupy_allclose(accept_error=TypeError)
def check_zerodim_op(self, op, xp, dtype):
a = xp.array(-2).astype(dtype)
return op(a)
try:
return op(a)
except ValueError:
# When op is operator.invert and dtype is inexact,
# NumPy raises TypeError while DPNP raises ValueError.
# With this logic, when ValueError is raised in DPNP,
# it is changed to TypeError to align with Numpy.
raise TypeError

def test_invert_zerodim(self):
self.check_zerodim_op(operator.invert)
Expand Down
5 changes: 3 additions & 2 deletions tests/third_party/cupy/math_tests/test_rounding.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from tests.third_party.cupy import testing


@testing.gpu
class TestRounding(unittest.TestCase):
@testing.for_all_dtypes(no_complex=True)
@testing.numpy_cupy_allclose(type_check=False, atol=1e-5)
Expand All @@ -26,7 +25,9 @@ def check_unary_complex(self, name, xp, dtype):
def check_unary_complex_unsupported(self, name, dtype):
for xp in (numpy, cupy):
a = testing.shaped_arange((2, 3), xp, dtype)
with pytest.raises(TypeError):
# NumPy returns TypeError while DPNP returns ValueError
# for these functions: "ceil", "floor", "trunc"
with pytest.raises((TypeError, ValueError)):
getattr(xp, name)(a)

@testing.for_dtypes(["?", "b", "h", "i", "q", "e", "f", "d"])
Expand Down