From d72cc51b9a626091c8cdd8238f352c579d3fca6c Mon Sep 17 00:00:00 2001 From: Nicolas Braud-Santoni Date: Tue, 16 Apr 2019 00:19:23 +0200 Subject: [PATCH] tests/subclass: Add pickling test See #147 --- tests/test_subclass.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_subclass.py b/tests/test_subclass.py index fe35f8f9..f6e2318f 100644 --- a/tests/test_subclass.py +++ b/tests/test_subclass.py @@ -29,6 +29,17 @@ def test_subclass_copy(v: Vector2, label_v: str): assert w.label == label_v +@given(v=vectors(), label_v=st.text()) +def test_ctor_pickle(v: Vector2, label_v: str): + """Round-trip instances of the subclass through `pickle.{dumps,loads}`.""" + import pickle + v = LabeledVector(*v, label_v) # type: ignore + w = pickle.loads(pickle.dumps(v)) + + assert v == w + assert isinstance(w, LabeledVector) + + @pytest.mark.parametrize("op", BINARY_OPS) @given(v=vectors(), label_v=st.text(), w=units(), label_w=st.text()) def test_subclass_binops_both(op, v: Vector2, label_v: str, w: Vector2, label_w: str):