|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
3 |
| -from typing import TYPE_CHECKING |
| 3 | +import pathlib |
| 4 | +import re |
4 | 5 |
|
| 6 | +import numpy as np |
5 | 7 | import pytest
|
6 | 8 |
|
7 | 9 | import zarr
|
| 10 | +from zarr import create_array |
8 | 11 | from zarr.core.buffer import Buffer, cpu
|
9 | 12 | from zarr.storage import LocalStore
|
10 | 13 | from zarr.testing.store import StoreTests
|
11 | 14 | from zarr.testing.utils import assert_bytes_equal
|
12 | 15 |
|
13 |
| -if TYPE_CHECKING: |
14 |
| - import pathlib |
15 |
| - |
16 | 16 |
|
17 | 17 | class TestLocalStore(StoreTests[LocalStore, cpu.Buffer]):
|
18 | 18 | store_cls = LocalStore
|
@@ -74,3 +74,38 @@ async def test_get_with_prototype_default(self, store: LocalStore) -> None:
|
74 | 74 | await self.set(store, key, data_buf)
|
75 | 75 | observed = await store.get(key, prototype=None)
|
76 | 76 | assert_bytes_equal(observed, data_buf)
|
| 77 | + |
| 78 | + @pytest.mark.parametrize("ndim", [0, 1, 3]) |
| 79 | + @pytest.mark.parametrize( |
| 80 | + "destination", ["destination", "foo/bar/destintion", pathlib.Path("foo/bar/destintion")] |
| 81 | + ) |
| 82 | + async def test_move( |
| 83 | + self, tmp_path: pathlib.Path, ndim: int, destination: pathlib.Path | str |
| 84 | + ) -> None: |
| 85 | + origin = tmp_path / "origin" |
| 86 | + if isinstance(destination, str): |
| 87 | + destination = str(tmp_path / destination) |
| 88 | + else: |
| 89 | + destination = tmp_path / destination |
| 90 | + |
| 91 | + print(type(destination)) |
| 92 | + store = await LocalStore.open(root=origin) |
| 93 | + shape = (4,) * ndim |
| 94 | + chunks = (2,) * ndim |
| 95 | + data = np.arange(4**ndim) |
| 96 | + if ndim > 0: |
| 97 | + data = data.reshape(*shape) |
| 98 | + array = create_array(store, data=data, chunks=chunks or "auto") |
| 99 | + |
| 100 | + await store.move(destination) |
| 101 | + |
| 102 | + assert store.root == pathlib.Path(destination) |
| 103 | + assert pathlib.Path(destination).exists() |
| 104 | + assert not origin.exists() |
| 105 | + assert np.array_equal(array[...], data) |
| 106 | + |
| 107 | + store2 = await LocalStore.open(root=origin) |
| 108 | + with pytest.raises( |
| 109 | + FileExistsError, match=re.escape(f"Destination root {destination} already exists") |
| 110 | + ): |
| 111 | + await store2.move(destination) |
0 commit comments