|
1 | 1 | import tempfile |
2 | 2 | from pathlib import Path |
3 | 3 |
|
| 4 | +import numpy as np |
4 | 5 | import pytest |
5 | 6 | from _pytest.compat import LEGACY_PATH |
6 | 7 |
|
7 | | -from zarr import Group |
| 8 | +from zarr import Group, open_group |
8 | 9 | from zarr.core.common import AccessModeLiteral, ZarrFormat |
9 | | -from zarr.storage import FsspecStore, LocalStore, MemoryStore, StoreLike, StorePath |
| 10 | +from zarr.storage import FsspecStore, LocalStore, MemoryStore, StoreLike, StorePath, ZipStore |
10 | 11 | from zarr.storage._common import contains_array, contains_group, make_store_path |
11 | 12 | from zarr.storage._utils import normalize_path |
12 | 13 |
|
@@ -83,6 +84,36 @@ async def test_make_store_path_local( |
83 | 84 | assert store_path.read_only == (mode == "r") |
84 | 85 |
|
85 | 86 |
|
| 87 | +@pytest.mark.parametrize("store_type", [str, Path]) |
| 88 | +@pytest.mark.parametrize("mode", ["r", "w"]) |
| 89 | +async def test_make_store_path_zip_path( |
| 90 | + tmpdir: LEGACY_PATH, |
| 91 | + store_type: type[str] | type[Path] | type[LocalStore], |
| 92 | + mode: AccessModeLiteral, |
| 93 | +) -> None: |
| 94 | + """ |
| 95 | + Test that make_store_path creates a ZipStore given a path ending in .zip |
| 96 | + """ |
| 97 | + zippath = Path(tmpdir) / "zarr.zip" |
| 98 | + store_like = store_type(str(zippath)) |
| 99 | + |
| 100 | + if mode == "r": |
| 101 | + store = ZipStore(zippath, mode="w") |
| 102 | + root = open_group(store=store, mode="w") |
| 103 | + data = np.arange(10000, dtype=np.uint16).reshape(100, 100) |
| 104 | + z = root.create_array( |
| 105 | + shape=data.shape, chunks=(10, 10), name="foo", dtype=np.uint16, fill_value=99 |
| 106 | + ) |
| 107 | + z[:] = data |
| 108 | + store.close() |
| 109 | + |
| 110 | + store_path = await make_store_path(store_like, mode=mode) |
| 111 | + assert isinstance(store_path.store, ZipStore) |
| 112 | + assert Path(store_path.store.path) == zippath |
| 113 | + assert store_path.path == normalize_path("") |
| 114 | + assert store_path.read_only == (mode == "r") |
| 115 | + |
| 116 | + |
86 | 117 | @pytest.mark.parametrize("path", [None, "", "bar"]) |
87 | 118 | @pytest.mark.parametrize("mode", ["r", "w"]) |
88 | 119 | async def test_make_store_path_store_path( |
|
0 commit comments