def test_apply_bad_move_fails(self): mock_gamestate = create_autospec(GameState) mock_gamestate.player_hands = [['card0', 'card1', 'card2'], ['card3', 'card4', 'card5', 'card6']] move = Move(move_type='discard', player_index=0, card_index=-1) with pytest.raises(AssertionError) as excinfo: move.apply(mock_gamestate) assert str( excinfo.value ) == 'Cannot apply move discard card index -1 in their hand, not playable.'
def test_apply_give_information_number_multiple_cards(self): """Give information (number) should: call make_public('number') on all cards with that number in a hand call board.use_clock_token() """ mock_gamestate = create_autospec(GameState) mock_gamestate.board = create_autospec(Board) mock_gamestate.board.clock_tokens = 1 mock_card = create_autospec(Card) mock_card.number = 2 mock_card_other_number = create_autospec(Card) mock_card_other_number.number = 4 mock_gamestate.player_hands = [[ mock_card_other_number, mock_card, mock_card_other_number ], [mock_card, mock_card_other_number, mock_card]] info_dict = { 'player_id': 1, 'information_type': 'number', 'information': 2 } move = Move(move_type='give_information', player_index=0, information=info_dict) mock_gamestate = move.apply(game_state=mock_gamestate) mock_card.make_public.assert_called_with('number') assert mock_card.make_public.call_count == 2 mock_gamestate.board.use_clock_token.assert_called_once()
def test_apply_give_information_color_once(self): """Give information (color) should: call make_public('color') on all cards with that color in a hand call board.use_clock_token() """ mock_gamestate = create_autospec(GameState) mock_gamestate.board = create_autospec(Board) mock_gamestate.board.clock_tokens = 2 mock_card = create_autospec(Card) mock_card.color = 'blue' mock_card_other_colors = create_autospec(Card) mock_card_other_colors.color = 'red' mock_gamestate.player_hands = [[ mock_card_other_colors, mock_card_other_colors, mock_card, mock_card ], [mock_card, mock_card_other_colors]] info_dict = { 'player_id': 1, 'information_type': 'color', 'information': 'blue' } move = Move(move_type='give_information', player_index=0, information=info_dict) mock_gamestate = move.apply(game_state=mock_gamestate) mock_card.make_public.assert_called_once_with('color') mock_gamestate.board.use_clock_token.assert_called_once()
def test_apply_discard(self): """Discard should remove a card from the player's hand, add it to the discard pile and add back a clock token.""" mock_gamestate = create_autospec(GameState) mock_card = create_autospec(Card) mock_card_for_discard = create_autospec(Card) mock_gamestate.player_hands = [[mock_card], [mock_card, mock_card_for_discard]] mock_gamestate.board = create_autospec(Board) move = Move(move_type='discard', player_index=1, card_index=1) mock_gamestate = move.apply(game_state=mock_gamestate) assert len(mock_gamestate.player_hands[1]) == 1 mock_gamestate.board.discard_card.assert_called_with( mock_card_for_discard) mock_gamestate.board.add_clock_token.assert_called_once()
def test_apply_play_blow_fuse(self): """Play (blow fuse) should discard the card marked for play and call board.use_fuse_token""" mock_gamestate = create_autospec(GameState) mock_gamestate.board = create_autospec(Board) mock_card = create_autospec(Card) mock_card_for_play = create_autospec(Card) mock_card_for_play.color = 'red' mock_gamestate.player_hands = [[mock_card], [mock_card_for_play, mock_card]] mock_stack = create_autospec(CardStack) mock_stack.is_legal_play.return_value = False mock_gamestate.board.get_card_stack.return_value = mock_stack move = Move(move_type='play', player_index=1, card_index=0) mock_gamestate = move.apply(game_state=mock_gamestate) mock_gamestate.board.get_card_stack.assert_called_with('red') assert len(mock_gamestate.player_hands[1]) == 1 mock_gamestate.board.use_fuse_token.assert_called_once() mock_gamestate.board.discard_card.assert_called_with( mock_card_for_play)
def test_apply_play_successful_play_complete_stack(self): """Play (successful) should remove the card from hand, add it to the stack of the right color, call board.add_clock_token """ mock_gamestate = create_autospec(GameState) mock_gamestate.board = create_autospec(Board) mock_card = create_autospec(Card) mock_card_for_play = create_autospec(Card) mock_card_for_play.color = 'green' mock_gamestate.player_hands = [[mock_card], [mock_card_for_play, mock_card]] mock_stack = create_autospec(CardStack) mock_stack.is_legal_play.return_value = True mock_stack.is_complete.return_value = True mock_gamestate.board.get_card_stack.return_value = mock_stack move = Move(move_type='play', player_index=1, card_index=0) mock_gamestate = move.apply(game_state=mock_gamestate) mock_gamestate.board.get_card_stack.assert_called_with('green') mock_stack.play.assert_called_with(mock_card_for_play) assert len(mock_gamestate.player_hands[1]) == 1 mock_gamestate.board.add_clock_token.assert_called_once()