|
29 | 29 | create_group, |
30 | 30 | group, |
31 | 31 | load, |
32 | | - open, |
33 | 32 | open_group, |
34 | 33 | save, |
35 | 34 | save_array, |
|
41 | 40 | from zarr.storage._utils import normalize_path |
42 | 41 | from zarr.testing.utils import gpu_test |
43 | 42 |
|
| 43 | +if TYPE_CHECKING: |
| 44 | + from pathlib import Path |
| 45 | + |
44 | 46 |
|
45 | 47 | def test_create(memory_store: Store) -> None: |
46 | 48 | store = memory_store |
@@ -135,28 +137,28 @@ async def test_open_array(memory_store: MemoryStore, zarr_format: ZarrFormat) -> |
135 | 137 | store = memory_store |
136 | 138 |
|
137 | 139 | # open array, create if doesn't exist |
138 | | - z = open(store=store, shape=100, zarr_format=zarr_format) |
| 140 | + z = zarr.api.synchronous.open(store=store, shape=100, zarr_format=zarr_format) |
139 | 141 | assert isinstance(z, Array) |
140 | 142 | assert z.shape == (100,) |
141 | 143 |
|
142 | 144 | # open array, overwrite |
143 | 145 | # store._store_dict = {} |
144 | 146 | store = MemoryStore() |
145 | | - z = open(store=store, shape=200, zarr_format=zarr_format) |
| 147 | + z = zarr.api.synchronous.open(store=store, shape=200, zarr_format=zarr_format) |
146 | 148 | assert isinstance(z, Array) |
147 | 149 | assert z.shape == (200,) |
148 | 150 |
|
149 | 151 | # open array, read-only |
150 | 152 | store_cls = type(store) |
151 | 153 | ro_store = await store_cls.open(store_dict=store._store_dict, read_only=True) |
152 | | - z = open(store=ro_store, mode="r") |
| 154 | + z = zarr.api.synchronous.open(store=ro_store, mode="r") |
153 | 155 | assert isinstance(z, Array) |
154 | 156 | assert z.shape == (200,) |
155 | 157 | assert z.read_only |
156 | 158 |
|
157 | 159 | # path not found |
158 | 160 | with pytest.raises(FileNotFoundError): |
159 | | - open(store="doesnotexist", mode="r", zarr_format=zarr_format) |
| 161 | + zarr.api.synchronous.open(store="doesnotexist", mode="r", zarr_format=zarr_format) |
160 | 162 |
|
161 | 163 |
|
162 | 164 | @pytest.mark.parametrize("store", ["memory", "local", "zip"], indirect=True) |
@@ -233,12 +235,12 @@ def test_save(store: Store, n_args: int, n_kwargs: int) -> None: |
233 | 235 | save(store) |
234 | 236 | elif n_args == 1 and n_kwargs == 0: |
235 | 237 | save(store, *args) |
236 | | - array = open(store) |
| 238 | + array = zarr.api.synchronous.open(store) |
237 | 239 | assert isinstance(array, Array) |
238 | 240 | assert_array_equal(array[:], data) |
239 | 241 | else: |
240 | 242 | save(store, *args, **kwargs) # type: ignore [arg-type] |
241 | | - group = open(store) |
| 243 | + group = zarr.api.synchronous.open(store) |
242 | 244 | assert isinstance(group, Group) |
243 | 245 | for array in group.array_values(): |
244 | 246 | assert_array_equal(array[:], data) |
@@ -1077,7 +1079,7 @@ def test_tree() -> None: |
1077 | 1079 | def test_open_positional_args_deprecated() -> None: |
1078 | 1080 | store = MemoryStore() |
1079 | 1081 | with pytest.warns(FutureWarning, match="pass"): |
1080 | | - open(store, "w", shape=(1,)) |
| 1082 | + zarr.api.synchronous.open(store, "w", shape=(1,)) |
1081 | 1083 |
|
1082 | 1084 |
|
1083 | 1085 | def test_save_array_positional_args_deprecated() -> None: |
@@ -1236,3 +1238,13 @@ def test_v2_with_v3_compressor() -> None: |
1236 | 1238 | zarr.create( |
1237 | 1239 | store={}, shape=(1), dtype="uint8", zarr_format=2, compressor=zarr.codecs.BloscCodec() |
1238 | 1240 | ) |
| 1241 | + |
| 1242 | + |
| 1243 | +def test_create_no_delete_file(tmp_path: Path) -> None: |
| 1244 | + with open(tmp_path / "file.txt", "w") as f: |
| 1245 | + f.write("abc") |
| 1246 | + |
| 1247 | + with pytest.raises(NotImplementedError, match="loading groups not yet supported"): |
| 1248 | + zarr.load("./tmp") |
| 1249 | + # Even though above fails, it shouldn't delete existing file |
| 1250 | + assert (tmp_path / "file.txt").exists() |
0 commit comments