|
8 | 8 | from zarr.core.common import AccessModeLiteral, ZarrFormat
|
9 | 9 | from zarr.storage import FsspecStore, LocalStore, MemoryStore, StoreLike, StorePath
|
10 | 10 | from zarr.storage._common import contains_array, contains_group, make_store_path
|
11 |
| -from zarr.storage._utils import _join_paths, _normalize_path_keys, _normalize_paths, normalize_path |
| 11 | +from zarr.storage._utils import ( |
| 12 | + _join_paths, |
| 13 | + _normalize_path_keys, |
| 14 | + _normalize_paths, |
| 15 | + _relativize_path, |
| 16 | + normalize_path, |
| 17 | +) |
12 | 18 |
|
13 | 19 |
|
14 | 20 | @pytest.mark.parametrize("path", ["foo", "foo/bar"])
|
@@ -221,3 +227,27 @@ def test_normalize_path_keys():
|
221 | 227 | """
|
222 | 228 | data = {"a": 10, "//b": 10}
|
223 | 229 | assert _normalize_path_keys(data) == {normalize_path(k): v for k, v in data.items()}
|
| 230 | + |
| 231 | + |
| 232 | +@pytest.mark.parametrize( |
| 233 | + ("path", "prefix", "expected"), |
| 234 | + [ |
| 235 | + ("a", "", "a"), |
| 236 | + ("a/b/c", "a/b", "c"), |
| 237 | + ("a/b/c", "a", "b/c"), |
| 238 | + ], |
| 239 | +) |
| 240 | +def test_relativize_path_valid(path: str, prefix: str, expected: str) -> None: |
| 241 | + """ |
| 242 | + Test the normal behavior of the _relativize_path function. Prefixes should be removed from the |
| 243 | + path argument. |
| 244 | + """ |
| 245 | + assert _relativize_path(path=path, prefix=prefix) == expected |
| 246 | + |
| 247 | + |
| 248 | +def test_relativize_path_invalid() -> None: |
| 249 | + path = "a/b/c" |
| 250 | + prefix = "b" |
| 251 | + msg = f"The first component of {path} does not start with {prefix}." |
| 252 | + with pytest.raises(ValueError, match=msg): |
| 253 | + _relativize_path(path="a/b/c", prefix="b") |
0 commit comments