Skip to content

Commit dff7034

Browse files
committed
Apply suggestion to shorten try block
1 parent 2789f4c commit dff7034

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

src/zarr/testing/store.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -163,43 +163,43 @@ async def test_with_read_only_store(self, open_kwargs: dict[str, Any]) -> None:
163163
# Check if the store implements with_read_only
164164
try:
165165
writer = store.with_read_only(read_only=False)
166-
167-
# Test that you can write to a new store copy
168-
assert not writer._is_open
169-
assert not writer.read_only
170-
await writer.set("foo", self.buffer_cls.from_bytes(b"bar"))
171-
await writer.delete("foo")
172-
173-
# Test that you cannot write to the original store
174-
assert store.read_only
175-
with pytest.raises(
176-
ValueError, match="store was opened in read-only mode and does not support writing"
177-
):
178-
await store.set("foo", self.buffer_cls.from_bytes(b"bar"))
179-
with pytest.raises(
180-
ValueError, match="store was opened in read-only mode and does not support writing"
181-
):
182-
await store.delete("foo")
183-
184-
# Test that you cannot write to a read-only store copy
185-
reader = store.with_read_only(read_only=True)
186-
assert reader.read_only
187-
with pytest.raises(
188-
ValueError, match="store was opened in read-only mode and does not support writing"
189-
):
190-
await reader.set("foo", self.buffer_cls.from_bytes(b"bar"))
191-
with pytest.raises(
192-
ValueError, match="store was opened in read-only mode and does not support writing"
193-
):
194-
await reader.delete("foo")
195-
196166
except NotImplementedError:
197167
# Test that stores that do not implement with_read_only raise NotImplementedError with the correct message
198168
with pytest.raises(
199169
NotImplementedError,
200170
match=f"with_read_only is not implemented for the {type(store)} store type.",
201171
):
202172
store.with_read_only(read_only=False)
173+
return
174+
175+
# Test that you can write to a new store copy
176+
assert not writer._is_open
177+
assert not writer.read_only
178+
await writer.set("foo", self.buffer_cls.from_bytes(b"bar"))
179+
await writer.delete("foo")
180+
181+
# Test that you cannot write to the original store
182+
assert store.read_only
183+
with pytest.raises(
184+
ValueError, match="store was opened in read-only mode and does not support writing"
185+
):
186+
await store.set("foo", self.buffer_cls.from_bytes(b"bar"))
187+
with pytest.raises(
188+
ValueError, match="store was opened in read-only mode and does not support writing"
189+
):
190+
await store.delete("foo")
191+
192+
# Test that you cannot write to a read-only store copy
193+
reader = store.with_read_only(read_only=True)
194+
assert reader.read_only
195+
with pytest.raises(
196+
ValueError, match="store was opened in read-only mode and does not support writing"
197+
):
198+
await reader.set("foo", self.buffer_cls.from_bytes(b"bar"))
199+
with pytest.raises(
200+
ValueError, match="store was opened in read-only mode and does not support writing"
201+
):
202+
await reader.delete("foo")
203203

204204
@pytest.mark.parametrize("key", ["c/0", "foo/c/0.0", "foo/0/0"])
205205
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)