Skip to content

Commit

Permalink
docstrings, add some Nones to test_get_partial_values; normalize func…
Browse files Browse the repository at this point in the history
…tion signatures
  • Loading branch information
d-v-b committed May 23, 2024
1 parent 8915ff3 commit fb2a46d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/zarr/abc/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async def get(

@abstractmethod
async def get_partial_values(
self, key_ranges: list[tuple[str, tuple[int, int]]]
self, key_ranges: list[tuple[str, tuple[int | None, int | None]]]
) -> list[Buffer | None]:
"""Retrieve possibly partial values from given key_ranges.
Expand Down
2 changes: 1 addition & 1 deletion src/zarr/store/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async def get(
return None

async def get_partial_values(
self, key_ranges: list[tuple[str, tuple[int, int]]]
self, key_ranges: list[tuple[str, tuple[int | None, int | None]]]
) -> list[Buffer | None]:
"""
Read byte ranges from multiple keys.
Expand Down
2 changes: 1 addition & 1 deletion src/zarr/store/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async def get(
return None

async def get_partial_values(
self, key_ranges: list[tuple[str, tuple[int, int]]]
self, key_ranges: list[tuple[str, tuple[int | None, int | None]]]
) -> list[Buffer | None]:
vals = await concurrent_map(key_ranges, self.get, limit=None)
return vals
Expand Down
21 changes: 15 additions & 6 deletions src/zarr/testing/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ class StoreTests(Generic[S]):

def set(self, store: S, key: str, value: Buffer) -> None:
"""
Insert key: value pairs into a store without using the store methods.
Insert a value into a storage backend, with a specific key.
This should not not use any store methods. Bypassing the store methods allows them to be
tested.
"""
raise NotImplementedError

def get(self, store: S, key: str) -> Buffer:
"""
Retrieve values from a store without using the store methods.
Retrieve a value from a storage backend, by key.
This should not not use any store methods. Bypassing the store methods allows them to be
tested.
"""

raise NotImplementedError
Expand Down Expand Up @@ -52,7 +56,9 @@ def test_store_supports_listing(self, store: S) -> None:
async def test_get(
self, store: S, key: str, data: bytes, byte_range: None | tuple[int | None, int | None]
) -> None:
# insert values into the store
"""
Ensure that data can be read from the store using the store.get method.
"""
data_buf = Buffer.from_bytes(data)
self.set(store, key, data_buf)
observed = await store.get(key, byte_range=byte_range)
Expand All @@ -63,6 +69,9 @@ async def test_get(
@pytest.mark.parametrize("key", ["zarr.json", "c/0", "foo/c/0.0", "foo/0/0"])
@pytest.mark.parametrize("data", [b"\x01\x02\x03\x04", b""])
async def test_set(self, store: S, key: str, data: bytes) -> None:
"""
Ensure that data can be written to the store using the store.set method.
"""
data_buf = Buffer.from_bytes(data)
await store.set(key, data_buf)
observed = self.get(store, key)
Expand All @@ -73,12 +82,12 @@ async def test_set(self, store: S, key: str, data: bytes) -> None:
(
[],
[("zarr.json", (0, 1))],
[("c/0", (0, 1)), ("zarr.json", (0, 2))],
[("c/0/0", (0, 1)), ("c/0/1", (0, 2)), ("c/0/2", (0, 3))],
[("c/0", (0, 1)), ("zarr.json", (0, None))],
[("c/0/0", (0, 1)), ("c/0/1", (None, 2)), ("c/0/2", (0, 3))],
),
)
async def test_get_partial_values(
self, store: S, key_ranges: list[tuple[str, tuple[int, int]]]
self, store: S, key_ranges: list[tuple[str, tuple[int | None, int | None]]]
) -> None:
# put all of the data
for key, _ in key_ranges:
Expand Down

0 comments on commit fb2a46d

Please sign in to comment.