Skip to content

Commit 1d10f86

Browse files
Adding tests to improve coverage
Removed tests expecting error raised in case of overlapping inputs. Added tests guided by coverage report.
1 parent 28d699c commit 1d10f86

File tree

1 file changed

+48
-16
lines changed

1 file changed

+48
-16
lines changed

dpctl/tests/elementwise/test_add.py

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def test_add_broadcasting_new_shape():
175175
).all()
176176

177177
r3 = dpt.empty_like(ar1)
178-
with pytest.raises(TypeError):
178+
with pytest.raises(ValueError):
179179
dpt.add(ar1, ar2, out=r3)
180180

181181
ar3 = dpt.ones((6, 1), dtype="i4")
@@ -273,7 +273,7 @@ def test_add_errors():
273273
ar2 = dpt.ones_like(ar1, sycl_queue=gpu_queue)
274274
y = dpt.empty_like(ar1, sycl_queue=cpu_queue)
275275
assert_raises_regex(
276-
TypeError,
276+
ExecutionPlacementError,
277277
"Input and output allocation queues are not compatible",
278278
dpt.add,
279279
ar1,
@@ -285,27 +285,14 @@ def test_add_errors():
285285
ar2 = dpt.ones_like(ar1, dtype="int32")
286286
y = dpt.empty(3)
287287
assert_raises_regex(
288-
TypeError,
288+
ValueError,
289289
"The shape of input and output arrays are inconsistent",
290290
dpt.add,
291291
ar1,
292292
ar2,
293293
y,
294294
)
295295

296-
ar1 = dpt.ones(2, dtype="float32")
297-
ar2 = dpt.ones_like(ar1, dtype="int32")
298-
# identical view but a different object
299-
y = ar1[:]
300-
assert_raises_regex(
301-
TypeError,
302-
"Input and output arrays have memory overlap",
303-
dpt.add,
304-
ar1,
305-
ar2,
306-
y,
307-
)
308-
309296
ar1 = np.ones(2, dtype="float32")
310297
ar2 = np.ones_like(ar1, dtype="int32")
311298
assert_raises_regex(
@@ -485,3 +472,48 @@ def test_add_inplace_same_tensors():
485472
dpt.add(ar1, ar2, out=ar2)
486473
# all ar2 vals should be 5
487474
assert (dpt.asnumpy(ar2) == np.full(ar2.shape, 5, dtype="i4")).all()
475+
476+
477+
def test_add_str_repr():
478+
add_s = str(dpt.add)
479+
assert isinstance(add_s, str)
480+
assert "add" in add_s
481+
482+
add_r = repr(dpt.add)
483+
assert isinstance(add_r, str)
484+
assert "add" in add_r
485+
486+
487+
def test_add_cfd():
488+
q1 = get_queue_or_skip()
489+
q2 = dpctl.SyclQueue(q1.sycl_device)
490+
491+
x1 = dpt.ones(10, sycl_queue=q1)
492+
x2 = dpt.ones(10, sycl_queue=q2)
493+
with pytest.raises(ExecutionPlacementError):
494+
dpt.add(x1, x2)
495+
496+
with pytest.raises(ExecutionPlacementError):
497+
dpt.add(x1, x1, out=x2)
498+
499+
500+
def test_add_out_type_check():
501+
get_queue_or_skip()
502+
503+
x1 = dpt.ones(10)
504+
x2 = dpt.ones(10)
505+
506+
out = range(10)
507+
508+
with pytest.raises(TypeError):
509+
dpt.add(x1, x2, out=out)
510+
511+
512+
def test_add_out_need_temporary():
513+
get_queue_or_skip()
514+
515+
x = dpt.ones(10, dtype="u4")
516+
517+
dpt.add(x[:6], 1, out=x[-6:])
518+
519+
assert dpt.all(x[:-6] == 1) and dpt.all(x[-6:] == 2)

0 commit comments

Comments
 (0)