4
4
from types import ModuleType
5
5
from typing import TYPE_CHECKING
6
6
7
- from zarr .common import ZarrFormat
7
+ from _pytest .compat import LEGACY_PATH
8
+
9
+ from zarr .abc .store import Store
10
+ from zarr .common import ChunkCoords , MemoryOrder , ZarrFormat
8
11
from zarr .group import AsyncGroup
9
12
10
13
if TYPE_CHECKING :
11
14
from typing import Any , Literal
12
15
import pathlib
13
16
from dataclasses import dataclass , field
14
17
18
+ import numpy as np
15
19
import pytest
16
20
17
21
from zarr .store import LocalStore , MemoryStore , StorePath
@@ -26,40 +30,40 @@ def parse_store(
26
30
if store == "memory" :
27
31
return MemoryStore (mode = "w" )
28
32
if store == "remote" :
29
- return RemoteStore (mode = "w" )
33
+ return RemoteStore (url = path , mode = "w" )
30
34
raise AssertionError
31
35
32
36
33
37
@pytest .fixture (params = [str , pathlib .Path ])
34
- def path_type (request ) :
38
+ def path_type (request : pytest . FixtureRequest ) -> Any :
35
39
return request .param
36
40
37
41
38
42
# todo: harmonize this with local_store fixture
39
43
@pytest .fixture
40
- def store_path (tmpdir ) :
44
+ def store_path (tmpdir : LEGACY_PATH ) -> StorePath :
41
45
store = LocalStore (str (tmpdir ), mode = "w" )
42
46
p = StorePath (store )
43
47
return p
44
48
45
49
46
50
@pytest .fixture (scope = "function" )
47
- def local_store (tmpdir ) :
51
+ def local_store (tmpdir : LEGACY_PATH ) -> LocalStore :
48
52
return LocalStore (str (tmpdir ), mode = "w" )
49
53
50
54
51
55
@pytest .fixture (scope = "function" )
52
- def remote_store () :
53
- return RemoteStore (mode = "w" )
56
+ def remote_store (url : str ) -> RemoteStore :
57
+ return RemoteStore (url , mode = "w" )
54
58
55
59
56
60
@pytest .fixture (scope = "function" )
57
- def memory_store ():
61
+ def memory_store () -> MemoryStore :
58
62
return MemoryStore (mode = "w" )
59
63
60
64
61
65
@pytest .fixture (scope = "function" )
62
- def store (request : str , tmpdir ) :
66
+ def store (request : pytest . FixtureRequest , tmpdir : LEGACY_PATH ) -> Store :
63
67
param = request .param
64
68
return parse_store (param , str (tmpdir ))
65
69
@@ -72,7 +76,7 @@ class AsyncGroupRequest:
72
76
73
77
74
78
@pytest .fixture (scope = "function" )
75
- async def async_group (request : pytest .FixtureRequest , tmpdir ) -> AsyncGroup :
79
+ async def async_group (request : pytest .FixtureRequest , tmpdir : LEGACY_PATH ) -> AsyncGroup :
76
80
param : AsyncGroupRequest = request .param
77
81
78
82
store = parse_store (param .store , str (tmpdir ))
@@ -90,3 +94,20 @@ def xp(request: pytest.FixtureRequest) -> Iterator[ModuleType]:
90
94
"""Fixture to parametrize over numpy-like libraries"""
91
95
92
96
yield pytest .importorskip (request .param )
97
+
98
+
99
+ @dataclass
100
+ class ArrayRequest :
101
+ shape : ChunkCoords
102
+ dtype : str
103
+ order : MemoryOrder
104
+
105
+
106
+ @pytest .fixture
107
+ def array_fixture (request : pytest .FixtureRequest ) -> np .ndarray :
108
+ array_request : ArrayRequest = request .param
109
+ return (
110
+ np .arange (np .prod (array_request .shape ))
111
+ .reshape (array_request .shape , order = array_request .order )
112
+ .astype (array_request .dtype )
113
+ )
0 commit comments