Skip to content

Commit 37f96b0

Browse files
committed
parametrize json indent
1 parent 5ab3640 commit 37f96b0

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

tests/test_metadata/test_v3.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from zarr.codecs.bytes import BytesCodec
1111
from zarr.core.buffer import default_buffer_prototype
1212
from zarr.core.chunk_key_encodings import DefaultChunkKeyEncoding, V2ChunkKeyEncoding
13+
from zarr.core.config import config
1314
from zarr.core.group import parse_node_type, GroupMetadata
1415
from zarr.core.metadata.v3 import (
1516
ArrayV3Metadata,
@@ -304,17 +305,19 @@ def test_metadata_to_dict(
304305
assert observed == expected
305306

306307

307-
def test_json_indent():
308-
m = GroupMetadata()
309-
d = m.to_buffer_dict(default_buffer_prototype())["zarr.json"].to_bytes()
310-
class TestIndentEncoder(json.JSONEncoder):
311-
def __init__(self, *args: Any, **kwargs: Any) -> None:
312-
super().__init__(*args, **kwargs)
313-
self.indent = 2
308+
@pytest.mark.parametrize('indent', (2, 4))
309+
def test_json_indent(indent: int):
310+
with config.set({"json_indent": indent}):
311+
m = GroupMetadata()
312+
d = m.to_buffer_dict(default_buffer_prototype())["zarr.json"].to_bytes()
313+
class TestIndentEncoder(json.JSONEncoder):
314+
def __init__(self, *args: Any, **kwargs: Any) -> None:
315+
super().__init__(*args, **kwargs)
316+
self.indent = indent
314317

315-
# expected has extra ' ' on each line compared with json.dumps( indent=2)
316-
expected = json.dumps(json.loads(d), cls=TestIndentEncoder).encode()
317-
assert d == expected
318+
# expected has extra ' ' on each line compared with json.dumps( indent=2)
319+
expected = json.dumps(json.loads(d), cls=TestIndentEncoder).encode()
320+
assert d == expected
318321

319322

320323
# @pytest.mark.parametrize("fill_value", [-1, 0, 1, 2932897])

0 commit comments

Comments
 (0)