Skip to content

Commit 2d8064a

Browse files
Adjusted tests to fix violations of keyword-arg given as positional
1 parent a43ba75 commit 2d8064a

File tree

1 file changed

+50
-43
lines changed

1 file changed

+50
-43
lines changed

dpctl/tests/test_usm_ndarray_manipulation.py

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def test_permute_dims_2d_3d(shapes):
8888
def test_expand_dims_incorrect_type():
8989
X_list = [1, 2, 3, 4, 5]
9090
with pytest.raises(TypeError):
91-
dpt.permute_dims(X_list, 1)
91+
dpt.permute_dims(X_list, axis=1)
9292

9393

9494
def test_expand_dims_0d():
@@ -97,16 +97,16 @@ def test_expand_dims_0d():
9797
Xnp = np.array(1, dtype="int64")
9898
X = dpt.asarray(Xnp, sycl_queue=q)
9999

100-
Y = dpt.expand_dims(X, 0)
101-
Ynp = np.expand_dims(Xnp, 0)
100+
Y = dpt.expand_dims(X, axis=0)
101+
Ynp = np.expand_dims(Xnp, axis=0)
102102
assert_array_equal(Ynp, dpt.asnumpy(Y))
103103

104-
Y = dpt.expand_dims(X, -1)
105-
Ynp = np.expand_dims(Xnp, -1)
104+
Y = dpt.expand_dims(X, axis=-1)
105+
Ynp = np.expand_dims(Xnp, axis=-1)
106106
assert_array_equal(Ynp, dpt.asnumpy(Y))
107107

108-
pytest.raises(np.AxisError, dpt.expand_dims, X, 1)
109-
pytest.raises(np.AxisError, dpt.expand_dims, X, -2)
108+
pytest.raises(np.AxisError, dpt.expand_dims, X, axis=1)
109+
pytest.raises(np.AxisError, dpt.expand_dims, X, axis=-2)
110110

111111

112112
@pytest.mark.parametrize("shapes", [(3,), (3, 3), (3, 3, 3)])
@@ -119,12 +119,12 @@ def test_expand_dims_1d_3d(shapes):
119119
X = dpt.asarray(Xnp, sycl_queue=q)
120120
shape_len = len(shapes)
121121
for axis in range(-shape_len - 1, shape_len):
122-
Y = dpt.expand_dims(X, axis)
123-
Ynp = np.expand_dims(Xnp, axis)
122+
Y = dpt.expand_dims(X, axis=axis)
123+
Ynp = np.expand_dims(Xnp, axis=axis)
124124
assert_array_equal(Ynp, dpt.asnumpy(Y))
125125

126-
pytest.raises(np.AxisError, dpt.expand_dims, X, shape_len + 1)
127-
pytest.raises(np.AxisError, dpt.expand_dims, X, -shape_len - 2)
126+
pytest.raises(np.AxisError, dpt.expand_dims, X, axis=shape_len + 1)
127+
pytest.raises(np.AxisError, dpt.expand_dims, X, axis=-shape_len - 2)
128128

129129

