3
3
import json
4
4
import os
5
5
import re
6
- from typing import TYPE_CHECKING
6
+ from typing import TYPE_CHECKING , Any
7
7
8
8
import pytest
9
9
from packaging .version import parse as parse_version
17
17
18
18
if TYPE_CHECKING :
19
19
from collections .abc import Generator
20
+ from pathlib import Path
20
21
21
22
import botocore .client
23
+ import s3fs
24
+
25
+ from zarr .core .common import JSON
26
+
22
27
23
28
# Warning filter due to https://github.com/boto/boto3/issues/3889
24
29
pytestmark = [
@@ -109,10 +114,13 @@ async def test_basic() -> None:
109
114
data = b"hello"
110
115
await store .set ("foo" , cpu .Buffer .from_bytes (data ))
111
116
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
113
120
out = await store .get_partial_values (
114
121
prototype = default_buffer_prototype (), key_ranges = [("foo" , OffsetByteRequest (1 ))]
115
122
)
123
+ assert out [0 ] is not None
116
124
assert out [0 ].to_bytes () == data [1 :]
117
125
118
126
@@ -121,7 +129,7 @@ class TestFsspecStoreS3(StoreTests[FsspecStore, cpu.Buffer]):
121
129
buffer_cls = cpu .Buffer
122
130
123
131
@pytest .fixture
124
- def store_kwargs (self , request ) -> dict [str , str | bool ]:
132
+ def store_kwargs (self ) -> dict [str , str | bool ]:
125
133
try :
126
134
from fsspec import url_to_fs
127
135
except ImportError :
@@ -133,7 +141,7 @@ def store_kwargs(self, request) -> dict[str, str | bool]:
133
141
return {"fs" : fs , "path" : path }
134
142
135
143
@pytest .fixture
136
- def store (self , store_kwargs : dict [str , str | bool ]) -> FsspecStore :
144
+ async def store (self , store_kwargs : dict [str , Any ]) -> FsspecStore :
137
145
return self .store_cls (** store_kwargs )
138
146
139
147
async def get (self , store : FsspecStore , key : str ) -> Buffer :
@@ -168,7 +176,11 @@ async def test_fsspec_store_from_uri(self, store: FsspecStore) -> None:
168
176
"anon" : False ,
169
177
}
170
178
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
+ }
172
184
173
185
await store .set (
174
186
"zarr.json" ,
@@ -179,7 +191,7 @@ async def test_fsspec_store_from_uri(self, store: FsspecStore) -> None:
179
191
)
180
192
assert dict (group .attrs ) == {"key" : "value" }
181
193
182
- meta ["attributes" ]["key" ] = "value-2"
194
+ meta ["attributes" ]["key" ] = "value-2" # type: ignore[index]
183
195
await store .set (
184
196
"directory-2/zarr.json" ,
185
197
self .buffer_cls .from_bytes (json .dumps (meta ).encode ()),
@@ -189,7 +201,7 @@ async def test_fsspec_store_from_uri(self, store: FsspecStore) -> None:
189
201
)
190
202
assert dict (group .attrs ) == {"key" : "value-2" }
191
203
192
- meta ["attributes" ]["key" ] = "value-3"
204
+ meta ["attributes" ]["key" ] = "value-3" # type: ignore[index]
193
205
await store .set (
194
206
"directory-3/zarr.json" ,
195
207
self .buffer_cls .from_bytes (json .dumps (meta ).encode ()),
@@ -216,7 +228,7 @@ def test_from_upath(self) -> None:
216
228
assert result .fs .asynchronous
217
229
assert result .path == f"{ test_bucket_name } /foo/bar"
218
230
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 :
220
232
# regression test for https://github.com/zarr-developers/zarr-python/issues/2342
221
233
store_kwargs ["path" ] = "s3://" + store_kwargs ["path" ]
222
234
with pytest .raises (
@@ -237,7 +249,7 @@ def test_init_warns_if_fs_asynchronous_is_false(self) -> None:
237
249
with pytest .warns (UserWarning , match = r".* was not created with `asynchronous=True`.*" ):
238
250
self .store_cls (** store_kwargs )
239
251
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 :
241
253
# regression test for https://github.com/zarr-developers/zarr-python/pull/2343
242
254
store_kwargs ["path" ] += "/abc"
243
255
store = await self .store_cls .open (** store_kwargs )
@@ -256,7 +268,7 @@ async def test_delete_dir_unsupported_deletes(self, store: FsspecStore) -> None:
256
268
parse_version (fsspec .__version__ ) < parse_version ("2024.12.0" ),
257
269
reason = "No AsyncFileSystemWrapper" ,
258
270
)
259
- def test_wrap_sync_filesystem ():
271
+ def test_wrap_sync_filesystem () -> None :
260
272
"""The local fs is not async so we should expect it to be wrapped automatically"""
261
273
from fsspec .implementations .asyn_wrapper import AsyncFileSystemWrapper
262
274
@@ -270,7 +282,7 @@ def test_wrap_sync_filesystem():
270
282
parse_version (fsspec .__version__ ) < parse_version ("2024.12.0" ),
271
283
reason = "No AsyncFileSystemWrapper" ,
272
284
)
273
- def test_no_wrap_async_filesystem ():
285
+ def test_no_wrap_async_filesystem () -> None :
274
286
"""An async fs should not be wrapped automatically; fsspec's https filesystem is such an fs"""
275
287
from fsspec .implementations .asyn_wrapper import AsyncFileSystemWrapper
276
288
@@ -284,12 +296,12 @@ def test_no_wrap_async_filesystem():
284
296
parse_version (fsspec .__version__ ) < parse_version ("2024.12.0" ),
285
297
reason = "No AsyncFileSystemWrapper" ,
286
298
)
287
- async def test_delete_dir_wrapped_filesystem (tmpdir ) -> None :
299
+ async def test_delete_dir_wrapped_filesystem (tmp_path : Path ) -> None :
288
300
from fsspec .implementations .asyn_wrapper import AsyncFileSystemWrapper
289
301
from fsspec .implementations .local import LocalFileSystem
290
302
291
303
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" )
293
305
294
306
assert isinstance (store .fs , AsyncFileSystemWrapper )
295
307
assert store .fs .asynchronous
0 commit comments