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
11
+ from pathlib import Path
13
12
from collections .abc import Callable
14
13
15
14
from zarr .abc .store import Store
46
45
from zarr .storage ._utils import normalize_path
47
46
from zarr .testing .utils import gpu_test
48
47
49
- if TYPE_CHECKING :
50
- from collections .abc import Callable
51
- from pathlib import Path
52
-
53
48
54
49
def test_create (memory_store : Store ) -> None :
55
50
store = memory_store
@@ -210,9 +205,7 @@ async def test_open_group(memory_store: MemoryStore) -> None:
210
205
211
206
212
207
@pytest .mark .parametrize ("zarr_format" , [None , 2 , 3 ])
213
- async def test_open_group_unspecified_version (
214
- tmpdir : pathlib .Path , zarr_format : ZarrFormat
215
- ) -> None :
208
+ async def test_open_group_unspecified_version (tmpdir : Path , zarr_format : ZarrFormat ) -> None :
216
209
"""Regression test for https://github.com/zarr-developers/zarr-python/issues/2175"""
217
210
218
211
# create a group with specified zarr format (could be 2, 3, or None)
@@ -273,7 +266,7 @@ def test_save_errors() -> None:
273
266
zarr .save ("data/example.zarr" , a , mode = "w" )
274
267
275
268
276
- def test_open_with_mode_r (tmp_path : pathlib . Path ) -> None :
269
+ def test_open_with_mode_r (tmp_path : Path ) -> None :
277
270
# 'r' means read only (must exist)
278
271
with pytest .raises (FileNotFoundError ):
279
272
zarr .open (store = tmp_path , mode = "r" )
@@ -289,7 +282,7 @@ def test_open_with_mode_r(tmp_path: pathlib.Path) -> None:
289
282
z2 [:] = 3
290
283
291
284
292
- def test_open_with_mode_r_plus (tmp_path : pathlib . Path ) -> None :
285
+ def test_open_with_mode_r_plus (tmp_path : Path ) -> None :
293
286
# 'r+' means read/write (must exist)
294
287
with pytest .raises (FileNotFoundError ):
295
288
zarr .open (store = tmp_path , mode = "r+" )
@@ -302,7 +295,7 @@ def test_open_with_mode_r_plus(tmp_path: pathlib.Path) -> None:
302
295
z2 [:] = 3
303
296
304
297
305
- async def test_open_with_mode_a (tmp_path : pathlib . Path ) -> None :
298
+ async def test_open_with_mode_a (tmp_path : Path ) -> None :
306
299
# Open without shape argument should default to group
307
300
g = zarr .open (store = tmp_path , mode = "a" )
308
301
assert isinstance (g , Group )
@@ -320,7 +313,7 @@ async def test_open_with_mode_a(tmp_path: pathlib.Path) -> None:
320
313
z2 [:] = 3
321
314
322
315
323
- def test_open_with_mode_w (tmp_path : pathlib . Path ) -> None :
316
+ def test_open_with_mode_w (tmp_path : Path ) -> None :
324
317
# 'w' means create (overwrite if exists);
325
318
arr = zarr .open (store = tmp_path , mode = "w" , shape = (3 , 3 ))
326
319
assert isinstance (arr , Array )
@@ -334,7 +327,7 @@ def test_open_with_mode_w(tmp_path: pathlib.Path) -> None:
334
327
z2 [:] = 3
335
328
336
329
337
- def test_open_with_mode_w_minus (tmp_path : pathlib . Path ) -> None :
330
+ def test_open_with_mode_w_minus (tmp_path : Path ) -> None :
338
331
# 'w-' means create (fail if exists)
339
332
arr = zarr .open (store = tmp_path , mode = "w-" , shape = (3 , 3 ))
340
333
assert isinstance (arr , Array )
@@ -406,7 +399,7 @@ def test_load_array(sync_store: Store) -> None:
406
399
407
400
@pytest .mark .parametrize ("path" , ["data" , None ])
408
401
@pytest .mark .parametrize ("load_read_only" , [True , False , None ])
409
- def test_load_zip (tmp_path : pathlib . Path , path : str | None , load_read_only : bool | None ) -> None :
402
+ def test_load_zip (tmp_path : Path , path : str | None , load_read_only : bool | None ) -> None :
410
403
file = tmp_path / "test.zip"
411
404
data = np .arange (100 ).reshape (10 , 10 )
412
405
@@ -424,7 +417,7 @@ def test_load_zip(tmp_path: pathlib.Path, path: str | None, load_read_only: bool
424
417
425
418
@pytest .mark .parametrize ("path" , ["data" , None ])
426
419
@pytest .mark .parametrize ("load_read_only" , [True , False ])
427
- def test_load_local (tmp_path : pathlib . Path , path : str | None , load_read_only : bool ) -> None :
420
+ def test_load_local (tmp_path : Path , path : str | None , load_read_only : bool ) -> None :
428
421
file = tmp_path / "test.zip"
429
422
data = np .arange (100 ).reshape (10 , 10 )
430
423
@@ -1174,7 +1167,7 @@ async def test_open_falls_back_to_open_group_async(zarr_format: ZarrFormat) -> N
1174
1167
1175
1168
1176
1169
@pytest .mark .parametrize ("mode" , ["r" , "r+" , "w" , "a" ])
1177
- def test_open_modes_creates_group (tmp_path : pathlib . Path , mode : str ) -> None :
1170
+ def test_open_modes_creates_group (tmp_path : Path , mode : str ) -> None :
1178
1171
# https://github.com/zarr-developers/zarr-python/issues/2490
1179
1172
zarr_dir = tmp_path / f"mode-{ mode } -test.zarr"
1180
1173
if mode in ["r" , "r+" ]:
@@ -1325,7 +1318,11 @@ def add_empty_file(path: Path) -> Path:
1325
1318
1326
1319
@pytest .mark .parametrize ("create_function" , [create_array , from_array ])
1327
1320
@pytest .mark .parametrize ("overwrite" , [True , False ])
1328
- def test_no_overwrite_array (tmp_path : Path , create_function : Callable , overwrite : bool ) -> None : # type:ignore[type-arg]
1321
+ def test_no_overwrite_array (
1322
+ tmp_path : Path ,
1323
+ create_function : Callable , # type:ignore[type-arg]
1324
+ overwrite : bool ,
1325
+ ) -> None :
1329
1326
store = zarr .storage .LocalStore (tmp_path )
1330
1327
existing_fpath = add_empty_file (tmp_path )
1331
1328
@@ -1339,7 +1336,11 @@ def test_no_overwrite_array(tmp_path: Path, create_function: Callable, overwrite
1339
1336
1340
1337
@pytest .mark .parametrize ("create_function" , [create_group , group ])
1341
1338
@pytest .mark .parametrize ("overwrite" , [True , False ])
1342
- def test_no_overwrite_group (tmp_path : Path , create_function : Callable , overwrite : bool ) -> None : # type:ignore[type-arg]
1339
+ def test_no_overwrite_group (
1340
+ tmp_path : Path ,
1341
+ create_function : Callable , # type:ignore[type-arg]
1342
+ overwrite : bool ,
1343
+ ) -> None :
1343
1344
store = zarr .storage .LocalStore (tmp_path )
1344
1345
existing_fpath = add_empty_file (tmp_path )
1345
1346
@@ -1353,7 +1354,11 @@ def test_no_overwrite_group(tmp_path: Path, create_function: Callable, overwrite
1353
1354
1354
1355
@pytest .mark .parametrize ("open_func" , [zarr .open , open_group ])
1355
1356
@pytest .mark .parametrize ("mode" , ["r" , "r+" , "a" , "w" , "w-" ])
1356
- def test_no_overwrite_open (tmp_path : Path , open_func : Callable , mode : str ) -> None : # type:ignore[type-arg]
1357
+ def test_no_overwrite_open (
1358
+ tmp_path : Path ,
1359
+ open_func : Callable , # type:ignore[type-arg]
1360
+ mode : str ,
1361
+ ) -> None :
1357
1362
store = zarr .storage .LocalStore (tmp_path )
1358
1363
existing_fpath = add_empty_file (tmp_path )
1359
1364
0 commit comments