@@ -108,121 +108,6 @@ async def test_basic() -> None:
108108 assert out [0 ].to_bytes () == data [1 :]
109109
110110
111- def array_roundtrip (store ):
112- """
113- Round trip an array using a Zarr store
114-
115- Args:
116- store: Store-Like object (e.g., FSMap)
117- """
118- arr = zarr .open (store = store , mode = "w" , shape = (3 , 3 ))
119- assert isinstance (arr , Array )
120- # Set values
121- arr [:] = 1
122- # Read set values
123- arr = zarr .open (store = store , mode = "r" , shape = (3 , 3 ))
124- assert isinstance (arr , Array )
125- np .testing .assert_array_equal (np .ones ((3 , 3 )), arr [:])
126-
127-
128- @pytest .mark .skipif (
129- parse_version (fsspec .__version__ ) < parse_version ("2024.12.0" ),
130- reason = "No AsyncFileSystemWrapper" ,
131- )
132- def test_wrap_sync_filesystem (tmp_path ):
133- """The local fs is not async so we should expect it to be wrapped automatically"""
134- from fsspec .implementations .asyn_wrapper import AsyncFileSystemWrapper
135-
136- store = FsspecStore .from_url (f"local://{ tmp_path } " , storage_options = {"auto_mkdir" : True })
137- assert isinstance (store .fs , AsyncFileSystemWrapper )
138- assert store .fs .async_impl
139- array_roundtrip (store )
140-
141-
142- @pytest .mark .skipif (
143- parse_version (fsspec .__version__ ) >= parse_version ("2024.12.0" ),
144- reason = "No AsyncFileSystemWrapper" ,
145- )
146- def test_wrap_sync_filesystem_raises (tmp_path ):
147- """The local fs is not async so we should expect it to be wrapped automatically"""
148- with pytest .raises (ImportError , match = "The filesystem .*" ):
149- FsspecStore .from_url (f"local://{ tmp_path } " , storage_options = {"auto_mkdir" : True })
150-
151-
152- @pytest .mark .skipif (
153- parse_version (fsspec .__version__ ) < parse_version ("2024.12.0" ),
154- reason = "No AsyncFileSystemWrapper" ,
155- )
156- def test_no_wrap_async_filesystem ():
157- """An async fs should not be wrapped automatically; fsspec's s3 filesystem is such an fs"""
158- from fsspec .implementations .asyn_wrapper import AsyncFileSystemWrapper
159-
160- store = FsspecStore .from_url (
161- f"s3://{ test_bucket_name } /foo/spam/" ,
162- storage_options = {"endpoint_url" : endpoint_url , "anon" : False },
163- )
164- assert not isinstance (store .fs , AsyncFileSystemWrapper )
165- assert store .fs .async_impl
166- array_roundtrip (store )
167-
168-
169- @pytest .mark .skipif (
170- parse_version (fsspec .__version__ ) < parse_version ("2024.12.0" ),
171- reason = "No AsyncFileSystemWrapper" ,
172- )
173- def test_open_fsmap_file (tmp_path : pathlib .Path ) -> None :
174- fsspec = pytest .importorskip ("fsspec" )
175- fs = fsspec .filesystem ("file" , auto_mkdir = True )
176- mapper = fs .get_mapper (tmp_path )
177- array_roundtrip (mapper )
178-
179-
180- @pytest .mark .skipif (
181- parse_version (fsspec .__version__ ) < parse_version ("2024.12.0" ),
182- reason = "No AsyncFileSystemWrapper" ,
183- )
184- def test_open_fsmap_file_raises (tmp_path : pathlib .Path ) -> None :
185- fsspec = pytest .importorskip ("fsspec.implementations.local" )
186- fs = fsspec .LocalFileSystem (auto_mkdir = False )
187- mapper = fs .get_mapper (tmp_path )
188- with pytest .raises (ValueError , match = "LocalFilesystem .*" ):
189- array_roundtrip (mapper )
190-
191-
192- @pytest .mark .parametrize ("asynchronous" , [True , False ])
193- def test_open_fsmap_s3 (asynchronous : bool ) -> None :
194- s3_filesystem = s3fs .S3FileSystem (
195- asynchronous = asynchronous , endpoint_url = endpoint_url , anon = False
196- )
197- mapper = s3_filesystem .get_mapper (f"s3://{ test_bucket_name } /map/foo/" )
198- array_roundtrip (mapper )
199-
200-
201- def test_open_s3map_raises () -> None :
202- with pytest .raises (TypeError , match = "Unsupported type for store_like:.*" ):
203- zarr .open (store = 0 , mode = "w" , shape = (3 , 3 ))
204- s3_filesystem = s3fs .S3FileSystem (asynchronous = True , endpoint_url = endpoint_url , anon = False )
205- mapper = s3_filesystem .get_mapper (f"s3://{ test_bucket_name } /map/foo/" )
206- with pytest .raises (
207- ValueError , match = "'path' was provided but is not used for FSMap store_like objects"
208- ):
209- zarr .open (store = mapper , path = "bar" , mode = "w" , shape = (3 , 3 ))
210- with pytest .raises (
211- ValueError ,
212- match = "'storage_options was provided but is not used for FSMap store_like objects" ,
213- ):
214- zarr .open (store = mapper , storage_options = {"anon" : True }, mode = "w" , shape = (3 , 3 ))
215-
216-
217- @pytest .mark .parametrize ("asynchronous" , [True , False ])
218- def test_make_async (asynchronous : bool ) -> None :
219- s3_filesystem = s3fs .S3FileSystem (
220- asynchronous = asynchronous , endpoint_url = endpoint_url , anon = False
221- )
222- fs = _make_async (s3_filesystem )
223- assert fs .asynchronous
224-
225-
226111class TestFsspecStoreS3 (StoreTests [FsspecStore , cpu .Buffer ]):
227112 store_cls = FsspecStore
228113 buffer_cls = cpu .Buffer
@@ -345,6 +230,121 @@ async def test_delete_dir_unsupported_deletes(self, store: FsspecStore) -> None:
345230 await store .delete_dir ("test_prefix" )
346231
347232
233+ def array_roundtrip (store ):
234+ """
235+ Round trip an array using a Zarr store
236+
237+ Args:
238+ store: Store-Like object (e.g., FSMap)
239+ """
240+ arr = zarr .open (store = store , mode = "w" , shape = (3 , 3 ))
241+ assert isinstance (arr , Array )
242+ # Set values
243+ arr [:] = 1
244+ # Read set values
245+ arr = zarr .open (store = store , mode = "r" , shape = (3 , 3 ))
246+ assert isinstance (arr , Array )
247+ np .testing .assert_array_equal (np .ones ((3 , 3 )), arr [:])
248+
249+
250+ @pytest .mark .skipif (
251+ parse_version (fsspec .__version__ ) < parse_version ("2024.12.0" ),
252+ reason = "No AsyncFileSystemWrapper" ,
253+ )
254+ def test_wrap_sync_filesystem (tmp_path ):
255+ """The local fs is not async so we should expect it to be wrapped automatically"""
256+ from fsspec .implementations .asyn_wrapper import AsyncFileSystemWrapper
257+
258+ store = FsspecStore .from_url (f"local://{ tmp_path } " , storage_options = {"auto_mkdir" : True })
259+ assert isinstance (store .fs , AsyncFileSystemWrapper )
260+ assert store .fs .async_impl
261+ array_roundtrip (store )
262+
263+
264+ @pytest .mark .skipif (
265+ parse_version (fsspec .__version__ ) >= parse_version ("2024.12.0" ),
266+ reason = "No AsyncFileSystemWrapper" ,
267+ )
268+ def test_wrap_sync_filesystem_raises (tmp_path ):
269+ """The local fs is not async so we should expect it to be wrapped automatically"""
270+ with pytest .raises (ImportError , match = "The filesystem .*" ):
271+ FsspecStore .from_url (f"local://{ tmp_path } " , storage_options = {"auto_mkdir" : True })
272+
273+
274+ @pytest .mark .skipif (
275+ parse_version (fsspec .__version__ ) < parse_version ("2024.12.0" ),
276+ reason = "No AsyncFileSystemWrapper" ,
277+ )
278+ def test_no_wrap_async_filesystem ():
279+ """An async fs should not be wrapped automatically; fsspec's s3 filesystem is such an fs"""
280+ from fsspec .implementations .asyn_wrapper import AsyncFileSystemWrapper
281+
282+ store = FsspecStore .from_url (
283+ f"s3://{ test_bucket_name } /foo/spam/" ,
284+ storage_options = {"endpoint_url" : endpoint_url , "anon" : False },
285+ )
286+ assert not isinstance (store .fs , AsyncFileSystemWrapper )
287+ assert store .fs .async_impl
288+ array_roundtrip (store )
289+
290+
291+ @pytest .mark .skipif (
292+ parse_version (fsspec .__version__ ) < parse_version ("2024.12.0" ),
293+ reason = "No AsyncFileSystemWrapper" ,
294+ )
295+ def test_open_fsmap_file (tmp_path : pathlib .Path ) -> None :
296+ fsspec = pytest .importorskip ("fsspec" )
297+ fs = fsspec .filesystem ("file" , auto_mkdir = True )
298+ mapper = fs .get_mapper (tmp_path )
299+ array_roundtrip (mapper )
300+
301+
302+ @pytest .mark .skipif (
303+ parse_version (fsspec .__version__ ) < parse_version ("2024.12.0" ),
304+ reason = "No AsyncFileSystemWrapper" ,
305+ )
306+ def test_open_fsmap_file_raises (tmp_path : pathlib .Path ) -> None :
307+ fsspec = pytest .importorskip ("fsspec.implementations.local" )
308+ fs = fsspec .LocalFileSystem (auto_mkdir = False )
309+ mapper = fs .get_mapper (tmp_path )
310+ with pytest .raises (ValueError , match = "LocalFilesystem .*" ):
311+ array_roundtrip (mapper )
312+
313+
314+ @pytest .mark .parametrize ("asynchronous" , [True , False ])
315+ def test_open_fsmap_s3 (asynchronous : bool ) -> None :
316+ s3_filesystem = s3fs .S3FileSystem (
317+ asynchronous = asynchronous , endpoint_url = endpoint_url , anon = False
318+ )
319+ mapper = s3_filesystem .get_mapper (f"s3://{ test_bucket_name } /map/foo/" )
320+ array_roundtrip (mapper )
321+
322+
323+ def test_open_s3map_raises () -> None :
324+ with pytest .raises (TypeError , match = "Unsupported type for store_like:.*" ):
325+ zarr .open (store = 0 , mode = "w" , shape = (3 , 3 ))
326+ s3_filesystem = s3fs .S3FileSystem (asynchronous = True , endpoint_url = endpoint_url , anon = False )
327+ mapper = s3_filesystem .get_mapper (f"s3://{ test_bucket_name } /map/foo/" )
328+ with pytest .raises (
329+ ValueError , match = "'path' was provided but is not used for FSMap store_like objects"
330+ ):
331+ zarr .open (store = mapper , path = "bar" , mode = "w" , shape = (3 , 3 ))
332+ with pytest .raises (
333+ ValueError ,
334+ match = "'storage_options was provided but is not used for FSMap store_like objects" ,
335+ ):
336+ zarr .open (store = mapper , storage_options = {"anon" : True }, mode = "w" , shape = (3 , 3 ))
337+
338+
339+ @pytest .mark .parametrize ("asynchronous" , [True , False ])
340+ def test_make_async (asynchronous : bool ) -> None :
341+ s3_filesystem = s3fs .S3FileSystem (
342+ asynchronous = asynchronous , endpoint_url = endpoint_url , anon = False
343+ )
344+ fs = _make_async (s3_filesystem )
345+ assert fs .asynchronous
346+
347+
348348@pytest .mark .skipif (
349349 parse_version (fsspec .__version__ ) < parse_version ("2024.12.0" ),
350350 reason = "No AsyncFileSystemWrapper" ,
0 commit comments