def test_shift_raises_error_on_invalid_player_id(): """ Tests shift validation """ game = Game(identifier=0) player_id = game.unused_player_id() game.add_player(Player(player_id)) game.start_game() with pytest.raises(PlayerNotFoundException): game.shift(player_id + 1, BoardLocation(0, 1), 90)
def test_move_raises_error_on_invalid_player_id(): """ Tests move validation """ game = Game(identifier=0) player_id = game.unused_player_id() game.add_player(Player(player_id)) game.start_game() with pytest.raises(PlayerNotFoundException): game.move(player_id - 1, BoardLocation(5, 5))
def test_add_player_start_game_calls_methods_on_turns(): """ Tests add_player, start_game and Player """ board = Board() turns = Mock() game = Game(identifier=0, board=board, turns=turns) for _ in range(4): player_id = game.unused_player_id() game.add_player(Player(player_id)) game.start_game() expected_turn_calls = [call.init(game.players)] + [call.start()] assert turns.mock_calls[-2:] == expected_turn_calls
def test_move_does_not_raise_error_after_shift(): """ Tests turn validation """ board = Mock() turns = Mock() turns.is_action_possible.return_value = True game = Game(identifier=0, board=board, turns=turns) player_id = game.unused_player_id() game.add_player(Player(player_id)) game.start_game() player = game.get_player(player_id) game.move(player_id, BoardLocation(0, 0)) board.move.assert_called_once() turns.is_action_possible.assert_called_once_with(player, PlayerAction.MOVE_ACTION)
def test_add_player_start_game_calls_methods_on_board(): """ Tests add_player, start_game and Player """ board = Board() turns = Mock() game = Game(identifier=0, board=board, turns=turns) with patch.object(board, 'create_piece', wraps=board.create_piece) as board_create_piece: for _ in range(4): player_id = game.unused_player_id() game.add_player(Player(player_id)) game.start_game() expected_board_calls = [ call.create_piece(), call.create_piece(), call.create_piece(), call.create_piece() ] assert board_create_piece.mock_calls == expected_board_calls