Coverage for Users/vladimirpavlov/PycharmProjects/parameterizable/tests/test_json_processor_slots_tuple_variants.py: 84%

1 import json

2

3 from mixinforge.json_processor import _from_serializable_dict, _to_serializable_dict, _Markers

4

5

6 class Duo:

7 __slots__ = ("x", "y")

8

9 def __init__(self, x=0, y=0):

10 self.x = x

11 self.y = y

12

13

14 class DuoDict:

15 __slots__ = ("__dict__", "x", "y")

16

17 def __init__(self, x=0, y=0):

18 self.x = x

19 self.y = y

20

21

22 def test_tuple_state_with_slot_values_and_none():

23 state_tuple = ([11, 22], None)

24 payload = {

25 _Markers.MODULE: __name__,

26 _Markers.CLASS: "Duo",

27 _Markers.STATE: _to_serializable_dict(state_tuple),

28 }

29 back = _from_serializable_dict(payload)

30 assert isinstance(back, Duo)

31 assert back.x == 11 and back.y == 22

32

33

34 def test_tuple_state_with_slot_values_and_dict_values():

35 state_tuple = ([9, 8], {"z": 5})

36 payload = {

37 _Markers.MODULE: __name__,

38 _Markers.CLASS: "DuoDict",

39 _Markers.STATE: _to_serializable_dict(state_tuple),

40 }

41 back = _from_serializable_dict(payload)

42 assert isinstance(back, DuoDict)

43 assert back.x == 9 and back.y == 8

44 assert getattr(back, "z") == 5