From 0de48eded9962fa50612061db5afc440d261db74 Mon Sep 17 00:00:00 2001 From: asim Date: Sun, 16 Feb 2025 09:37:51 +0530 Subject: [PATCH 1/3] add other open modes in group creation test Signed-off-by: asim --- tests/test_api.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/test_api.py b/tests/test_api.py index aacd558f2..f04b81664 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -51,11 +51,11 @@ def test_create(memory_store: Store) -> None: # create array with float shape with pytest.raises(TypeError): - z = create(shape=(400.5, 100), store=store, overwrite=True) # type: ignore [arg-type] + z = create(shape=(400.5, 100), store=store, overwrite=True) # create array with float chunk shape with pytest.raises(TypeError): - z = create(shape=(400, 100), chunks=(16, 16.5), store=store, overwrite=True) # type: ignore [arg-type] + z = create(shape=(400, 100), chunks=(16, 16.5), store=store, overwrite=True) # TODO: parametrize over everything this function takes @@ -200,7 +200,7 @@ def test_save(store: Store, n_args: int, n_kwargs: int) -> None: assert isinstance(array, Array) assert_array_equal(array[:], data) else: - save(store, *args, **kwargs) # type: ignore[arg-type] + save(store, *args, **kwargs) group = open(store) assert isinstance(group, Group) for array in group.array_values(): @@ -1086,10 +1086,16 @@ async def test_open_falls_back_to_open_group_async() -> None: assert group.attrs == {"key": "value"} -def test_open_mode_write_creates_group(tmp_path: pathlib.Path) -> None: +@pytest.mark.parametrize("mode", ["r", "r+", "w", "a"]) +def test_open_modes_creates_group(tmp_path: pathlib.Path, mode: str) -> None: # https://github.com/zarr-developers/zarr-python/issues/2490 - zarr_dir = tmp_path / "test.zarr" - group = zarr.open(zarr_dir, mode="w") + zarr_dir = tmp_path / f"mode-{mode}-test.zarr" + if mode in ["r", "r+"]: + # Expect FileNotFoundError to be raised if 'r' or 'r+' mode + with pytest.raises(FileNotFoundError): + zarr.open(store=zarr_dir, mode=mode) + zarr.open(store=zarr_dir, mode="w") + group = zarr.open(store=zarr_dir, mode=mode) assert isinstance(group, Group) @@ -1098,13 +1104,13 @@ async def test_metadata_validation_error() -> None: MetadataValidationError, match="Invalid value for 'zarr_format'. Expected '2, 3, or None'. Got '3.0'.", ): - await zarr.api.asynchronous.open_group(zarr_format="3.0") # type: ignore[arg-type] + await zarr.api.asynchronous.open_group(zarr_format="3.0") with pytest.raises( MetadataValidationError, match="Invalid value for 'zarr_format'. Expected '2, 3, or None'. Got '3.0'.", ): - await zarr.api.asynchronous.open_array(shape=(1,), zarr_format="3.0") # type: ignore[arg-type] + await zarr.api.asynchronous.open_array(shape=(1,), zarr_format="3.0") @pytest.mark.parametrize( From 4e54b239ccff18871e2f3d6bd256feea93a66ccb Mon Sep 17 00:00:00 2001 From: asim Date: Sun, 16 Feb 2025 10:17:57 +0530 Subject: [PATCH 2/3] minor fix Signed-off-by: asim --- tests/test_api.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_api.py b/tests/test_api.py index f04b81664..c5ab6f3fc 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -51,11 +51,11 @@ def test_create(memory_store: Store) -> None: # create array with float shape with pytest.raises(TypeError): - z = create(shape=(400.5, 100), store=store, overwrite=True) + z = create(shape=(400.5, 100), store=store, overwrite=True) # type: ignore [arg-type] # create array with float chunk shape with pytest.raises(TypeError): - z = create(shape=(400, 100), chunks=(16, 16.5), store=store, overwrite=True) + z = create(shape=(400, 100), chunks=(16, 16.5), store=store, overwrite=True) # type: ignore [arg-type] # TODO: parametrize over everything this function takes @@ -200,7 +200,7 @@ def test_save(store: Store, n_args: int, n_kwargs: int) -> None: assert isinstance(array, Array) assert_array_equal(array[:], data) else: - save(store, *args, **kwargs) + save(store, *args, **kwargs) # type: ignore [arg-type] group = open(store) assert isinstance(group, Group) for array in group.array_values(): @@ -1104,13 +1104,13 @@ async def test_metadata_validation_error() -> None: MetadataValidationError, match="Invalid value for 'zarr_format'. Expected '2, 3, or None'. Got '3.0'.", ): - await zarr.api.asynchronous.open_group(zarr_format="3.0") + await zarr.api.asynchronous.open_group(zarr_format="3.0") # type: ignore [arg-type] with pytest.raises( MetadataValidationError, match="Invalid value for 'zarr_format'. Expected '2, 3, or None'. Got '3.0'.", ): - await zarr.api.asynchronous.open_array(shape=(1,), zarr_format="3.0") + await zarr.api.asynchronous.open_array(shape=(1,), zarr_format="3.0") # type: ignore [arg-type] @pytest.mark.parametrize( From 9325ba6d441abfcad7ea31e9d00bfd188e471e6c Mon Sep 17 00:00:00 2001 From: Asim <95623198+asimchoudhary@users.noreply.github.com> Date: Mon, 24 Feb 2025 19:39:07 +0530 Subject: [PATCH 3/3] Update tests/test_api.py Add else block for write operations only Co-authored-by: Davis Bennett --- tests/test_api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_api.py b/tests/test_api.py index c5ab6f3fc..5b78eecc7 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -1094,9 +1094,9 @@ def test_open_modes_creates_group(tmp_path: pathlib.Path, mode: str) -> None: # Expect FileNotFoundError to be raised if 'r' or 'r+' mode with pytest.raises(FileNotFoundError): zarr.open(store=zarr_dir, mode=mode) - zarr.open(store=zarr_dir, mode="w") - group = zarr.open(store=zarr_dir, mode=mode) - assert isinstance(group, Group) + else: + group = zarr.open(store=zarr_dir, mode=mode) + assert isinstance(group, Group) async def test_metadata_validation_error() -> None: