Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/test_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,15 @@ def test_other_dtype_roundtrip(fill_value: bytes | None, tmp_path: Path) -> None
assert (a == za[:]).all()


# numcodecs deprecates its Pickle codec and warns whenever one is created
# (zarr-developers/numcodecs#905). These tests create Pickle codecs on purpose to check zarr's
# decode gate, so the warning is expected. numcodecs versions without that deprecation don't
# emit it, so the filter ignores the warning rather than requiring it.
ignore_pickle_deprecation = pytest.mark.filterwarnings(
"ignore:The Pickle codec is deprecated:DeprecationWarning"
)


def _pickle_compressed_array() -> zarr.Array[Any]:
# Writing with the pickle codec is allowed without opting in, only decoding is gated.
arr = zarr.create_array(
Expand All @@ -351,6 +360,7 @@ def allow_numcodecs_unpickle(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(numcodecs.pickles, "ALLOW_UNSAFE_PICKLE_DECODE", True)


@ignore_pickle_deprecation
def test_pickle_codec_read_disabled_by_default() -> None:
"""Reading data encoded with the pickle codec fails unless the user opts in."""
arr = _pickle_compressed_array()
Expand All @@ -362,6 +372,7 @@ def test_pickle_codec_read_disabled_by_default() -> None:
assert "ALLOW_UNSAFE_PICKLE_DECODE" in str(excinfo.value)


@ignore_pickle_deprecation
def test_pickle_codec_read_does_not_unpickle() -> None:
"""A malicious chunk is not unpickled when the pickle codec is disabled."""

Expand Down Expand Up @@ -389,6 +400,7 @@ def __reduce__(self) -> tuple[Any, ...]:
arr[:]


@ignore_pickle_deprecation
def test_pickle_codec_zarr_opt_in_does_not_bypass_numcodecs(
monkeypatch: pytest.MonkeyPatch,
) -> None:
Expand All @@ -402,13 +414,15 @@ def test_pickle_codec_zarr_opt_in_does_not_bypass_numcodecs(
arr[:]


@ignore_pickle_deprecation
@pytest.mark.usefixtures("allow_numcodecs_unpickle")
def test_pickle_codec_read_enabled_via_config() -> None:
arr = _pickle_compressed_array()
with config.set({"array.allow_unsafe_pickle_decode": True}):
np.testing.assert_array_equal(arr[:], np.array(["a", "bb", "ccc"]))


@ignore_pickle_deprecation
@pytest.mark.usefixtures("allow_numcodecs_unpickle")
@pytest.mark.parametrize(("env_value", "allowed"), [("True", True), ("false", False)])
def test_pickle_codec_read_enabled_via_env_var(
Expand Down
Loading