Skip to content

Commit

Permalink
Add Message pickle serialization test (#904)
Browse files Browse the repository at this point in the history
Add a test that exercises pickling/unpickling of a Message.

Addresses #804
  • Loading branch information
karlding committed Aug 28, 2020
1 parent 738a5d7 commit 5ba2a93
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/test_message_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
import sys
from math import isinf, isnan
from copy import copy, deepcopy
import pickle

from hypothesis import given, settings, reproduce_failure
import hypothesis.strategies as st

from can import Message

from .message_helper import ComparingMessagesTestCase


class TestMessageClass(unittest.TestCase):
"""
Expand Down Expand Up @@ -85,5 +88,31 @@ def test_methods(self, **kwargs):
self.assertTrue(message.equals(other, timestamp_delta=0))


class MessageSerialization(unittest.TestCase, ComparingMessagesTestCase):
def __init__(self, *args, **kwargs):
unittest.TestCase.__init__(self, *args, **kwargs)
ComparingMessagesTestCase.__init__(
self, allowed_timestamp_delta=0.016, preserves_channel=True
)

def test_serialization(self):
message = Message(
timestamp=1.0,
arbitration_id=0x401,
is_extended_id=False,
is_remote_frame=False,
is_error_frame=False,
channel=1,
dlc=6,
data=bytearray([0x01, 0x02, 0x03, 0x04, 0x05, 0x06]),
is_fd=False,
)

serialized = pickle.dumps(message, -1)
deserialized = pickle.loads(serialized)

self.assertMessageEqual(message, deserialized)


if __name__ == "__main__":
unittest.main()

0 comments on commit 5ba2a93

Please sign in to comment.