Skip to content

Commit 3e220e7

Browse files
committed
Fix typing in test_memory
1 parent 3c750ad commit 3e220e7

File tree

3 files changed

+28
-26
lines changed

3 files changed

+28
-26
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,8 @@ module = [
361361
"tests.test_config",
362362
"tests.test_store.test_zip",
363363
"tests.test_store.test_local",
364-
"tests.test_store.test_fsspec"
364+
"tests.test_store.test_fsspec",
365+
"tests.test_store.test_memory",
365366
]
366367
strict = false
367368

@@ -373,7 +374,6 @@ module = [
373374
"tests.test_metadata.*",
374375
"tests.test_store.test_core",
375376
"tests.test_store.test_logging",
376-
"tests.test_store.test_memory",
377377
"tests.test_store.test_object",
378378
"tests.test_store.test_stateful",
379379
"tests.test_store.test_wrapper",

src/zarr/testing/utils.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

3-
from collections.abc import Callable, Coroutine
4-
from typing import TYPE_CHECKING, Any, TypeVar, cast
3+
from typing import TYPE_CHECKING, TypeVar, cast
54

65
import pytest
76

@@ -38,13 +37,13 @@ def has_cupy() -> bool:
3837
return False
3938

4039

41-
T_Callable = TypeVar("T_Callable", bound=Callable[..., Coroutine[Any, Any, None] | None])
40+
T = TypeVar("T")
4241

4342

4443
# Decorator for GPU tests
45-
def gpu_test(func: T_Callable) -> T_Callable:
44+
def gpu_test(func: T) -> T:
4645
return cast(
47-
"T_Callable",
46+
"T",
4847
pytest.mark.gpu(
4948
pytest.mark.skipif(not has_cupy(), reason="CuPy not installed or no GPU available")(
5049
func

tests/test_store/test_memory.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
from __future__ import annotations
22

33
import re
4-
from typing import TYPE_CHECKING
4+
from typing import TYPE_CHECKING, Any
55

66
import numpy as np
7+
import numpy.typing as npt
78
import pytest
89

910
import zarr
11+
import zarr.core
12+
import zarr.core.array
1013
from zarr.core.buffer import Buffer, cpu, gpu
1114
from zarr.storage import GpuMemoryStore, MemoryStore
1215
from zarr.testing.store import StoreTests
@@ -31,16 +34,16 @@ async def get(self, store: MemoryStore, key: str) -> Buffer:
3134
return store._store_dict[key]
3235

3336
@pytest.fixture(params=[None, True])
34-
def store_kwargs(
35-
self, request: pytest.FixtureRequest
36-
) -> dict[str, str | dict[str, Buffer] | None]:
37-
kwargs = {"store_dict": None}
37+
def store_kwargs(self, request: pytest.FixtureRequest) -> dict[str, Any]:
38+
kwargs: dict[str, Any]
3839
if request.param is True:
39-
kwargs["store_dict"] = {}
40+
kwargs = {"store_dict": {}}
41+
else:
42+
kwargs = {"store_dict": None}
4043
return kwargs
4144

4245
@pytest.fixture
43-
def store(self, store_kwargs: str | dict[str, Buffer] | None) -> MemoryStore:
46+
async def store(self, store_kwargs: dict[str, Any]) -> MemoryStore:
4447
return self.store_cls(**store_kwargs)
4548

4649
def test_store_repr(self, store: MemoryStore) -> None:
@@ -55,13 +58,13 @@ def test_store_supports_listing(self, store: MemoryStore) -> None:
5558
def test_store_supports_partial_writes(self, store: MemoryStore) -> None:
5659
assert store.supports_partial_writes
5760

58-
def test_list_prefix(self, store: MemoryStore) -> None:
61+
async def test_list_prefix(self, store: MemoryStore) -> None:
5962
assert True
6063

6164
@pytest.mark.parametrize("dtype", ["uint8", "float32", "int64"])
6265
@pytest.mark.parametrize("zarr_format", [2, 3])
6366
async def test_deterministic_size(
64-
self, store: MemoryStore, dtype, zarr_format: ZarrFormat
67+
self, store: MemoryStore, dtype: npt.DTypeLike, zarr_format: ZarrFormat
6568
) -> None:
6669
a = zarr.empty(
6770
store=store,
@@ -85,23 +88,23 @@ class TestGpuMemoryStore(StoreTests[GpuMemoryStore, gpu.Buffer]):
8588
store_cls = GpuMemoryStore
8689
buffer_cls = gpu.Buffer
8790

88-
async def set(self, store: GpuMemoryStore, key: str, value: Buffer) -> None:
91+
async def set(self, store: GpuMemoryStore, key: str, value: gpu.Buffer) -> None: # type: ignore[override]
8992
store._store_dict[key] = value
9093

9194
async def get(self, store: MemoryStore, key: str) -> Buffer:
9295
return store._store_dict[key]
9396

9497
@pytest.fixture(params=[None, True])
95-
def store_kwargs(
96-
self, request: pytest.FixtureRequest
97-
) -> dict[str, str | dict[str, Buffer] | None]:
98-
kwargs = {"store_dict": None}
98+
def store_kwargs(self, request: pytest.FixtureRequest) -> dict[str, Any]:
99+
kwargs: dict[str, Any]
99100
if request.param is True:
100-
kwargs["store_dict"] = {}
101+
kwargs = {"store_dict": {}}
102+
else:
103+
kwargs = {"store_dict": None}
101104
return kwargs
102105

103106
@pytest.fixture
104-
def store(self, store_kwargs: str | dict[str, gpu.Buffer] | None) -> GpuMemoryStore:
107+
async def store(self, store_kwargs: dict[str, Any]) -> GpuMemoryStore:
105108
return self.store_cls(**store_kwargs)
106109

107110
def test_store_repr(self, store: GpuMemoryStore) -> None:
@@ -116,15 +119,15 @@ def test_store_supports_listing(self, store: GpuMemoryStore) -> None:
116119
def test_store_supports_partial_writes(self, store: GpuMemoryStore) -> None:
117120
assert store.supports_partial_writes
118121

119-
def test_list_prefix(self, store: GpuMemoryStore) -> None:
122+
async def test_list_prefix(self, store: GpuMemoryStore) -> None:
120123
assert True
121124

122125
def test_dict_reference(self, store: GpuMemoryStore) -> None:
123-
store_dict = {}
126+
store_dict: dict[str, Any] = {}
124127
result = GpuMemoryStore(store_dict=store_dict)
125128
assert result._store_dict is store_dict
126129

127-
def test_from_dict(self):
130+
def test_from_dict(self) -> None:
128131
d = {
129132
"a": gpu.Buffer.from_bytes(b"aaaa"),
130133
"b": cpu.Buffer.from_bytes(b"bbbb"),

0 commit comments

Comments
 (0)