def test_serialize_message(): """ Test basic serialization. """ # Raw serialization test = b'asdf' message = serialize_message(message=test, serializer='raw') assert isinstance(message, bytes) assert test == message # Pickle serialization test = [0, 1] message = serialize_message(message=test, serializer='pickle') assert isinstance(message, bytes) assert test == pickle.loads(message) # Json serialization test = [0, 1] message = serialize_message(message=test, serializer='json') assert isinstance(message, bytes) assert test == json.loads(message.decode('ascii')) # Un-serializable type with pytest.raises(TypeError): serialize_message(message=b'Hello', serializer='json') # Incorrect serializer with pytest.raises(ValueError): serialize_message(message=test, serializer='foo')