Skip to content

Commit 3c750ad

Browse files
committed
Fix test_fsspec
1 parent a6bd0a2 commit 3c750ad

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ module = [
361361
"tests.test_config",
362362
"tests.test_store.test_zip",
363363
"tests.test_store.test_local",
364+
"tests.test_store.test_fsspec"
364365
]
365366
strict = false
366367

@@ -371,7 +372,6 @@ module = [
371372
"tests.test_codecs.test_codecs",
372373
"tests.test_metadata.*",
373374
"tests.test_store.test_core",
374-
"tests.test_store.test_fsspec",
375375
"tests.test_store.test_logging",
376376
"tests.test_store.test_memory",
377377
"tests.test_store.test_object",

tests/test_store/test_fsspec.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import json
44
import os
55
import re
6-
from typing import TYPE_CHECKING
6+
from typing import TYPE_CHECKING, Any
77

88
import pytest
99
from packaging.version import parse as parse_version
@@ -17,8 +17,13 @@
1717

1818
if TYPE_CHECKING:
1919
from collections.abc import Generator
20+
from pathlib import Path
2021

2122
import botocore.client
23+
import s3fs
24+
25+
from zarr.core.common import JSON
26+
2227

2328
# Warning filter due to https://github.com/boto/boto3/issues/3889
2429
pytestmark = [
@@ -109,10 +114,12 @@ async def test_basic() -> None:
109114
data = b"hello"
110115
await store.set("foo", cpu.Buffer.from_bytes(data))
111116
assert await store.exists("foo")
112-
assert (await store.get("foo", prototype=default_buffer_prototype())).to_bytes() == data
117+
assert (buf := (await store.get("foo", prototype=default_buffer_prototype()))) is not None
118+
assert buf.to_bytes() == data
113119
out = await store.get_partial_values(
114120
prototype=default_buffer_prototype(), key_ranges=[("foo", OffsetByteRequest(1))]
115121
)
122+
assert out[0] is not None
116123
assert out[0].to_bytes() == data[1:]
117124

118125

@@ -121,7 +128,7 @@ class TestFsspecStoreS3(StoreTests[FsspecStore, cpu.Buffer]):
121128
buffer_cls = cpu.Buffer
122129

123130
@pytest.fixture
124-
def store_kwargs(self, request) -> dict[str, str | bool]:
131+
def store_kwargs(self) -> dict[str, str | bool]:
125132
try:
126133
from fsspec import url_to_fs
127134
except ImportError:
@@ -133,7 +140,7 @@ def store_kwargs(self, request) -> dict[str, str | bool]:
133140
return {"fs": fs, "path": path}
134141

135142
@pytest.fixture
136-
def store(self, store_kwargs: dict[str, str | bool]) -> FsspecStore:
143+
async def store(self, store_kwargs: dict[str, Any]) -> FsspecStore:
137144
return self.store_cls(**store_kwargs)
138145

139146
async def get(self, store: FsspecStore, key: str) -> Buffer:
@@ -168,7 +175,11 @@ async def test_fsspec_store_from_uri(self, store: FsspecStore) -> None:
168175
"anon": False,
169176
}
170177

171-
meta = {"attributes": {"key": "value"}, "zarr_format": 3, "node_type": "group"}
178+
meta: dict[str, JSON] = {
179+
"attributes": {"key": "value"},
180+
"zarr_format": 3,
181+
"node_type": "group",
182+
}
172183

173184
await store.set(
174185
"zarr.json",
@@ -179,7 +190,7 @@ async def test_fsspec_store_from_uri(self, store: FsspecStore) -> None:
179190
)
180191
assert dict(group.attrs) == {"key": "value"}
181192

182-
meta["attributes"]["key"] = "value-2"
193+
meta["attributes"]["key"] = "value-2" # type: ignore[index]
183194
await store.set(
184195
"directory-2/zarr.json",
185196
self.buffer_cls.from_bytes(json.dumps(meta).encode()),
@@ -189,7 +200,7 @@ async def test_fsspec_store_from_uri(self, store: FsspecStore) -> None:
189200
)
190201
assert dict(group.attrs) == {"key": "value-2"}
191202

192-
meta["attributes"]["key"] = "value-3"
203+
meta["attributes"]["key"] = "value-3" # type: ignore[index]
193204
await store.set(
194205
"directory-3/zarr.json",
195206
self.buffer_cls.from_bytes(json.dumps(meta).encode()),
@@ -216,7 +227,7 @@ def test_from_upath(self) -> None:
216227
assert result.fs.asynchronous
217228
assert result.path == f"{test_bucket_name}/foo/bar"
218229

219-
def test_init_raises_if_path_has_scheme(self, store_kwargs) -> None:
230+
def test_init_raises_if_path_has_scheme(self, store_kwargs: dict[str, Any]) -> None:
220231
# regression test for https://github.com/zarr-developers/zarr-python/issues/2342
221232
store_kwargs["path"] = "s3://" + store_kwargs["path"]
222233
with pytest.raises(
@@ -237,7 +248,7 @@ def test_init_warns_if_fs_asynchronous_is_false(self) -> None:
237248
with pytest.warns(UserWarning, match=r".* was not created with `asynchronous=True`.*"):
238249
self.store_cls(**store_kwargs)
239250

240-
async def test_empty_nonexistent_path(self, store_kwargs) -> None:
251+
async def test_empty_nonexistent_path(self, store_kwargs: dict[str, Any]) -> None:
241252
# regression test for https://github.com/zarr-developers/zarr-python/pull/2343
242253
store_kwargs["path"] += "/abc"
243254
store = await self.store_cls.open(**store_kwargs)
@@ -256,7 +267,7 @@ async def test_delete_dir_unsupported_deletes(self, store: FsspecStore) -> None:
256267
parse_version(fsspec.__version__) < parse_version("2024.12.0"),
257268
reason="No AsyncFileSystemWrapper",
258269
)
259-
def test_wrap_sync_filesystem():
270+
def test_wrap_sync_filesystem() -> None:
260271
"""The local fs is not async so we should expect it to be wrapped automatically"""
261272
from fsspec.implementations.asyn_wrapper import AsyncFileSystemWrapper
262273

@@ -270,7 +281,7 @@ def test_wrap_sync_filesystem():
270281
parse_version(fsspec.__version__) < parse_version("2024.12.0"),
271282
reason="No AsyncFileSystemWrapper",
272283
)
273-
def test_no_wrap_async_filesystem():
284+
def test_no_wrap_async_filesystem() -> None:
274285
"""An async fs should not be wrapped automatically; fsspec's https filesystem is such an fs"""
275286
from fsspec.implementations.asyn_wrapper import AsyncFileSystemWrapper
276287

@@ -284,12 +295,12 @@ def test_no_wrap_async_filesystem():
284295
parse_version(fsspec.__version__) < parse_version("2024.12.0"),
285296
reason="No AsyncFileSystemWrapper",
286297
)
287-
async def test_delete_dir_wrapped_filesystem(tmpdir) -> None:
298+
async def test_delete_dir_wrapped_filesystem(tmp_path: Path) -> None:
288299
from fsspec.implementations.asyn_wrapper import AsyncFileSystemWrapper
289300
from fsspec.implementations.local import LocalFileSystem
290301

291302
wrapped_fs = AsyncFileSystemWrapper(LocalFileSystem(auto_mkdir=True))
292-
store = FsspecStore(wrapped_fs, read_only=False, path=f"{tmpdir}/test/path")
303+
store = FsspecStore(wrapped_fs, read_only=False, path=f"{tmp_path}/test/path")
293304

294305
assert isinstance(store.fs, AsyncFileSystemWrapper)
295306
assert store.fs.asynchronous

0 commit comments

Comments
 (0)