22from dataclasses import dataclass
33from itertools import product
44from pathlib import Path
5+ from typing import TYPE_CHECKING
56
67import numcodecs
78import numpy as np
1011
1112import zarr
1213from zarr .core .array import Array
14+ from zarr .core .chunk_key_encodings import V2ChunkKeyEncoding
1315from zarr .core .dtype .npy .string import VariableLengthString
1416from zarr .storage import LocalStore
1517
18+ if TYPE_CHECKING :
19+ from zarr .core .dtype import ZDTypeLike
20+
1621
1722def runner_installed () -> bool :
1823 """
@@ -69,8 +74,10 @@ def source_array(tmp_path: Path, request: pytest.FixtureRequest) -> Array:
6974 store = LocalStore (dest )
7075 array_params : ArrayParams = request .param
7176 compressor = array_params .compressor
77+ chunk_key_encoding = V2ChunkKeyEncoding (separator = "/" )
78+ dtype : ZDTypeLike
7279 if array_params .values .dtype == np .dtype ("|O" ):
73- dtype = VariableLengthString ()
80+ dtype = VariableLengthString () # type: ignore[assignment]
7481 else :
7582 dtype = array_params .values .dtype
7683 z = zarr .create_array (
@@ -82,25 +89,30 @@ def source_array(tmp_path: Path, request: pytest.FixtureRequest) -> Array:
8289 fill_value = array_params .fill_value ,
8390 order = "C" ,
8491 filters = None ,
85- chunk_key_encoding = { "name" : "v2" , "configuration" : { "separator" : "/" }} ,
92+ chunk_key_encoding = chunk_key_encoding ,
8693 write_data = True ,
8794 zarr_format = 2 ,
8895 )
8996 z [:] = array_params .values
9097 return z
9198
9299
100+ # TODO: make this dynamic based on the installed scripts
101+ script_paths = [Path (__file__ ).resolve ().parent / "scripts" / "v2.18.py" ]
102+
103+
93104@pytest .mark .skipif (not runner_installed (), reason = "no python script runner installed" )
94105@pytest .mark .parametrize (
95106 "source_array" , array_cases , indirect = True , ids = tuple (map (str , array_cases ))
96107)
97- def test_roundtrip (source_array : Array , tmp_path : Path ) -> None :
108+ @pytest .mark .parametrize ("script_path" , script_paths )
109+ def test_roundtrip (source_array : Array , tmp_path : Path , script_path : Path ) -> None :
98110 out_path = tmp_path / "out"
99111 copy_op = subprocess .run (
100112 [
101113 "uv" ,
102114 "run" ,
103- Path ( __file__ ). resolve (). parent / "v2.18.py" ,
115+ script_path ,
104116 str (source_array .store ).removeprefix ("file://" ),
105117 str (out_path ),
106118 ],
0 commit comments