From fb2a46d999a96806864ef0679d84c791e5ce4d80 Mon Sep 17 00:00:00 2001 From: Davis Vann Bennett Date: Thu, 23 May 2024 13:56:56 +0200 Subject: [PATCH] docstrings, add some Nones to test_get_partial_values; normalize function signatures --- src/zarr/abc/store.py | 2 +- src/zarr/store/local.py | 2 +- src/zarr/store/memory.py | 2 +- src/zarr/testing/store.py | 21 +++++++++++++++------ 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/zarr/abc/store.py b/src/zarr/abc/store.py index d7cb56ca1..7087706b3 100644 --- a/src/zarr/abc/store.py +++ b/src/zarr/abc/store.py @@ -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. diff --git a/src/zarr/store/local.py b/src/zarr/store/local.py index 7328cd858..50fe9701f 100644 --- a/src/zarr/store/local.py +++ b/src/zarr/store/local.py @@ -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. diff --git a/src/zarr/store/memory.py b/src/zarr/store/memory.py index 888215147..5e438919c 100644 --- a/src/zarr/store/memory.py +++ b/src/zarr/store/memory.py @@ -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 diff --git a/src/zarr/testing/store.py b/src/zarr/testing/store.py index d59e245d5..1c0ed9373 100644 --- a/src/zarr/testing/store.py +++ b/src/zarr/testing/store.py @@ -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 @@ -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) @@ -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) @@ -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: