Skip to content

Commit

Permalink
tests: add reduce test
Browse files Browse the repository at this point in the history
  • Loading branch information
corenting committed Dec 16, 2023
1 parent ea2c428 commit 59ab1e2
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion tests/test_immutabledict.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pickle
from io import BytesIO
from typing import Any, Dict, Union

import pytest
Expand Down Expand Up @@ -213,7 +215,7 @@ def test_performance(self, statement: str) -> None:
setup="s=0; d = immutabledict({i:i for i in range(1000000)})",
)

assert time_immutable < 1.2 * time_standard
assert time_immutable < 1.4 * time_standard

def test_set_delete_update(self) -> None:
d: immutabledict[str, int] = immutabledict(a=1, b=2)
Expand All @@ -237,6 +239,23 @@ def test_new_kwargs(self) -> None:
immutable_dict: immutabledict[str, int] = immutabledict(a=1, b=2)
assert immutable_dict == {"a": 1, "b": 2} == dict(a=1, b=2)

def test_reduce(self):
my_dict: immutabledict[str, int] = immutabledict(a=1, b=2)
reduce_cls, reduce_args = my_dict.__reduce__()

assert reduce_cls == immutabledict
assert reduce_args == (my_dict._dict,)

def test_pickle(self) -> None:
my_dict: immutabledict[str, int] = immutabledict(a=1, b=2)
bytes_io = BytesIO()
pickle.dump(my_dict, bytes_io)
bytes_io.seek(0)

from_pickle_dict = pickle.loads(bytes_io.getvalue()) # noqa: S301

assert my_dict == from_pickle_dict


class TestImmutableOrderedDict:
def test_ordered(self) -> None:
Expand Down

0 comments on commit 59ab1e2

Please sign in to comment.