Skip to content

Commit 3732d13

Browse files
committed
TST: Less redundant skip_xp_backends
1 parent c608062 commit 3732d13

File tree

5 files changed

+29
-41
lines changed

5 files changed

+29
-41
lines changed

tests/conftest.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ def library(request: pytest.FixtureRequest) -> Backend: # numpydoc ignore=PR01,
3636
msg = "argument of skip_xp_backend must be a Backend enum"
3737
raise TypeError(msg)
3838
if skip_library == elem:
39-
reason = cast(str, marker.kwargs.get("reason", "skip_xp_backend"))
39+
reason = skip_library.value
40+
try:
41+
reason += ":" + cast(str, marker.kwargs["reason"])
42+
except KeyError:
43+
pass
4044
pytest.skip(reason=reason)
4145

4246
return elem

tests/test_at.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def assert_copy(array: Array, copy: bool | None) -> Generator[None, None, None]:
3131

3232

3333
@pytest.mark.skip_xp_backend(
34-
Backend.SPARSE, reason="sparse:read-only backend without .at support"
34+
Backend.SPARSE, reason="read-only backend without .at support"
3535
)
3636
@pytest.mark.parametrize(
3737
("kwargs", "expect_copy"),

tests/test_funcs.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
# mypy: disable-error-code=no-untyped-usage
2727

2828

29-
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="sparse:no expand_dims")
29+
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no expand_dims")
3030
class TestAtLeastND:
3131
def test_0D(self, xp: ModuleType):
3232
x = xp.asarray(1.0)
@@ -98,7 +98,7 @@ def test_xp(self, xp: ModuleType):
9898
xp_assert_equal(y, x)
9999

100100

101-
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="sparse:no isdtype")
101+
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no isdtype")
102102
class TestCov:
103103
def test_basic(self, xp: ModuleType):
104104
xp_assert_close(
@@ -137,17 +137,15 @@ def test_device(self, xp: ModuleType, device: Device):
137137
x = xp.asarray([1, 2, 3], device=device)
138138
assert get_device(cov(x)) == device
139139

140-
@pytest.mark.skip_xp_backend(
141-
Backend.NUMPY_READONLY, reason="numpy_readonly:explicit xp"
142-
)
140+
@pytest.mark.skip_xp_backend(Backend.NUMPY_READONLY, reason="explicit xp")
143141
def test_xp(self, xp: ModuleType):
144142
xp_assert_close(
145143
cov(xp.asarray([[0.0, 2.0], [1.0, 1.0], [2.0, 0.0]]).T, xp=xp),
146144
xp.asarray([[1.0, -1.0], [-1.0, 1.0]], dtype=xp.float64),
147145
)
148146

149147

150-
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="sparse:no device kwarg in asarray")
148+
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no device")
151149
class TestCreateDiagonal:
152150
def test_1d(self, xp: ModuleType):
153151
# from np.diag tests
@@ -193,10 +191,10 @@ def test_xp(self, xp: ModuleType):
193191
xp_assert_equal(y, xp.asarray([[1, 0], [0, 2]]))
194192

195193

196-
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="sparse:no expand_dims")
194+
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no expand_dims")
197195
class TestExpandDims:
198-
@pytest.mark.skip_xp_backend(Backend.DASK, reason="dask:tuple index out of range")
199-
@pytest.mark.skip_xp_backend(Backend.TORCH, reason="torch:tuple index out of range")
196+
@pytest.mark.skip_xp_backend(Backend.DASK, reason="tuple index out of range")
197+
@pytest.mark.skip_xp_backend(Backend.TORCH, reason="tuple index out of range")
200198
def test_functionality(self, xp: ModuleType):
201199
def _squeeze_all(b: Array) -> Array:
202200
"""Mimics `np.squeeze(b)`. `xpx.squeeze`?"""
@@ -254,7 +252,7 @@ def test_xp(self, xp: ModuleType):
254252
assert y.shape == (1, 1, 1, 3)
255253

256254

257-
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="sparse:no expand_dims")
255+
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no expand_dims")
258256
class TestKron:
259257
def test_basic(self, xp: ModuleType):
260258
# Using 0-dimensional array
@@ -351,9 +349,7 @@ def test_xp(self, xp: ModuleType):
351349
xp_assert_equal(nunique(a, xp=xp), xp.asarray(3))
352350

353351

354-
@pytest.mark.skip_xp_backend(
355-
Backend.SPARSE, reason="sparse:no arange, no device kwarg in asarray"
356-
)
352+
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no arange, no device")
357353
class TestPad:
358354
def test_simple(self, xp: ModuleType):
359355
a = xp.arange(1, 4)
@@ -403,8 +399,8 @@ def test_list_of_tuples_width(self, xp: ModuleType):
403399
assert padded.shape == (4, 4)
404400

405401

