Skip to content

Commit cbf1a61

Browse files
committed
xfail zipstore in open_array test
1 parent e29e072 commit cbf1a61

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

tests/test_api.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import pytest
66
from numpy.testing import assert_array_equal
77

8-
from tests.conftest import as_immutable
98
import zarr
109
import zarr.api.asynchronous
1110
import zarr.core.group
11+
from tests.conftest import as_immutable
1212
from zarr import Array, Group
1313
from zarr.abc.store import Store
1414
from zarr.api.synchronous import (
@@ -64,26 +64,30 @@ def test_open_normalized_path(
6464
assert node.path == normalize_path(path)
6565

6666

67-
@pytest.mark.parametrize("store", ["local", "memory", "remote", "zip"], indirect=True)
67+
@pytest.mark.parametrize(
68+
"store",
69+
["local", "memory", "remote", pytest.param("zip", marks=pytest.mark.xfail)],
70+
indirect=True,
71+
)
6872
async def test_open_array(store: Store, zarr_format: ZarrFormat) -> None:
6973
# open array, create if doesn't exist
7074
z = open(store=store, shape=100, zarr_format=zarr_format)
7175
assert isinstance(z, Array)
7276
assert z.shape == (100,)
7377

74-
75-
z = open(store=store, shape=200, zarr_format=zarr_format, mode='w')
78+
# invoke open again, with a different shape and mode w.
79+
# We expect the store to be wiped at the current path and new array to come out.
80+
z = open(store=store, shape=200, zarr_format=zarr_format, mode="w")
7681
assert isinstance(z, Array)
7782
assert z.shape == (200,)
7883

7984
store_r = as_immutable(store)
80-
z = open(store=store_r, zarr_format=zarr_format, mode='r')
85+
z = open(store=store_r, zarr_format=zarr_format, mode="r")
8186
assert isinstance(z, Array)
8287
assert z.shape == (200,)
8388
assert z.read_only
8489

8590

86-
# zipstore is marked as xfail because you cannot open a zipstore in read-only mode if it doesn't exist in the first place.
8791
@pytest.mark.parametrize(
8892
"store",
8993
["local", "memory", "remote", "zip"],
@@ -112,7 +116,7 @@ async def test_open_group(store: Store) -> None:
112116
# assert "foo" not in g
113117
store_r = as_immutable(store)
114118

115-
g = open_group(store=store_r)
119+
g = open_group(store=store_r, mode="r")
116120
assert isinstance(g, Group)
117121

118122
if isinstance(store, ZipStore):
@@ -1103,3 +1107,19 @@ async def test_metadata_validation_error() -> None:
11031107
match="Invalid value for 'zarr_format'. Expected '2, 3, or None'. Got '3.0'.",
11041108
):
11051109
await zarr.api.asynchronous.open_array(shape=(1,), zarr_format="3.0") # type: ignore[arg-type]
1110+
1111+
1112+
@pytest.mark.parametrize(
1113+
"store",
1114+
["local", "memory", "remote", "zip"],
1115+
indirect=True,
1116+
)
1117+
def test_open_array_with_mode_r_plus(store: Store) -> None:
1118+
# 'r+' means read/write (must exist)
1119+
with pytest.raises(FileNotFoundError):
1120+
zarr.open_array(store=store, mode="r+")
1121+
zarr.ones(store=store, shape=(3, 3))
1122+
z2 = zarr.open(store=store, mode="r+")
1123+
assert isinstance(z2, Array)
1124+
assert (z2[:] == 1).all()
1125+
z2[:] = 3

0 commit comments

Comments
 (0)