130130
@pytest.mark.parametrize(
@@ -135,8 +135,8 @@ def test_expand_dims_tuple(axes):
135135

136136
Xnp = np.empty((3, 3, 3), dtype="u1")
137137
X = dpt.asarray(Xnp, sycl_queue=q)
138-
Y = dpt.expand_dims(X, axes)
139-
Ynp = np.expand_dims(Xnp, axes)
138+
Y = dpt.expand_dims(X, axis=axes)
139+
Ynp = np.expand_dims(Xnp, axis=axes)
140140
assert_array_equal(Ynp, dpt.asnumpy(Y))
141141

142142

@@ -146,12 +146,12 @@ def test_expand_dims_incorrect_tuple():
146146
except dpctl.SyclDeviceCreationError:
147147
pytest.skip("No SYCL devices available")
148148
with pytest.raises(np.AxisError):
149-
dpt.expand_dims(X, (0, -6))
149+
dpt.expand_dims(X, axis=(0, -6))
150150
with pytest.raises(np.AxisError):
151-
dpt.expand_dims(X, (0, 5))
151+
dpt.expand_dims(X, axis=(0, 5))
152152

153153
with pytest.raises(ValueError):
154-
dpt.expand_dims(X, (1, 1))
154+
dpt.expand_dims(X, axis=(1, 1))
155155

156156

157157
def test_squeeze_incorrect_type():
@@ -456,9 +456,9 @@ def test_flip_0d():
456456
Y = dpt.flip(X)
457457
assert_array_equal(Ynp, dpt.asnumpy(Y))
458458

459-
pytest.raises(np.AxisError, dpt.flip, X, 0)
460-
pytest.raises(np.AxisError, dpt.flip, X, 1)
461-
pytest.raises(np.AxisError, dpt.flip, X, -1)
459+
pytest.raises(np.AxisError, dpt.flip, X, axis=0)
460+
pytest.raises(np.AxisError, dpt.flip, X, axis=1)
461+
pytest.raises(np.AxisError, dpt.flip, X, axis=-1)
462462

463463

464464
def test_flip_1d():
@@ -468,12 +468,12 @@ def test_flip_1d():
468468
X = dpt.asarray(Xnp, sycl_queue=q)
469469

470470
for ax in range(-X.ndim, X.ndim):
471-
Ynp = np.flip(Xnp, ax)
472-
Y = dpt.flip(X, ax)
471+
Ynp = np.flip(Xnp, axis=ax)
472+
Y = dpt.flip(X, axis=ax)
473473
assert_array_equal(Ynp, dpt.asnumpy(Y))
474474

475-
Ynp = np.flip(Xnp, 0)
476-
Y = dpt.flip(X, 0)
475+
Ynp = np.flip(Xnp, axis=0)
476+
Y = dpt.flip(X, axis=0)
477477
assert_array_equal(Ynp, dpt.asnumpy(Y))
478478

479479

@@ -497,8 +497,8 @@ def test_flip_2d_3d(shapes):
497497
Xnp = np.arange(Xnp_size).reshape(shapes)
498498
X = dpt.asarray(Xnp, sycl_queue=q)
499499
for ax in range(-X.ndim, X.ndim):
500-
Y = dpt.flip(X, ax)
501-
Ynp = np.flip(Xnp, ax)
500+
Y = dpt.flip(X, axis=ax)
501+
Ynp = np.flip(Xnp, axis=ax)
502502
assert_array_equal(Ynp, dpt.asnumpy(Y))
503503

504504

@@ -569,8 +569,8 @@ def test_flip_multiple_axes(data):
569569
Xnp_size = np.prod(shape)
570570
Xnp = np.arange(Xnp_size).reshape(shape)
571571
X = dpt.asarray(Xnp, sycl_queue=q)
572-
Y = dpt.flip(X, axes)
573-
Ynp = np.flip(Xnp, axes)
572+
Y = dpt.flip(X, axis=axes)
573+
Ynp = np.flip(Xnp, axis=axes)
574574
assert_array_equal(Ynp, dpt.asnumpy(Y))
575575

576576

@@ -583,8 +583,10 @@ def test_roll_empty():
583583
Y = dpt.roll(X, 1)
584584
Ynp = np.roll(Xnp, 1)
585585
assert_array_equal(Ynp, dpt.asnumpy(Y))
586-
pytest.raises(np.AxisError, dpt.roll, X, 1, 0)
587-
pytest.raises(np.AxisError, dpt.roll, X, 1, 1)
586+
with pytest.raises(np.AxisError):
587+
dpt.roll(X, 1, axis=0)
588+
with pytest.raises(np.AxisError):
589+
dpt.roll(X, 1, axis=1)
588590

589591

590592
@pytest.mark.parametrize(
@@ -605,12 +607,12 @@ def test_roll_1d(data):
605607
X = dpt.asarray(Xnp, sycl_queue=q)
606608
sh, ax = data
607609

608-
Y = dpt.roll(X, sh, ax)
609-
Ynp = np.roll(Xnp, sh, ax)
610+
Y = dpt.roll(X, sh, axis=ax)
611+
Ynp = np.roll(Xnp, sh, axis=ax)
610612
assert_array_equal(Ynp, dpt.asnumpy(Y))
611613

612-
Y = dpt.roll(X, sh, ax)
613-
Ynp = np.roll(Xnp, sh, ax)
614+
Y = dpt.roll(X, sh, axis=ax)
615+
Ynp = np.roll(Xnp, sh, axis=ax)
614616
assert_array_equal(Ynp, dpt.asnumpy(Y))
615617

616618

@@ -644,8 +646,8 @@ def test_roll_2d(data):
644646
X = dpt.asarray(Xnp, sycl_queue=q)
645647
sh, ax = data
646648

647-
Y = dpt.roll(X, sh, ax)
648-
Ynp = np.roll(Xnp, sh, ax)
649+
Y = dpt.roll(X, sh, axis=ax)
650+
Ynp = np.roll(Xnp, sh, axis=ax)
649651
assert_array_equal(Ynp, dpt.asnumpy(Y))
650652

651653

@@ -664,10 +666,14 @@ def test_roll_validation():
664666

665667
def test_concat_incorrect_type():
666668
Xnp = np.ones((2, 2))
667-
pytest.raises(TypeError, dpt.concat)
668-
pytest.raises(TypeError, dpt.concat, [])
669-
pytest.raises(TypeError, dpt.concat, Xnp)
670-
pytest.raises(TypeError, dpt.concat, [Xnp, Xnp])
669+
with pytest.raises(TypeError):
670+
dpt.concat()
671+
with pytest.raises(TypeError):
672+
dpt.concat([])
673+
with pytest.raises(TypeError):
674+
dpt.concat(Xnp)
675+
with pytest.raises(TypeError):
676+
dpt.concat([Xnp, Xnp])
671677

672678

673679
def test_concat_incorrect_queue():
@@ -719,7 +725,7 @@ def test_concat_incorrect_shape(data):
719725
X = dpt.ones(Xshape, sycl_queue=q)
720726
Y = dpt.ones(Yshape, sycl_queue=q)
721727

722-
pytest.raises(ValueError, dpt.concat, [X, Y], axis)
728+
pytest.raises(ValueError, dpt.concat, [X, Y], axis=axis)
723729

724730

725731
@pytest.mark.parametrize(
@@ -827,7 +833,8 @@ def test_stack_incorrect_shape():
827833
X = dpt.ones((1,), sycl_queue=q)
828834
Y = dpt.ones((2,), sycl_queue=q)
829835

830-
pytest.raises(ValueError, dpt.stack, [X, Y], 0)
836+
with pytest.raises(ValueError):
837+
dpt.stack([X, Y], axis=0)
831838

832839

833840
@pytest.mark.parametrize(
@@ -1111,7 +1118,7 @@ def test_unstack_axis1():
11111118
except dpctl.SyclDeviceCreationError:
11121119
pytest.skip("No SYCL devices available")
11131120
y = dpt.reshape(x_flat, (2, 3))
1114-
res = dpt.unstack(y, 1)
1121+
res = dpt.unstack(y, axis=1)
11151122

11161123
assert_array_equal(dpt.asnumpy(y[:, 0, ...]), dpt.asnumpy(res[0]))
11171124
assert_array_equal(dpt.asnumpy(y[:, 1, ...]), dpt.asnumpy(res[1]))
@@ -1124,7 +1131,7 @@ def test_unstack_axis2():
11241131
except dpctl.SyclDeviceCreationError:
11251132
pytest.skip("No SYCL devices available")
11261133
y = dpt.reshape(x_flat, (4, 5, 3))
1127-
res = dpt.unstack(y, 2)
1134+
res = dpt.unstack(y, axis=2)
11281135

11291136
assert_array_equal(dpt.asnumpy(y[:, :, 0, ...]), dpt.asnumpy(res[0]))
11301137
assert_array_equal(dpt.asnumpy(y[:, :, 1, ...]), dpt.asnumpy(res[1]))

0 commit comments

Comments
 (0)