406-
@pytest.mark.skip_xp_backend(Backend.DASK, reason="dask:no argsort")
407-
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="sparse:no device kwarg in asarray")
402+
@pytest.mark.skip_xp_backend(Backend.DASK, reason="no argsort")
403+
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no device kwarg in asarray")
408404
class TestSetDiff1D:
409405
@pytest.mark.skip_xp_backend(
410406
Backend.TORCH, reason="index_select not implemented for uint32"
@@ -440,9 +436,7 @@ def test_device(self, xp: ModuleType, device: Device):
440436
x2 = xp.asarray([2, 3, 4], device=device)
441437
assert get_device(setdiff1d(x1, x2)) == device
442438

443-
@pytest.mark.skip_xp_backend(
444-
Backend.NUMPY_READONLY, reason="numpy_readonly:explicit xp"
445-
)
439+
@pytest.mark.skip_xp_backend(Backend.NUMPY_READONLY, reason="explicit xp")
446440
def test_xp(self, xp: ModuleType):
447441
x1 = xp.asarray([3, 8, 20])
448442
x2 = xp.asarray([2, 3, 4])
@@ -451,7 +445,7 @@ def test_xp(self, xp: ModuleType):
451445
xp_assert_equal(actual, expected)
452446

453447

454-
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="sparse:no isdtype")
448+
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no isdtype")
455449
class TestSinc:
456450
def test_simple(self, xp: ModuleType):
457451
xp_assert_equal(sinc(xp.asarray(0.0)), xp.asarray(1.0))

tests/test_testing.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
xp_assert_equal,
1818
pytest.param(
1919
xp_assert_close,
20-
marks=pytest.mark.skip_xp_backend(
21-
Backend.SPARSE, reason="sparse:no isdtype"
22-
),
20+
marks=pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no isdtype"),
2321
),
2422
],
2523
)
@@ -40,19 +38,15 @@ def test_assert_close_equal_basic(xp: ModuleType, func: Callable[..., None]): #
4038
func(xp.asarray([1, 2]), xp.asarray([1, 3]), err_msg="hello")
4139

4240

43-
@pytest.mark.skip_xp_backend(Backend.NUMPY, reason="numpy:test other ns vs. numpy")
44-
@pytest.mark.skip_xp_backend(
45-
Backend.NUMPY_READONLY, reason="numpy_readonly:test other ns vs. numpy"
46-
)
41+
@pytest.mark.skip_xp_backend(Backend.NUMPY, reason="test other ns vs. numpy")
42+
@pytest.mark.skip_xp_backend(Backend.NUMPY_READONLY, reason="test other ns vs. numpy")
4743
@pytest.mark.parametrize(
4844
"func",
4945
[
5046
xp_assert_equal,
5147
pytest.param(
5248
xp_assert_close,
53-
marks=pytest.mark.skip_xp_backend(
54-
Backend.SPARSE, reason="sparse:no isdtype"
55-
),
49+
marks=pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no isdtype"),
5650
),
5751
],
5852
)
@@ -65,7 +59,7 @@ def test_assert_close_equal_namespace(xp: ModuleType, func: Callable[..., None])
6559
func(xp.asarray([0]), [0])
6660

6761

68-
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="sparse:no isdtype")
62+
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no isdtype")
6963
def test_assert_close_tolerance(xp: ModuleType):
7064
xp_assert_close(xp.asarray([100.0]), xp.asarray([102.0]), rtol=0.03)
7165
with pytest.raises(AssertionError):

tests/test_utils.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313

1414
class TestIn1D:
15-
@pytest.mark.skip_xp_backend(Backend.DASK, reason="dask:no argsort")
15+
@pytest.mark.skip_xp_backend(Backend.DASK, reason="no argsort")
1616
@pytest.mark.skip_xp_backend(
17-
Backend.SPARSE, reason="sparse:no unique_inverse, no device kwarg in asarray"
17+
Backend.SPARSE, reason="no unique_inverse, no device kwarg in asarray"
1818
)
1919
# cover both code paths
2020
@pytest.mark.parametrize("n", [9, 15])
@@ -25,19 +25,15 @@ def test_no_invert_assume_unique(self, xp: ModuleType, n: int):
2525
actual = in1d(x1, x2)
2626
xp_assert_equal(actual, expected)
2727

28-
@pytest.mark.skip_xp_backend(
29-
Backend.SPARSE, reason="sparse: no device kwarg in asarray"
30-
)
28+
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no device kwarg in asarray")
3129
def test_device(self, xp: ModuleType, device: Device):
3230
x1 = xp.asarray([3, 8, 20], device=device)
3331
x2 = xp.asarray([2, 3, 4], device=device)
3432
assert get_device(in1d(x1, x2)) == device
3533

34+
@pytest.mark.skip_xp_backend(Backend.NUMPY_READONLY, reason="explicit xp")
3635
@pytest.mark.skip_xp_backend(
37-
Backend.NUMPY_READONLY, reason="numpy_readonly:explicit xp"
38-
)
39-
@pytest.mark.skip_xp_backend(
40-
Backend.SPARSE, reason="sparse:no arange, no device kwarg in asarray"
36+
Backend.SPARSE, reason="no arange, no device kwarg in asarray"
4137
)
4238
def test_xp(self, xp: ModuleType):
4339
x1 = xp.asarray([1, 6])

0 commit comments

Comments
 (0)