Skip to content

Commit 0328e01

Browse files
committed
test(storage): add SupportsGetRanges conformance tests
1 parent 913be10 commit 0328e01

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

tests/test_store/test_protocols.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# tests/test_store/test_protocols.py
2+
"""Runtime and static conformance tests for zarr.storage._protocols.SupportsGetRanges."""
3+
4+
from __future__ import annotations
5+
6+
import pytest
7+
8+
from zarr.storage._protocols import SupportsGetRanges
9+
10+
11+
def test_fsspec_store_satisfies_supports_get_ranges() -> None:
12+
pytest.importorskip("fsspec")
13+
from fsspec.implementations.memory import MemoryFileSystem
14+
15+
from zarr.storage import FsspecStore
16+
from zarr.storage._fsspec import _make_async
17+
18+
fs = MemoryFileSystem()
19+
fs.store.clear()
20+
store = FsspecStore(fs=_make_async(fs), path="/x")
21+
assert isinstance(store, SupportsGetRanges)
22+
23+
24+
def test_memory_store_does_not_satisfy_supports_get_ranges() -> None:
25+
"""Sanity check: stores that don't implement get_ranges shouldn't satisfy the protocol."""
26+
from zarr.storage import MemoryStore
27+
28+
store = MemoryStore()
29+
assert not isinstance(store, SupportsGetRanges)
30+
31+
32+
def test_type_assignment_at_module_level() -> None:
33+
"""Smoke-test the module-level `_: type[SupportsGetRanges] = FsspecStore`.
34+
35+
If this runs without error the module imported cleanly; the static check is in mypy.
36+
"""
37+
pytest.importorskip("fsspec")
38+
from zarr.storage import _fsspec # noqa: F401

0 commit comments

Comments
 (0)