Example #1
0
    async def test_send_close_negative(self):
        """Test send close message with invalid reference and message id and target."""
        incorrect_msg = GymMessage(
            performative=GymMessage.Performative.CLOSE,
            dialogue_reference=self.dialogues.
            new_self_initiated_dialogue_reference(),
        )
        incorrect_msg.to = self.gym_address
        incorrect_msg.sender = self.agent_address

        # the incorrect message cannot be sent into a dialogue, so this is omitted.

        envelope = Envelope(
            to=incorrect_msg.to,
            sender=incorrect_msg.sender,
            protocol_specification_id=incorrect_msg.protocol_specification_id,
            message=incorrect_msg,
        )
        await self.gym_con.connect()

        with patch.object(self.gym_con.channel.logger,
                          "warning") as mock_logger:
            await self.gym_con.send(envelope)
            mock_logger.assert_any_call(
                f"Could not create dialogue from message={incorrect_msg}")
Example #2
0
def test_act_serialization():
    """Test the serialization for 'act' speech-act works."""
    msg = GymMessage(
        message_id=1,
        dialogue_reference=(str(0), ""),
        target=0,
        performative=GymMessage.Performative.ACT,
        action=GymMessage.AnyObject("some_action"),
        step_id=1,
    )
    msg.to = "receiver"
    envelope = Envelope(
        to=msg.to,
        sender="sender",
        message=msg,
    )
    envelope_bytes = envelope.encode()

    actual_envelope = Envelope.decode(envelope_bytes)
    expected_envelope = envelope
    assert expected_envelope.to == actual_envelope.to
    assert expected_envelope.sender == actual_envelope.sender
    assert (expected_envelope.protocol_specification_id ==
            actual_envelope.protocol_specification_id)
    assert expected_envelope.message != actual_envelope.message

    actual_msg = GymMessage.serializer.decode(actual_envelope.message)
    actual_msg.to = actual_envelope.to
    actual_msg.sender = actual_envelope.sender
    expected_msg = msg
    assert expected_msg == actual_msg
Example #3
0
def test_percept_serialization():
    """Test the serialization for 'percept' speech-act works."""
    msg = GymMessage(
        message_id=2,
        dialogue_reference=(str(0), ""),
        target=1,
        performative=GymMessage.Performative.PERCEPT,
        step_id=1,
        observation=GymMessage.AnyObject("some_observation"),
        reward=10.0,
        done=False,
        info=GymMessage.AnyObject("some_info"),
    )
    msg.to = "receiver"
    envelope = Envelope(
        to=msg.to,
        sender="sender",
        message=msg,
    )
    envelope_bytes = envelope.encode()

    actual_envelope = Envelope.decode(envelope_bytes)
    expected_envelope = envelope
    assert expected_envelope.to == actual_envelope.to
    assert expected_envelope.sender == actual_envelope.sender
    assert (expected_envelope.protocol_specification_id ==
            actual_envelope.protocol_specification_id)
    assert expected_envelope.message != actual_envelope.message

    actual_msg = GymMessage.serializer.decode(actual_envelope.message)
    actual_msg.to = actual_envelope.to
    actual_msg.sender = actual_envelope.sender
    expected_msg = msg
    assert expected_msg == actual_msg
Example #4
0
def test_status_serialization():
    """Test the serialization for 'status' speech-act works."""
    content_arg = {
        "key_1": "value_1",
        "key_2": "value_2",
    }
    msg = GymMessage(
        message_id=1,
        dialogue_reference=(str(0), ""),
        target=0,
        performative=GymMessage.Performative.STATUS,
        content=content_arg,
    )
    msg.to = "receiver"
    envelope = Envelope(
        to=msg.to,
        sender="sender",
        message=msg,
    )
    envelope_bytes = envelope.encode()

    actual_envelope = Envelope.decode(envelope_bytes)
    expected_envelope = envelope
    assert expected_envelope.to == actual_envelope.to
    assert expected_envelope.sender == actual_envelope.sender
    assert (expected_envelope.protocol_specification_id ==
            actual_envelope.protocol_specification_id)
    assert expected_envelope.message != actual_envelope.message

    actual_msg = GymMessage.serializer.decode(actual_envelope.message)
    actual_msg.to = actual_envelope.to
    actual_msg.sender = actual_envelope.sender
    expected_msg = msg
    assert expected_msg == actual_msg