Exemple #1
0
 def test_invalid_json_placement(self):
     # Tests that receiving invalid JSON results in a None placement
     rpp = RemotePlayerProxy('name', 1.0, self.dummy_socket)
     rpp._RemotePlayerProxy__socket = self.mock_socket
     self.mock_socket.recv.return_value = b'['
     state = State(self.__b, players=[self.__p1, self.__p2, self.__p3])
     pos = rpp.get_placement(state)
     self.assertEqual(pos, None)
Exemple #2
0
    def test_valid_json_invalid_message(self):
        # Tests that valid JSON but invalid message returns JsonDecodeException
        rpp = RemotePlayerProxy('name', 1.0, self.dummy_socket)
        rpp._RemotePlayerProxy__socket = self.mock_socket
        self.mock_socket.recv.return_value = b'["test"]'

        with self.assertRaises(JsonDecodeException):
            state = State(self.__b, players=[self.__p1, self.__p2, self.__p3])
            pos = rpp.get_placement(state)
Exemple #3
0
    def test_get_placement_success(self):
        # Test that RPP can successfully request, receive and decode a position
        # This is done to bypass the constructor type checking
        rpp = RemotePlayerProxy('name', 1.0, self.dummy_socket)
        rpp._RemotePlayerProxy__socket = self.mock_socket
        self.mock_socket.recv.return_value = b'[0, 1]'

        state = State(self.__b, players=[self.__p1, self.__p2, self.__p3])
        json_state = _state_to_json(state)

        expected_client_request = f'["setup", [{json.dumps(json_state)}]]'

        with patch.object(rpp, '_RemotePlayerProxy__send_message') as mock:
            pos = rpp.get_placement(state)
            mock.assert_called_with(expected_client_request)
            self.assertEqual(pos, Position(0, 1))