Coverage for Users/vladimirpavlov/PycharmProjects/parameterizable/tests/test_not_picklable.py: 100%

1 import pickle

2

3 from mixinforge import NotPicklableMixin

4

5 import pytest

6

7 def test_not_picklable():

8 npo = NotPicklableMixin()

9

10 # Test dunder methods directly

11 with pytest.raises(TypeError):

12 npo.__reduce__()

13 with pytest.raises(TypeError):

14 _ = npo.__getstate__()

15 with pytest.raises(TypeError):

16 npo.__setstate__({"key": "value"})

17

18 # Test pickling via pickle.dumps(), which calls __reduce__()

19 with pytest.raises(TypeError):

20 pickle.dumps(npo)

21

22 # Test that a subclass is also not picklable

23 class MyNotPicklableMixin(NotPicklableMixin):

24 pass

25 mnpo = MyNotPicklableMixin()

26 with pytest.raises(TypeError):

27 pickle.dumps(mnpo)