11from __future__ import annotations
22
3- from collections .abc import Mapping
43import json
54import re
65from typing import TYPE_CHECKING , Literal
76
87import numpy as np
98import pytest
109
11- from zarr .codecs .bytes import BytesCodec
1210from zarr .core .buffer import default_buffer_prototype
13- from zarr .core .chunk_key_encodings import DefaultChunkKeyEncoding , V2ChunkKeyEncoding
14- from zarr .core .common import ArrayMetadataJSON_V3 , NamedConfig
1511from zarr .core .config import config
1612from zarr .core .dtype import get_data_type_from_native_dtype
1713from zarr .core .dtype .npy .string import _NUMPY_SUPPORTS_VLEN_STRING
2218)
2319
2420if TYPE_CHECKING :
21+ from collections .abc import Mapping
2522 from typing import Any
2623
2724 from zarr .abc .codec import Codec
28- from zarr .core .common import JSON
25+ from zarr .core .common import JSON , ArrayMetadataJSON_V3 , NamedConfig
2926
3027
3128bool_dtypes = ("bool" ,)
@@ -112,20 +109,25 @@ def test_parse_fill_value_invalid_type_sequence(fill_value: Any, dtype_str: str)
112109 dtype_instance .from_json_scalar (fill_value , zarr_format = 3 )
113110
114111
115- @pytest .mark .parametrize ("chunk_grid" , [{"name" : "regular" , "configuration" : {"chunk_shape" : (1 , 1 , 1 )}}])
116- @pytest .mark .parametrize ("codecs" , [({"name" : "bytes" },)])
112+ @pytest .mark .parametrize (
113+ "chunk_grid" , [{"name" : "regular" , "configuration" : {"chunk_shape" : (1 , 1 , 1 )}}]
114+ )
115+ @pytest .mark .parametrize ("codecs" , [({"name" : "bytes" },)])
117116@pytest .mark .parametrize ("fill_value" , [0 , 1 ])
118117@pytest .mark .parametrize ("data_type" , ["int8" , "uint8" ])
119- @pytest .mark .parametrize ("chunk_key_encoding" , [
120- {"name" : "v2" , "configuration" : {"separator" : "." }},
121- {"name" : "v2" , "configuration" : {"separator" : "/" }},
122- {"name" : "v2" },
123- {"name" : "default" , "configuration" : {"separator" : "." }},
124- {"name" : "default" , "configuration" : {"separator" : "/" }},
125- {"name" : "default" },
126- ])
118+ @pytest .mark .parametrize (
119+ "chunk_key_encoding" ,
120+ [
121+ {"name" : "v2" , "configuration" : {"separator" : "." }},
122+ {"name" : "v2" , "configuration" : {"separator" : "/" }},
123+ {"name" : "v2" },
124+ {"name" : "default" , "configuration" : {"separator" : "." }},
125+ {"name" : "default" , "configuration" : {"separator" : "/" }},
126+ {"name" : "default" },
127+ ],
128+ )
127129@pytest .mark .parametrize ("attributes" , ["unset" , {"foo" : "bar" }])
128- @pytest .mark .parametrize ("dimension_names" , [(None , None , None ), ('a' , 'b' , None ), "unset" ])
130+ @pytest .mark .parametrize ("dimension_names" , [(None , None , None ), ("a" , "b" , None ), "unset" ])
129131@pytest .mark .parametrize ("storage_transformers" , [(), "unset" ])
130132def test_metadata_to_dict (
131133 chunk_grid : NamedConfig [str , Mapping [str , object ]],
@@ -134,7 +136,7 @@ def test_metadata_to_dict(
134136 fill_value : Any ,
135137 chunk_key_encoding : NamedConfig [str , Mapping [str , object ]],
136138 dimension_names : tuple [str | None , ...] | Literal ["unset" ],
137- attributes : dict [str , Any ] | Literal [' unset' ],
139+ attributes : dict [str , Any ] | Literal [" unset" ],
138140 storage_transformers : tuple [dict [str , JSON ]] | Literal ["unset" ],
139141) -> None :
140142 shape = (1 , 2 , 3 )
@@ -165,28 +167,34 @@ def test_metadata_to_dict(
165167 metadata = ArrayV3Metadata .from_dict (source_dict )
166168 parsed_dict = metadata .to_dict ()
167169
168- for k ,v in parsed_dict .items ():
170+ for k , v in parsed_dict .items ():
169171 if k in source_dict :
170- if k == ' chunk_key_encoding' :
171- assert v [' name' ] == chunk_key_encoding [' name' ]
172- if chunk_key_encoding [' name' ] == 'v2' :
172+ if k == " chunk_key_encoding" :
173+ assert v [" name" ] == chunk_key_encoding [" name" ]
174+ if chunk_key_encoding [" name" ] == "v2" :
173175 if "configuration" in chunk_key_encoding :
174- if "separator" in chunk_key_encoding ['configuration' ]:
175- assert v ['configuration' ]['separator' ] == chunk_key_encoding ['configuration' ]['separator' ]
176+ if "separator" in chunk_key_encoding ["configuration" ]:
177+ assert (
178+ v ["configuration" ]["separator" ]
179+ == chunk_key_encoding ["configuration" ]["separator" ]
180+ )
176181 else :
177182 assert v ["configuration" ]["separator" ] == "."
178- elif chunk_key_encoding [' name' ] == ' default' :
183+ elif chunk_key_encoding [" name" ] == " default" :
179184 if "configuration" in chunk_key_encoding :
180- if "separator" in chunk_key_encoding ['configuration' ]:
181- assert v ['configuration' ]['separator' ] == chunk_key_encoding ['configuration' ]['separator' ]
185+ if "separator" in chunk_key_encoding ["configuration" ]:
186+ assert (
187+ v ["configuration" ]["separator" ]
188+ == chunk_key_encoding ["configuration" ]["separator" ]
189+ )
182190 else :
183191 assert v ["configuration" ]["separator" ] == "/"
184192 else :
185193 assert source_dict [k ] == v
186194 else :
187- if k == ' attributes' :
195+ if k == " attributes" :
188196 assert v == {}
189- elif k == ' storage_transformers' :
197+ elif k == " storage_transformers" :
190198 assert v == ()
191199 else :
192200 assert v is None
0 commit comments