|
5 | 5 |
|
6 | 6 | import pytest |
7 | 7 |
|
8 | | -from zarr.storage._utils import ParsedStoreUrl, parse_store_url |
| 8 | +from tests.conftest import Expect, ExpectFail |
| 9 | +from zarr.storage._utils import ParsedStoreUrl, _dereference_path, parse_store_url |
9 | 10 |
|
10 | 11 |
|
11 | 12 | class TestParseStoreUrl: |
@@ -95,3 +96,47 @@ def test_drive_letter_not_special_on_non_windows(self, url: str) -> None: |
95 | 96 | result = parse_store_url(url) |
96 | 97 | # urlparse interprets the drive letter as a scheme |
97 | 98 | assert result.scheme == "c" |
| 99 | + |
| 100 | + |
| 101 | +@pytest.mark.parametrize( |
| 102 | + "case", |
| 103 | + [ |
| 104 | + Expect(input=("root", "path"), output="root/path", id="basic"), |
| 105 | + Expect(input=("root", ""), output="root", id="empty_path"), |
| 106 | + Expect(input=("", "path"), output="path", id="empty_root"), |
| 107 | + Expect(input=("", ""), output="", id="both_empty"), |
| 108 | + Expect(input=("root/", "path"), output="root/path", id="root_trailing_slash"), |
| 109 | + Expect(input=("root//", "path"), output="root/path", id="root_multiple_trailing_slashes"), |
| 110 | + Expect(input=("root", "path/"), output="root/path", id="path_trailing_slash"), |
| 111 | + Expect(input=("a/b", "c/d"), output="a/b/c/d", id="nested"), |
| 112 | + Expect(input=("memory://store", "key"), output="memory://store/key", id="url_root"), |
| 113 | + ], |
| 114 | + ids=lambda case: case.id, |
| 115 | +) |
| 116 | +def test_dereference_path(case: Expect[tuple[str, str], str]) -> None: |
| 117 | + """ |
| 118 | + Test the normal behavior of _dereference_path |
| 119 | + """ |
| 120 | + root, path = case.input |
| 121 | + assert _dereference_path(root, path) == case.output |
| 122 | + |
| 123 | + |
| 124 | +@pytest.mark.parametrize( |
| 125 | + "case", |
| 126 | + [ |
| 127 | + ExpectFail( |
| 128 | + input=(1, "path"), exception=TypeError, msg="root=.*not a string", id="root_not_str" |
| 129 | + ), |
| 130 | + ExpectFail( |
| 131 | + input=("root", 1), exception=TypeError, msg="path=.*not a string", id="path_not_str" |
| 132 | + ), |
| 133 | + ], |
| 134 | + ids=lambda case: case.id, |
| 135 | +) |
| 136 | +def test_dereference_path_errors(case: ExpectFail[tuple[object, object]]) -> None: |
| 137 | + """ |
| 138 | + Test that _dereference_path raises TypeError for non-string inputs. |
| 139 | + """ |
| 140 | + root, path = case.input |
| 141 | + with pytest.raises(case.exception, match=case.msg): |
| 142 | + _dereference_path(root, path) # type: ignore[arg-type] |
0 commit comments