Skip to content

Commit 0a5a2bd

Browse files
authored
update tests affected by changing TypeError to ValueError in dpctl (#1662)
* update tests update more tests rename varibale update test hypot * including both type of erros in tests * address comments
1 parent 75f1f97 commit 0a5a2bd

File tree

4 files changed

+65
-21
lines changed

4 files changed

+65
-21
lines changed

tests/test_mathematical.py

+33-11
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,9 @@ def test_invalid_dtype(self, dtype):
11601160
dp_array = dpnp.arange(10, dtype=dpnp_dtype)
11611161
dp_out = dpnp.empty(10, dtype=dtype)
11621162

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

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

1203-
with pytest.raises(TypeError):
1205+
# TODO: change it to ValueError, when dpctl
1206+
# is being used in internal CI
1207+
with pytest.raises((TypeError, ValueError)):
12041208
dpnp.floor(dp_array, out=dp_out)
12051209

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

1243-
with pytest.raises(TypeError):
1247+
# TODO: change it to ValueError, when dpctl
1248+
# is being used in internal CI
1249+
with pytest.raises((TypeError, ValueError)):
12441250
dpnp.trunc(dp_array, out=dp_out)
12451251

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

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

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

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

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

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

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

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

21802202
# allocate new out with expected type

tests/test_umath.py

+21-7
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,9 @@ def test_invalid_dtype(self, func_params, dtype):
205205
dp_array = dpnp.arange(10, dtype=dpnp_dtype)
206206
dp_out = dpnp.empty(10, dtype=dtype)
207207

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

211213
@pytest.mark.parametrize(
@@ -250,7 +252,9 @@ def test_invalid_dtype(self, dtype):
250252
dp_array = dpnp.arange(10, dtype=dpnp_dtype)
251253
dp_out = dpnp.empty(10, dtype=dtype)
252254

253-
with pytest.raises(TypeError):
255+
# TODO: change it to ValueError, when dpctl
256+
# is being used in internal CI
257+
with pytest.raises((TypeError, ValueError)):
254258
dpnp.cbrt(dp_array, out=dp_out)
255259

256260
@pytest.mark.parametrize(
@@ -296,7 +300,9 @@ def test_invalid_dtype(self, dtype):
296300
dp_array = dpnp.arange(10, dtype=dpnp_dtype)
297301
dp_out = dpnp.empty(10, dtype=dtype)
298302

299-
with pytest.raises(TypeError):
303+
# TODO: change it to ValueError, when dpctl
304+
# is being used in internal CI
305+
with pytest.raises((TypeError, ValueError)):
300306
dpnp.rsqrt(dp_array, out=dp_out)
301307

302308
@pytest.mark.parametrize(
@@ -337,7 +343,9 @@ def test_invalid_dtype(self, dtype):
337343
dp_array = dpnp.arange(10, dtype=dpnp_dtype)
338344
dp_out = dpnp.empty(10, dtype=dtype)
339345

340-
with pytest.raises(TypeError):
346+
# TODO: change it to ValueError, when dpctl
347+
# is being used in internal CI
348+
with pytest.raises((TypeError, ValueError)):
341349
dpnp.square(dp_array, out=dp_out)
342350

343351
@pytest.mark.parametrize(
@@ -385,7 +393,9 @@ def test_invalid_dtype(self, dtype):
385393
dp_array = dpnp.arange(10, dtype=dpnp_dtype)
386394
dp_out = dpnp.empty(10, dtype=dtype)
387395

388-
with pytest.raises(TypeError):
396+
# TODO: change it to ValueError, when dpctl
397+
# is being used in internal CI
398+
with pytest.raises((TypeError, ValueError)):
389399
dpnp.arctan2(dp_array, dp_array, out=dp_out)
390400

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

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

463477
@pytest.mark.parametrize(

tests/third_party/cupy/core_tests/test_ndarray_unary_op.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,14 @@ def test_invert_array(self):
124124
@testing.numpy_cupy_allclose(accept_error=TypeError)
125125
def check_zerodim_op(self, op, xp, dtype):
126126
a = xp.array(-2).astype(dtype)
127-
return op(a)
127+
try:
128+
return op(a)
129+
except ValueError:
130+
# When op is operator.invert and dtype is inexact,
131+
# NumPy raises TypeError while DPNP raises ValueError.
132+
# With this logic, when ValueError is raised in DPNP,
133+
# it is changed to TypeError to align with Numpy.
134+
raise TypeError
128135

129136
def test_invert_zerodim(self):
130137
self.check_zerodim_op(operator.invert)

tests/third_party/cupy/math_tests/test_rounding.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from tests.third_party.cupy import testing
99

1010

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

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

0 commit comments

Comments
 (0)