|
6 | 6 | from numpy.testing import assert_array_equal
|
7 | 7 |
|
8 | 8 | import zarr
|
| 9 | +import zarr.api.asynchronous |
| 10 | +import zarr.core.group |
9 | 11 | from zarr import Array, Group
|
10 | 12 | from zarr.abc.store import Store
|
11 | 13 | from zarr.api.synchronous import create, group, load, open, open_group, save, save_array, save_group
|
12 | 14 | from zarr.core.common import ZarrFormat
|
| 15 | +from zarr.errors import MetadataValidationError |
13 | 16 | from zarr.storage.memory import MemoryStore
|
14 | 17 |
|
15 | 18 |
|
@@ -921,3 +924,37 @@ def test_open_group_positional_args_deprecated() -> None:
|
921 | 924 | store = MemoryStore({}, mode="w")
|
922 | 925 | with pytest.warns(FutureWarning, match="pass"):
|
923 | 926 | open_group(store, "w")
|
| 927 | + |
| 928 | + |
| 929 | +def test_open_falls_back_to_open_group() -> None: |
| 930 | + # https://github.com/zarr-developers/zarr-python/issues/2309 |
| 931 | + store = MemoryStore(mode="w") |
| 932 | + zarr.open_group(store, attributes={"key": "value"}) |
| 933 | + |
| 934 | + group = zarr.open(store) |
| 935 | + assert isinstance(group, Group) |
| 936 | + assert group.attrs == {"key": "value"} |
| 937 | + |
| 938 | + |
| 939 | +async def test_open_falls_back_to_open_group_async() -> None: |
| 940 | + # https://github.com/zarr-developers/zarr-python/issues/2309 |
| 941 | + store = MemoryStore(mode="w") |
| 942 | + await zarr.api.asynchronous.open_group(store, attributes={"key": "value"}) |
| 943 | + |
| 944 | + group = await zarr.api.asynchronous.open(store=store) |
| 945 | + assert isinstance(group, zarr.core.group.AsyncGroup) |
| 946 | + assert group.attrs == {"key": "value"} |
| 947 | + |
| 948 | + |
| 949 | +async def test_metadata_validation_error() -> None: |
| 950 | + with pytest.raises( |
| 951 | + MetadataValidationError, |
| 952 | + match="Invalid value for 'zarr_format'. Expected '2, 3, or None'. Got '3.0'.", |
| 953 | + ): |
| 954 | + await zarr.api.asynchronous.open_group(zarr_format="3.0") # type: ignore[arg-type] |
| 955 | + |
| 956 | + with pytest.raises( |
| 957 | + MetadataValidationError, |
| 958 | + match="Invalid value for 'zarr_format'. Expected '2, 3, or None'. Got '3.0'.", |
| 959 | + ): |
| 960 | + await zarr.api.asynchronous.open_array(shape=(1,), zarr_format="3.0") # type: ignore[arg-type] |
0 commit comments