Skip to content

Commit

Permalink
test: always disable custom pickler in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
agoose77 committed Dec 4, 2023
1 parent 8f7208c commit bd3d668
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
12 changes: 12 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from __future__ import annotations

import pytest

from awkward._pickle import use_builtin_reducer


@pytest.fixture(autouse=True)
def disable_external_pickler():
"""Fixture to disable external pickler implementation for every test"""
with use_builtin_reducer():
yield
20 changes: 6 additions & 14 deletions tests/test_2757_attrs_metadata.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE
from __future__ import annotations

import pickle

import packaging.version
import pytest

import awkward as ak
from awkward._pickle import use_builtin_reducer


@pytest.fixture
def array_pickler():
import pickle

with use_builtin_reducer():
yield pickle


SOME_ATTRS = {"foo": "!SOME"}
OTHER_ATTRS = {"bar": "!OTHER", "foo": "!OTHER"}
Expand All @@ -31,18 +23,18 @@ def test_set_attrs():
array.attrs = "Hello world!"


def test_serialise_with_transient_attrs(array_pickler):
def test_serialise_with_transient_attrs():
attrs = {**SOME_ATTRS, "@transient_key": lambda: None}
array = ak.Array([1, 2, 3], attrs=attrs)
result = array_pickler.loads(array_pickler.dumps(array))
result = pickle.loads(pickle.dumps(array))
assert result.attrs == SOME_ATTRS


def test_serialise_with_nonserialisable_attrs(array_pickler):
def test_serialise_with_nonserialisable_attrs():
attrs = {**SOME_ATTRS, "non_transient_key": lambda: None}
array = ak.Array([1, 2, 3], attrs=attrs)
with pytest.raises(AttributeError, match=r"Can't pickle local object"):
array_pickler.loads(array_pickler.dumps(array))
pickle.loads(pickle.dumps(array))


def test_transient_metadata_persists():
Expand Down

0 comments on commit bd3d668

Please sign in to comment.