Skip to content

Commit abbdbf2

Browse files
Apply ruff/flake8-pytest-style rule PT030 (#3270)
PT030 `pytest.warns(UserWarning)` is too broad, set the `match` parameter or use a more specific warning
1 parent 80d4f36 commit abbdbf2

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-11
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ extend-select = [
324324
ignore = [
325325
"ANN401",
326326
"PT011", # TODO: apply this rule
327-
"PT030", # TODO: apply this rule
328327
"RET505",
329328
"RET506",
330329
"RUF005",

tests/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ def test_tree() -> None:
470470
g3.create_group("baz")
471471
g5 = g3.create_group("qux")
472472
g5.create_array("baz", shape=(100,), chunks=(10,), dtype="float64")
473-
with pytest.warns(DeprecationWarning): # noqa: PT031
473+
with pytest.warns(DeprecationWarning, match=r"Group\.tree instead\."): # noqa: PT031
474474
assert repr(zarr.tree(g1)) == repr(g1.tree())
475475
assert str(zarr.tree(g1)) == str(g1.tree())
476476

tests/test_codecs/test_codecs.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,10 @@ def test_invalid_metadata(store: Store) -> None:
355355
],
356356
)
357357
spath7 = StorePath(store, "warning_inefficient_codecs")
358-
with pytest.warns(UserWarning):
358+
with pytest.warns(
359+
UserWarning,
360+
match="Combining a `sharding_indexed` codec disables partial reads and writes, which may lead to inefficient performance",
361+
):
359362
Array.create(
360363
spath7,
361364
shape=(16, 16),
@@ -372,7 +375,10 @@ def test_invalid_metadata(store: Store) -> None:
372375
@pytest.mark.parametrize("store", ["local", "memory"], indirect=["store"])
373376
def test_invalid_metadata_create_array(store: Store) -> None:
374377
spath = StorePath(store, "warning_inefficient_codecs")
375-
with pytest.warns(UserWarning):
378+
with pytest.warns(
379+
UserWarning,
380+
match="codec disables partial reads and writes, which may lead to inefficient performance",
381+
):
376382
zarr.create_array(
377383
spath,
378384
shape=(16, 16),

tests/test_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ class NewCodec2(BytesCodec):
287287

288288
# warning because multiple implementations are available but none is selected in the config
289289
register_codec("new_codec", NewCodec2)
290-
with pytest.warns(UserWarning):
290+
with pytest.warns(UserWarning, match="not configured in config. Selecting any implementation"):
291291
get_codec_class("new_codec")
292292

293293
# no warning if multiple implementations are available and one is selected in the config

tests/test_group.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ def test_group_create_array(
648648
array = group.create_array(name=name, shape=shape, dtype=dtype)
649649
array[:] = data
650650
elif method == "array":
651-
with pytest.warns(DeprecationWarning):
651+
with pytest.warns(DeprecationWarning, match=r"Group\.create_array instead\."):
652652
array = group.array(name=name, data=data, shape=shape, dtype=dtype)
653653
else:
654654
raise AssertionError
@@ -660,7 +660,7 @@ def test_group_create_array(
660660
a[:] = data
661661
elif method == "array":
662662
with pytest.raises(ContainsArrayError): # noqa: PT012
663-
with pytest.warns(DeprecationWarning):
663+
with pytest.warns(DeprecationWarning, match=r"Group\.create_array instead\."):
664664
a = group.array(name=name, shape=shape, dtype=dtype)
665665
a[:] = data
666666

@@ -1184,22 +1184,28 @@ def test_create_dataset_with_data(store: Store, zarr_format: ZarrFormat) -> None
11841184
"""
11851185
root = Group.from_store(store=store, zarr_format=zarr_format)
11861186
arr = np.random.random((5, 5))
1187-
with pytest.warns(DeprecationWarning):
1187+
with pytest.warns(DeprecationWarning, match=r"Group\.create_array instead\."):
11881188
data = root.create_dataset("random", data=arr, shape=arr.shape)
11891189
np.testing.assert_array_equal(np.asarray(data), arr)
11901190

11911191

11921192
async def test_create_dataset(store: Store, zarr_format: ZarrFormat) -> None:
11931193
root = await AsyncGroup.from_store(store=store, zarr_format=zarr_format)
1194-
with pytest.warns(DeprecationWarning):
1194+
with pytest.warns(DeprecationWarning, match=r"Group\.create_array instead\."):
11951195
foo = await root.create_dataset("foo", shape=(10,), dtype="uint8")
11961196
assert foo.shape == (10,)
11971197

1198-
with pytest.raises(ContainsArrayError), pytest.warns(DeprecationWarning):
1198+
with (
1199+
pytest.raises(ContainsArrayError),
1200+
pytest.warns(DeprecationWarning, match=r"Group\.create_array instead\."),
1201+
):
11991202
await root.create_dataset("foo", shape=(100,), dtype="int8")
12001203

12011204
_ = await root.create_group("bar")
1202-
with pytest.raises(ContainsGroupError), pytest.warns(DeprecationWarning):
1205+
with (
1206+
pytest.raises(ContainsGroupError),
1207+
pytest.warns(DeprecationWarning, match=r"Group\.create_array instead\."),
1208+
):
12031209
await root.create_dataset("bar", shape=(100,), dtype="int8")
12041210

12051211

0 commit comments

Comments
 (0)