33import json
44import os
55import re
6- from typing import TYPE_CHECKING
6+ from typing import TYPE_CHECKING , Any
77
88import pytest
99from packaging .version import parse as parse_version
1717
1818if 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
2429pytestmark = [
@@ -109,10 +114,13 @@ 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+ buf = await store .get ("foo" , prototype = default_buffer_prototype ())
118+ assert buf is not None
119+ assert buf .to_bytes () == data
113120 out = await store .get_partial_values (
114121 prototype = default_buffer_prototype (), key_ranges = [("foo" , OffsetByteRequest (1 ))]
115122 )
123+ assert out [0 ] is not None
116124 assert out [0 ].to_bytes () == data [1 :]
117125
118126
@@ -121,7 +129,7 @@ class TestFsspecStoreS3(StoreTests[FsspecStore, cpu.Buffer]):
121129 buffer_cls = cpu .Buffer
122130
123131 @pytest .fixture
124- def store_kwargs (self , request ) -> dict [str , str | bool ]:
132+ def store_kwargs (self ) -> dict [str , str | bool ]:
125133 try :
126134 from fsspec import url_to_fs
127135 except ImportError :
@@ -133,7 +141,7 @@ def store_kwargs(self, request) -> dict[str, str | bool]:
133141 return {"fs" : fs , "path" : path }
134142
135143 @pytest .fixture
136- def store (self , store_kwargs : dict [str , str | bool ]) -> FsspecStore :
144+ async def store (self , store_kwargs : dict [str , Any ]) -> FsspecStore :
137145 return self .store_cls (** store_kwargs )
138146
139147 async def get (self , store : FsspecStore , key : str ) -> Buffer :
@@ -168,7 +176,11 @@ async def test_fsspec_store_from_uri(self, store: FsspecStore) -> None:
168176 "anon" : False ,
169177 }
170178
171- meta = {"attributes" : {"key" : "value" }, "zarr_format" : 3 , "node_type" : "group" }
179+ meta : dict [str , JSON ] = {
180+ "attributes" : {"key" : "value" },
181+ "zarr_format" : 3 ,
182+ "node_type" : "group" ,
183+ }
172184
173185 await store .set (
174186 "zarr.json" ,
@@ -179,7 +191,7 @@ async def test_fsspec_store_from_uri(self, store: FsspecStore) -> None:
179191 )
180192 assert dict (group .attrs ) == {"key" : "value" }
181193
182- meta ["attributes" ]["key" ] = "value-2"
194+ meta ["attributes" ]["key" ] = "value-2" # type: ignore[index]
183195 await store .set (
184196 "directory-2/zarr.json" ,
185197 self .buffer_cls .from_bytes (json .dumps (meta ).encode ()),
@@ -189,7 +201,7 @@ async def test_fsspec_store_from_uri(self, store: FsspecStore) -> None:
189201 )
190202 assert dict (group .attrs ) == {"key" : "value-2" }
191203
192- meta ["attributes" ]["key" ] = "value-3"
204+ meta ["attributes" ]["key" ] = "value-3" # type: ignore[index]
193205 await store .set (
194206 "directory-3/zarr.json" ,
195207 self .buffer_cls .from_bytes (json .dumps (meta ).encode ()),
@@ -216,7 +228,7 @@ def test_from_upath(self) -> None:
216228 assert result .fs .asynchronous
217229 assert result .path == f"{ test_bucket_name } /foo/bar"
218230
219- def test_init_raises_if_path_has_scheme (self , store_kwargs ) -> None :
231+ def test_init_raises_if_path_has_scheme (self , store_kwargs : dict [ str , Any ] ) -> None :
220232 # regression test for https://github.com/zarr-developers/zarr-python/issues/2342
221233 store_kwargs ["path" ] = "s3://" + store_kwargs ["path" ]
222234 with pytest .raises (
@@ -237,7 +249,7 @@ def test_init_warns_if_fs_asynchronous_is_false(self) -> None:
237249 with pytest .warns (UserWarning , match = r".* was not created with `asynchronous=True`.*" ):
238250 self .store_cls (** store_kwargs )
239251
240- async def test_empty_nonexistent_path (self , store_kwargs ) -> None :
252+ async def test_empty_nonexistent_path (self , store_kwargs : dict [ str , Any ] ) -> None :
241253 # regression test for https://github.com/zarr-developers/zarr-python/pull/2343
242254 store_kwargs ["path" ] += "/abc"
243255 store = await self .store_cls .open (** store_kwargs )
@@ -256,7 +268,7 @@ async def test_delete_dir_unsupported_deletes(self, store: FsspecStore) -> None:
256268 parse_version (fsspec .__version__ ) < parse_version ("2024.12.0" ),
257269 reason = "No AsyncFileSystemWrapper" ,
258270)
259- def test_wrap_sync_filesystem ():
271+ def test_wrap_sync_filesystem () -> None :
260272 """The local fs is not async so we should expect it to be wrapped automatically"""
261273 from fsspec .implementations .asyn_wrapper import AsyncFileSystemWrapper
262274
@@ -270,7 +282,7 @@ def test_wrap_sync_filesystem():
270282 parse_version (fsspec .__version__ ) < parse_version ("2024.12.0" ),
271283 reason = "No AsyncFileSystemWrapper" ,
272284)
273- def test_no_wrap_async_filesystem ():
285+ def test_no_wrap_async_filesystem () -> None :
274286 """An async fs should not be wrapped automatically; fsspec's https filesystem is such an fs"""
275287 from fsspec .implementations .asyn_wrapper import AsyncFileSystemWrapper
276288
@@ -284,12 +296,12 @@ def test_no_wrap_async_filesystem():
284296 parse_version (fsspec .__version__ ) < parse_version ("2024.12.0" ),
285297 reason = "No AsyncFileSystemWrapper" ,
286298)
287- async def test_delete_dir_wrapped_filesystem (tmpdir ) -> None :
299+ async def test_delete_dir_wrapped_filesystem (tmp_path : Path ) -> None :
288300 from fsspec .implementations .asyn_wrapper import AsyncFileSystemWrapper
289301 from fsspec .implementations .local import LocalFileSystem
290302
291303 wrapped_fs = AsyncFileSystemWrapper (LocalFileSystem (auto_mkdir = True ))
292- store = FsspecStore (wrapped_fs , read_only = False , path = f"{ tmpdir } /test/path" )
304+ store = FsspecStore (wrapped_fs , read_only = False , path = f"{ tmp_path } /test/path" )
293305
294306 assert isinstance (store .fs , AsyncFileSystemWrapper )
295307 assert store .fs .asynchronous
0 commit comments