-
-
Notifications
You must be signed in to change notification settings - Fork 356
chore/add missing tests #3353
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
Merged
Merged
chore/add missing tests #3353
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
aa79f2d
exclude notimplementederrors from test coverage
d-v-b 85665e0
add tests for untested features of api.asynchronous
d-v-b 83799df
add tests for untested features of api.asynchronous
d-v-b d828ac7
remove whitespace removal
d-v-b dddb0b5
Merge branch 'main' into chore/add-missing-tests
d-v-b 4b40f2e
fix import of arraylike
d-v-b 28bd51e
Merge branch 'chore/add-missing-tests' of github.com:d-v-b/zarr-pytho…
d-v-b 9117776
be more explicit about the data type
d-v-b f6016db
Merge branch 'main' into chore/add-missing-tests
d-v-b 95097a7
Merge branch 'main' into chore/add-missing-tests
d-v-b 5cacdcb
Merge branch 'main' into chore/add-missing-tests
d-v-b 9d13b60
Update tests/test_api/test_asynchronous.py
d-v-b a9b4ad2
Merge branch 'main' into chore/add-missing-tests
d-v-b 14e5573
Merge branch 'main' into chore/add-missing-tests
d-v-b 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 hidden or 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 hidden or 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,105 @@ | ||
from __future__ import annotations | ||
|
||
import json | ||
from dataclasses import dataclass | ||
from typing import TYPE_CHECKING | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
from zarr import create_array | ||
from zarr.api.asynchronous import _get_shape_chunks, _like_args, open | ||
from zarr.core.buffer.core import default_buffer_prototype | ||
|
||
if TYPE_CHECKING: | ||
from typing import Any | ||
|
||
import numpy.typing as npt | ||
|
||
from zarr.core.array import Array, AsyncArray | ||
from zarr.core.metadata import ArrayV2Metadata, ArrayV3Metadata | ||
|
||
|
||
@dataclass | ||
class WithShape: | ||
shape: tuple[int, ...] | ||
|
||
|
||
@dataclass | ||
class WithChunks(WithShape): | ||
chunks: tuple[int, ...] | ||
|
||
|
||
@dataclass | ||
class WithChunkLen(WithShape): | ||
chunklen: int | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("observed", "expected"), | ||
[ | ||
({}, (None, None)), | ||
(WithShape(shape=(1, 2)), ((1, 2), None)), | ||
(WithChunks(shape=(1, 2), chunks=(1, 2)), ((1, 2), (1, 2))), | ||
(WithChunkLen(shape=(10, 10), chunklen=1), ((10, 10), (1, 10))), | ||
], | ||
) | ||
def test_get_shape_chunks( | ||
observed: object, expected: tuple[tuple[int, ...] | None, tuple[int, ...] | None] | ||
) -> None: | ||
""" | ||
Test the _get_shape_chunks function | ||
""" | ||
assert _get_shape_chunks(observed) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("observed", "expected"), | ||
[ | ||
(np.arange(10, dtype=np.dtype("int64")), {"shape": (10,), "dtype": np.dtype("int64")}), | ||
(WithChunks(shape=(1, 2), chunks=(1, 2)), {"chunks": (1, 2), "shape": (1, 2)}), | ||
( | ||
create_array( | ||
{}, | ||
chunks=(10,), | ||
shape=(100,), | ||
dtype="f8", | ||
compressors=None, | ||
filters=None, | ||
zarr_format=2, | ||
)._async_array, | ||
{ | ||
"chunks": (10,), | ||
"shape": (100,), | ||
"dtype": np.dtype("f8"), | ||
"compressor": None, | ||
"filters": None, | ||
"order": "C", | ||
}, | ||
), | ||
], | ||
) | ||
def test_like_args( | ||
observed: AsyncArray[ArrayV2Metadata] | AsyncArray[ArrayV3Metadata] | Array | npt.NDArray[Any], | ||
expected: object, | ||
) -> None: | ||
""" | ||
Test the like_args function | ||
""" | ||
assert _like_args(observed, {}) == expected | ||
|
||
|
||
async def test_open_no_array() -> None: | ||
""" | ||
Test that zarr.api.asynchronous.open attempts to open a group when no array is found, but shape was specified in kwargs. | ||
This behavior makes no sense but we should still test it. | ||
""" | ||
store = { | ||
"zarr.json": default_buffer_prototype().buffer.from_bytes( | ||
json.dumps({"zarr_format": 3, "node_type": "group"}).encode("utf-8") | ||
) | ||
} | ||
with pytest.raises( | ||
TypeError, match=r"open_group\(\) got an unexpected keyword argument 'shape'" | ||
): | ||
await open(store=store, shape=(1,)) |
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.
Uh oh!
There was an error while loading. Please reload this page.