1
1
from __future__ import annotations
2
2
3
3
import inspect
4
- import pathlib
5
4
import re
6
5
from typing import TYPE_CHECKING
7
6
8
7
import zarr .codecs
9
8
import zarr .storage
10
9
11
10
if TYPE_CHECKING :
12
- import pathlib
13
11
from collections .abc import Callable
12
+ from pathlib import Path
14
13
15
14
from zarr .abc .store import Store
16
15
from zarr .core .common import JSON , MemoryOrder , ZarrFormat
45
44
from zarr .storage ._utils import normalize_path
46
45
from zarr .testing .utils import gpu_test
47
46
48
- if TYPE_CHECKING :
49
- from collections .abc import Callable
50
- from pathlib import Path
51
-
52
47
53
48
def test_create (memory_store : Store ) -> None :
54
49
store = memory_store
@@ -209,9 +204,7 @@ async def test_open_group(memory_store: MemoryStore) -> None:
209
204
210
205
211
206
@pytest .mark .parametrize ("zarr_format" , [None , 2 , 3 ])
212
- async def test_open_group_unspecified_version (
213
- tmpdir : pathlib .Path , zarr_format : ZarrFormat
214
- ) -> None :
207
+ async def test_open_group_unspecified_version (tmpdir : Path , zarr_format : ZarrFormat ) -> None :
215
208
"""Regression test for https://github.com/zarr-developers/zarr-python/issues/2175"""
216
209
217
210
# create a group with specified zarr format (could be 2, 3, or None)
@@ -272,7 +265,7 @@ def test_save_errors() -> None:
272
265
zarr .save ("data/example.zarr" , a , mode = "w" )
273
266
274
267
275
- def test_open_with_mode_r (tmp_path : pathlib . Path ) -> None :
268
+ def test_open_with_mode_r (tmp_path : Path ) -> None :
276
269
# 'r' means read only (must exist)
277
270
with pytest .raises (FileNotFoundError ):
278
271
zarr .open (store = tmp_path , mode = "r" )
@@ -288,7 +281,7 @@ def test_open_with_mode_r(tmp_path: pathlib.Path) -> None:
288
281
z2 [:] = 3
289
282
290
283
291
- def test_open_with_mode_r_plus (tmp_path : pathlib . Path ) -> None :
284
+ def test_open_with_mode_r_plus (tmp_path : Path ) -> None :
292
285
# 'r+' means read/write (must exist)
293
286
with pytest .raises (FileNotFoundError ):
294
287
zarr .open (store = tmp_path , mode = "r+" )
@@ -301,7 +294,7 @@ def test_open_with_mode_r_plus(tmp_path: pathlib.Path) -> None:
301
294
z2 [:] = 3
302
295
303
296
304
- async def test_open_with_mode_a (tmp_path : pathlib . Path ) -> None :
297
+ async def test_open_with_mode_a (tmp_path : Path ) -> None :
305
298
# Open without shape argument should default to group
306
299
g = zarr .open (store = tmp_path , mode = "a" )
307
300
assert isinstance (g , Group )
@@ -319,7 +312,7 @@ async def test_open_with_mode_a(tmp_path: pathlib.Path) -> None:
319
312
z2 [:] = 3
320
313
321
314
322
- def test_open_with_mode_w (tmp_path : pathlib . Path ) -> None :
315
+ def test_open_with_mode_w (tmp_path : Path ) -> None :
323
316
# 'w' means create (overwrite if exists);
324
317
arr = zarr .open (store = tmp_path , mode = "w" , shape = (3 , 3 ))
325
318
assert isinstance (arr , Array )
@@ -333,7 +326,7 @@ def test_open_with_mode_w(tmp_path: pathlib.Path) -> None:
333
326
z2 [:] = 3
334
327
335
328
336
- def test_open_with_mode_w_minus (tmp_path : pathlib . Path ) -> None :
329
+ def test_open_with_mode_w_minus (tmp_path : Path ) -> None :
337
330
# 'w-' means create (fail if exists)
338
331
arr = zarr .open (store = tmp_path , mode = "w-" , shape = (3 , 3 ))
339
332
assert isinstance (arr , Array )
@@ -405,7 +398,7 @@ def test_load_array(sync_store: Store) -> None:
405
398
406
399
@pytest .mark .parametrize ("path" , ["data" , None ])
407
400
@pytest .mark .parametrize ("load_read_only" , [True , False , None ])
408
- def test_load_zip (tmp_path : pathlib . Path , path : str | None , load_read_only : bool | None ) -> None :
401
+ def test_load_zip (tmp_path : Path , path : str | None , load_read_only : bool | None ) -> None :
409
402
file = tmp_path / "test.zip"
410
403
data = np .arange (100 ).reshape (10 , 10 )
411
404
@@ -423,7 +416,7 @@ def test_load_zip(tmp_path: pathlib.Path, path: str | None, load_read_only: bool
423
416
424
417
@pytest .mark .parametrize ("path" , ["data" , None ])
425
418
@pytest .mark .parametrize ("load_read_only" , [True , False ])
426
- def test_load_local (tmp_path : pathlib . Path , path : str | None , load_read_only : bool ) -> None :
419
+ def test_load_local (tmp_path : Path , path : str | None , load_read_only : bool ) -> None :
427
420
file = tmp_path / "test.zip"
428
421
data = np .arange (100 ).reshape (10 , 10 )
429
422
@@ -1139,7 +1132,7 @@ async def test_open_falls_back_to_open_group_async(zarr_format: ZarrFormat) -> N
1139
1132
1140
1133
1141
1134
@pytest .mark .parametrize ("mode" , ["r" , "r+" , "w" , "a" ])
1142
- def test_open_modes_creates_group (tmp_path : pathlib . Path , mode : str ) -> None :
1135
+ def test_open_modes_creates_group (tmp_path : Path , mode : str ) -> None :
1143
1136
# https://github.com/zarr-developers/zarr-python/issues/2490
1144
1137
zarr_dir = tmp_path / f"mode-{ mode } -test.zarr"
1145
1138
if mode in ["r" , "r+" ]:
0 commit comments