Ejemplo n.º 1
0
def test_protocol_creation() -> None:
    """Test protocol creation."""

    # This should fail because _TMessage1 can return _TResponse1 which
    # is not given an id here.
    with pytest.raises(ValueError):
        _protocol = MessageProtocol(message_types={0: _TMessage1},
                                    response_types={0: _TResponse2})

    # Now it should work.
    _protocol = MessageProtocol(message_types={0: _TMessage1},
                                response_types={0: _TResponse1})
Ejemplo n.º 2
0
        self._receiver = receiver

    def handle_raw_message(self, message: bytes) -> bytes:
        """Handle a raw incoming message."""
        return self._receiver.handle_raw_message(self._obj, message)


# RCV_CODE_TEST_END

TEST_PROTOCOL = MessageProtocol(
    message_types={
        0: _TMessage1,
        1: _TMessage2,
        2: _TMessage3,
    },
    response_types={
        0: _TResponse1,
        1: _TResponse2,
    },
    trusted_sender=True,
    log_remote_exceptions=False,
)


def test_protocol_creation() -> None:
    """Test protocol creation."""

    # This should fail because _TMessage1 can return _TResponse1 which
    # is not given an id here.
    with pytest.raises(ValueError):
        _protocol = MessageProtocol(message_types={0: _TMessage1},
Ejemplo n.º 3
0
                                 message: str,
                                 raise_unregistered: bool = False) -> str:
        """Asynchronously handle a raw incoming message."""
        return await self._receiver.handle_raw_message_async(
            self._obj, message, raise_unregistered)


# RCV_ASYNC_CODE_TEST_END

TEST_PROTOCOL = MessageProtocol(
    message_types={
        0: _TMsg1,
        1: _TMsg2,
        2: _TMsg3,
    },
    response_types={
        0: _TResp1,
        1: _TResp2,
    },
    trusted_sender=True,
    log_remote_exceptions=False,
)

# Represents an 'evolved' TEST_PROTOCOL (one extra message type added).
# (so we can test communication failures talking to older protocols)
TEST_PROTOCOL_B = MessageProtocol(
    message_types={
        0: _TMsg1,
        1: _TMsg2,
        2: _TMsg3,
        3: _TMsg4,