Skip to content

Commit 97d3137

Browse files
committed
Fix typing in test_core
1 parent 6a546d6 commit 97d3137

File tree

2 files changed

+33
-19
lines changed

2 files changed

+33
-19
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ module = [
352352
"tests.test_store.test_fsspec",
353353
"tests.test_store.test_memory",
354354
"tests.test_codecs.test_codecs",
355+
"tests.test_store.test_core",
355356
]
356357
strict = false
357358

@@ -360,7 +361,6 @@ strict = false
360361
[[tool.mypy.overrides]]
361362
module = [
362363
"tests.test_metadata.*",
363-
"tests.test_store.test_core",
364364
"tests.test_store.test_logging",
365365
"tests.test_store.test_object",
366366
"tests.test_store.test_stateful",

tests/test_store/test_core.py

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import tempfile
2+
from collections.abc import Callable, Generator
23
from pathlib import Path
4+
from typing import Any, Literal
35

46
import pytest
57
from _pytest.compat import LEGACY_PATH
@@ -21,7 +23,9 @@
2123
@pytest.fixture(
2224
params=["none", "temp_dir_str", "temp_dir_path", "store_path", "memory_store", "dict"]
2325
)
24-
def store_like(request):
26+
def store_like(
27+
request: pytest.FixtureRequest,
28+
) -> Generator[None | str | Path | StorePath | MemoryStore | dict[Any, Any], None, None]:
2529
if request.param == "none":
2630
yield None
2731
elif request.param == "temp_dir_str":
@@ -42,7 +46,7 @@ def store_like(request):
4246
@pytest.mark.parametrize("write_group", [True, False])
4347
@pytest.mark.parametrize("zarr_format", [2, 3])
4448
async def test_contains_group(
45-
local_store, path: str, write_group: bool, zarr_format: ZarrFormat
49+
local_store: LocalStore, path: str, write_group: bool, zarr_format: ZarrFormat
4650
) -> None:
4751
"""
4852
Test that the contains_group method correctly reports the existence of a group.
@@ -58,7 +62,7 @@ async def test_contains_group(
5862
@pytest.mark.parametrize("write_array", [True, False])
5963
@pytest.mark.parametrize("zarr_format", [2, 3])
6064
async def test_contains_array(
61-
local_store, path: str, write_array: bool, zarr_format: ZarrFormat
65+
local_store: LocalStore, path: str, write_array: bool, zarr_format: ZarrFormat
6266
) -> None:
6367
"""
6468
Test that the contains array method correctly reports the existence of an array.
@@ -71,13 +75,15 @@ async def test_contains_array(
7175

7276

7377
@pytest.mark.parametrize("func", [contains_array, contains_group])
74-
async def test_contains_invalid_format_raises(local_store, func: callable) -> None:
78+
async def test_contains_invalid_format_raises(
79+
local_store: LocalStore, func: Callable[[Any], Any]
80+
) -> None:
7581
"""
7682
Test contains_group and contains_array raise errors for invalid zarr_formats
7783
"""
7884
store_path = StorePath(local_store)
7985
with pytest.raises(ValueError):
80-
assert await func(store_path, zarr_format="3.0")
86+
assert await func(store_path, zarr_format="3.0") # type: ignore[call-arg]
8187

8288

8389
@pytest.mark.parametrize("path", [None, "", "bar"])
@@ -113,40 +119,48 @@ async def test_make_store_path_local(
113119
@pytest.mark.parametrize("path", [None, "", "bar"])
114120
@pytest.mark.parametrize("mode", ["r", "w"])
115121
async def test_make_store_path_store_path(
116-
tmpdir: LEGACY_PATH, path: str, mode: AccessModeLiteral
122+
tmp_path: Path, path: str, mode: AccessModeLiteral
117123
) -> None:
118124
"""
119125
Test invoking make_store_path when the input is another store_path. In particular we want to ensure
120126
that a new path is handled correctly.
121127
"""
122128
ro = mode == "r"
123-
store_like = await StorePath.open(LocalStore(str(tmpdir), read_only=ro), path="root", mode=mode)
129+
store_like = await StorePath.open(
130+
LocalStore(str(tmp_path), read_only=ro), path="root", mode=mode
131+
)
124132
store_path = await make_store_path(store_like, path=path, mode=mode)
125133
assert isinstance(store_path.store, LocalStore)
126-
assert Path(store_path.store.root) == Path(tmpdir)
134+
assert Path(store_path.store.root) == tmp_path
127135
path_normalized = normalize_path(path)
128136
assert store_path.path == (store_like / path_normalized).path
129137
assert store_path.read_only == ro
130138

131139

132140
@pytest.mark.parametrize("modes", [(True, "w"), (False, "x")])
133-
async def test_store_path_invalid_mode_raises(tmpdir: LEGACY_PATH, modes: tuple) -> None:
141+
async def test_store_path_invalid_mode_raises(
142+
tmp_path: Path, modes: tuple[bool, Literal["w", "x"]]
143+
) -> None:
134144
"""
135145
Test that ValueErrors are raise for invalid mode.
136146
"""
137147
with pytest.raises(ValueError):
138-
await StorePath.open(LocalStore(str(tmpdir), read_only=modes[0]), path=None, mode=modes[1])
148+
await StorePath.open(
149+
LocalStore(str(tmp_path), read_only=modes[0]),
150+
path="",
151+
mode=modes[1], # type:ignore[arg-type]
152+
)
139153

140154

141155
async def test_make_store_path_invalid() -> None:
142156
"""
143157
Test that invalid types raise TypeError
144158
"""
145159
with pytest.raises(TypeError):
146-
await make_store_path(1) # type: ignore[arg-type]
160+
await make_store_path(1)
147161

148162

149-
async def test_make_store_path_fsspec(monkeypatch) -> None:
163+
async def test_make_store_path_fsspec() -> None:
150164
pytest.importorskip("fsspec")
151165
pytest.importorskip("requests")
152166
pytest.importorskip("aiohttp")
@@ -161,7 +175,7 @@ async def test_make_store_path_storage_options_raises(store_like: StoreLike) ->
161175

162176
async def test_unsupported() -> None:
163177
with pytest.raises(TypeError, match="Unsupported type for store_like: 'int'"):
164-
await make_store_path(1) # type: ignore[arg-type]
178+
await make_store_path(1)
165179

166180

167181
@pytest.mark.parametrize(
@@ -184,12 +198,12 @@ def test_normalize_path_upath() -> None:
184198
assert normalize_path(upath.UPath("foo/bar")) == "foo/bar"
185199

186200

187-
def test_normalize_path_none():
201+
def test_normalize_path_none() -> None:
188202
assert normalize_path(None) == ""
189203

190204

191205
@pytest.mark.parametrize("path", [".", ".."])
192-
def test_normalize_path_invalid(path: str):
206+
def test_normalize_path_invalid(path: str) -> None:
193207
with pytest.raises(ValueError):
194208
normalize_path(path)
195209

@@ -230,7 +244,7 @@ def test_invalid(paths: tuple[str, str]) -> None:
230244
_normalize_paths(paths)
231245

232246

233-
def test_normalize_path_keys():
247+
def test_normalize_path_keys() -> None:
234248
"""
235249
Test that ``_normalize_path_keys`` just applies the normalize_path function to each key of its
236250
input
@@ -272,10 +286,10 @@ def test_different_open_mode(tmp_path: LEGACY_PATH) -> None:
272286

273287
# Test with a store that doesn't implement .with_read_only()
274288
zarr_path = tmp_path / "foo.zarr"
275-
store = ZipStore(zarr_path, mode="w")
289+
zip_store = ZipStore(zarr_path, mode="w")
276290
zarr.create((100,), store=store, zarr_format=2, path="a")
277291
with pytest.raises(
278292
ValueError,
279293
match="Store is not read-only but mode is 'r'. Unable to create a read-only copy of the store. Please use a read-only store or a storage class that implements .with_read_only().",
280294
):
281-
zarr.open_array(store=store, path="a", zarr_format=2, mode="r")
295+
zarr.open_array(store=zip_store, path="a", zarr_format=2, mode="r")

0 commit comments

Comments
 (0)