Skip to content

Commit df0eef4

Browse files
committed
add test to ensure that ambiguous group.open warns
1 parent ba5be4f commit df0eef4

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tests/test_group.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import contextlib
44
import inspect
5+
import json
56
import operator
67
import pickle
78
import re
@@ -58,6 +59,7 @@
5859

5960
from _pytest.compat import LEGACY_PATH
6061

62+
from zarr.core.buffer.core import Buffer
6163
from zarr.core.common import JSON, ZarrFormat
6264

6365

@@ -1400,6 +1402,21 @@ def test_open_mutable_mapping_sync():
14001402
assert isinstance(group.store_path.store, MemoryStore)
14011403

14021404

1405+
async def test_open_ambiguous_node():
1406+
zarr_json_bytes = default_buffer_prototype().buffer.from_bytes(
1407+
json.dumps({"zarr_format": 3, "node_type": "group"}).encode("utf-8")
1408+
)
1409+
zgroup_bytes = default_buffer_prototype().buffer.from_bytes(
1410+
json.dumps({"zarr_format": 2}).encode("utf-8")
1411+
)
1412+
store: dict[str, Buffer] = {"zarr.json": zarr_json_bytes, ".zgroup": zgroup_bytes}
1413+
with pytest.warns(
1414+
ZarrUserWarning,
1415+
match=r"Both zarr\.json \(Zarr format 3\) and \.zgroup \(Zarr format 2\) metadata objects exist at",
1416+
):
1417+
await AsyncGroup.open(store, zarr_format=None)
1418+
1419+
14031420
class TestConsolidated:
14041421
async def test_group_getitem_consolidated(self, store: Store) -> None:
14051422
root = await AsyncGroup.from_store(store=store)

0 commit comments

Comments
 (0)