1
1
from __future__ import annotations
2
2
3
3
import re
4
- from typing import TYPE_CHECKING , get_args
4
+ from typing import TYPE_CHECKING , Any
5
5
6
6
import zarr .codecs
7
7
import zarr .storage
@@ -77,16 +77,22 @@ def test_create(memory_store: Store) -> None:
77
77
z = create (shape = (400 , 100 ), chunks = (16 , 16.5 ), store = store , overwrite = True ) # type: ignore [arg-type]
78
78
79
79
80
- LikeFuncName = Literal ["zeros_like" , "ones_like" , "empty_like" , "full_like" , "open_like" ]
81
-
82
-
83
- @pytest .mark .parametrize ("func_name" , get_args (LikeFuncName ))
80
+ @pytest .mark .parametrize (
81
+ "func" ,
82
+ [
83
+ zarr .api .asynchronous .zeros_like ,
84
+ zarr .api .asynchronous .ones_like ,
85
+ zarr .api .asynchronous .empty_like ,
86
+ zarr .api .asynchronous .full_like ,
87
+ zarr .api .asynchronous .open_like ,
88
+ ],
89
+ )
84
90
@pytest .mark .parametrize ("out_shape" , ["keep" , (10 , 10 )])
85
91
@pytest .mark .parametrize ("out_chunks" , ["keep" , (10 , 10 )])
86
92
@pytest .mark .parametrize ("out_dtype" , ["keep" , "int8" ])
87
93
async def test_array_like_creation (
88
94
zarr_format : ZarrFormat ,
89
- func_name : LikeFuncName ,
95
+ func : Callable [[ Any ], Any ] ,
90
96
out_shape : Literal ["keep" ] | tuple [int , ...],
91
97
out_chunks : Literal ["keep" ] | tuple [int , ...],
92
98
out_dtype : str ,
@@ -100,23 +106,18 @@ async def test_array_like_creation(
100
106
store = {}, shape = (11 , 12 ), dtype = "uint8" , chunks = (11 , 12 ), zarr_format = zarr_format
101
107
)
102
108
kwargs : dict [str , object ] = {}
103
- if func_name == " full_like" :
109
+ if func is zarr . api . asynchronous . full_like :
104
110
expect_fill = 4
105
111
kwargs ["fill_value" ] = expect_fill
106
- func = zarr .api .asynchronous .full_like
107
- elif func_name == "zeros_like" :
112
+ elif func is zarr .api .asynchronous .zeros_like :
108
113
expect_fill = 0
109
- func = zarr .api .asynchronous .zeros_like
110
- elif func_name == "ones_like" :
114
+ elif func is zarr .api .asynchronous .ones_like :
111
115
expect_fill = 1
112
- func = zarr .api .asynchronous .ones_like
113
- elif func_name == "empty_like" :
116
+ elif func is zarr .api .asynchronous .empty_like :
114
117
expect_fill = ref_arr .fill_value
115
- func = zarr .api .asynchronous .empty_like
116
- elif func_name == "open_like" :
118
+ elif func is zarr .api .asynchronous .open_like : # type: ignore[assignment]
117
119
expect_fill = ref_arr .fill_value
118
120
kwargs ["mode" ] = "w"
119
- func = zarr .api .asynchronous .open_like # type: ignore[assignment]
120
121
else :
121
122
raise AssertionError
122
123
if out_shape != "keep" :
@@ -135,7 +136,7 @@ async def test_array_like_creation(
135
136
else :
136
137
expect_dtype = ref_arr .dtype # type: ignore[assignment]
137
138
138
- new_arr = await func (ref_arr , path = "foo" , ** kwargs )
139
+ new_arr = await func (ref_arr , path = "foo" , ** kwargs ) # type: ignore[call-arg]
139
140
assert new_arr .shape == expect_shape
140
141
assert new_arr .chunks == expect_chunks
141
142
assert new_arr .dtype == expect_dtype
0 commit comments