-
-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature(store): list_* -> AsyncGenerators #1844
Merged
jhamman
merged 5 commits into
zarr-developers:v3
from
jhamman:feature/store-list-async-gen
May 7, 2024
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0e035fb
feature(store): list_* -> AsyncGenerators
jhamman eb49dd6
revert changes to v2/test_storage.py
jhamman 26f071d
Merge branch 'v3' of https://github.com/zarr-developers/zarr-python i…
jhamman 8b4d4cf
fix v2 import
jhamman e984e20
Merge branch 'v3' into feature/store-list-async-gen
jhamman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import importlib.util | ||
import warnings | ||
|
||
if importlib.util.find_spec("pytest") is not None: | ||
from zarr.testing.store import StoreTests | ||
else: | ||
warnings.warn("pytest not installed, skipping test suite") | ||
|
||
__all__ = ["StoreTests"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import pytest | ||
|
||
from zarr.abc.store import Store | ||
|
||
|
||
class StoreTests: | ||
store_cls: type[Store] | ||
|
||
@pytest.fixture(scope="function") | ||
def store(self) -> Store: | ||
return self.store_cls() | ||
|
||
def test_store_type(self, store: Store) -> None: | ||
assert isinstance(store, Store) | ||
assert isinstance(store, self.store_cls) | ||
|
||
def test_store_repr(self, store: Store) -> None: | ||
assert repr(store) | ||
|
||
def test_store_capabilities(self, store: Store) -> None: | ||
assert store.supports_writes | ||
assert store.supports_partial_writes | ||
assert store.supports_listing | ||
|
||
@pytest.mark.parametrize("key", ["c/0", "foo/c/0.0", "foo/0/0"]) | ||
@pytest.mark.parametrize("data", [b"\x01\x02\x03\x04", b""]) | ||
async def test_set_get_bytes_roundtrip(self, store: Store, key: str, data: bytes) -> None: | ||
await store.set(key, data) | ||
assert await store.get(key) == data | ||
|
||
@pytest.mark.parametrize("key", ["foo/c/0"]) | ||
@pytest.mark.parametrize("data", [b"\x01\x02\x03\x04", b""]) | ||
async def test_get_partial_values(self, store: Store, key: str, data: bytes) -> None: | ||
# put all of the data | ||
await store.set(key, data) | ||
# read back just part of it | ||
vals = await store.get_partial_values([(key, (0, 2))]) | ||
assert vals == [data[0:2]] | ||
|
||
# read back multiple parts of it at once | ||
vals = await store.get_partial_values([(key, (0, 2)), (key, (2, 4))]) | ||
assert vals == [data[0:2], data[2:4]] | ||
|
||
async def test_exists(self, store: Store) -> None: | ||
assert not await store.exists("foo") | ||
await store.set("foo/zarr.json", b"bar") | ||
assert await store.exists("foo/zarr.json") | ||
|
||
async def test_delete(self, store: Store) -> None: | ||
await store.set("foo/zarr.json", b"bar") | ||
assert await store.exists("foo/zarr.json") | ||
await store.delete("foo/zarr.json") | ||
assert not await store.exists("foo/zarr.json") | ||
|
||
async def test_list(self, store: Store) -> None: | ||
assert [k async for k in store.list()] == [] | ||
await store.set("foo/zarr.json", b"bar") | ||
keys = [k async for k in store.list()] | ||
assert keys == ["foo/zarr.json"], keys | ||
|
||
expected = ["foo/zarr.json"] | ||
for i in range(10): | ||
key = f"foo/c/{i}" | ||
expected.append(key) | ||
await store.set(f"foo/c/{i}", i.to_bytes(length=3, byteorder="little")) | ||
|
||
async def test_list_prefix(self, store: Store) -> None: | ||
# TODO: we currently don't use list_prefix anywhere | ||
pass | ||
|
||
async def test_list_dir(self, store: Store) -> None: | ||
assert [k async for k in store.list_dir("")] == [] | ||
assert [k async for k in store.list_dir("foo")] == [] | ||
await store.set("foo/zarr.json", b"bar") | ||
await store.set("foo/c/1", b"\x01") | ||
|
||
keys = [k async for k in store.list_dir("foo")] | ||
assert keys == ["zarr.json", "c"], keys | ||
|
||
keys = [k async for k in store.list_dir("foo/")] | ||
assert keys == ["zarr.json", "c"], keys |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea here is that we will provide a test harness for the generic store interface. This doesn't mean we can't have store-specific tests but those can go in our tests directory.
Importing
zarr.testing.store
will raise anImportError
if pytest is not installed. I think that could be fine but calling it out so others have a chance to comment. I think there are some things we can do to further hide this import if folks object to the current configuration.