Beispiel #1
0
def test_eliminate_discardsCards(player: RoundPlayer):
    game_round = player.round
    card = player.hand.card
    player.eliminate()
    assert game_round.discard_pile.top == card
    assert player.discarded_cards[-1] == card
    assert len(player.hand) == 0
Beispiel #2
0
def test_playCard_right_playsRightCard(dummy_player: RoundPlayer, left, right):
    dummy_player.give(left)
    dummy_player.give(right)
    autofill_move(dummy_player.play_card(right))
    right.play.assert_called_once_with(dummy_player)
    left.play.assert_not_called()
    assert dummy_player.hand.card is left
    assert right not in dummy_player.hand
    dummy_player.round.discard_pile.place.assert_called_once_with(right)
    assert dummy_player.discarded_cards[-1] == right
Beispiel #3
0
def test_newPlayer_validRound_initsCorrectly(game_round, id: int):
    player = RoundPlayer(game_round, id)
    assert player.round is game_round
    assert player.alive
    assert player.hand.card is None
    assert len(player.discarded_cards) == 0
    assert player.id == id
Beispiel #4
0
    def __init__(self, num_players: int, deck: Deck = None):
        """
        Initialise a new round.

        :param num_players: Number of players in the round.
        :param deck: Initial deck to start with. None means use the standard deck.
        """
        players = [RoundPlayer(self, i) for i in range(num_players)]
        super().__init__(players)

        self.deck = deck if deck is not None else Deck.from_counts()
        self.discard_pile = DiscardPile([])
Beispiel #5
0
def play_with_choices(player: RoundPlayer,
                      card_type: CardType,
                      *choices,
                      advance_turn=True):
    move_ = player.play_type(card_type)
    step = None
    for choice in choices:
        step = move_.send(step)
        step.choice = choice
    result = send_gracious(move_, step)
    if advance_turn:
        player.round.advance_turn()
    return result
Beispiel #6
0
def play_card(player: RoundPlayer,
              card: cards.Card,
              autofill=None,
              skip_if_disallowed=True):
    from test_loveletter.unit.test_cards_cases import DISCARD_TYPES

    if autofill is None:
        autofill = CardType(card) in DISCARD_TYPES
    if (skip_if_disallowed and not isinstance(card, Mock)
            and CardType.COUNTESS in map(CardType, player.hand)
            and CardType(card) in {CardType.PRINCE, CardType.KING}):
        pytest.skip(f"Playing {card} with Countess in hand will raise")

    give_card(player, card)
    move_ = player.play_card(card)
    if autofill:
        return autofill_move(move_, close=True)
    else:
        return move_
Beispiel #7
0
def give_card(player: RoundPlayer, card: Card, replace=False):
    if replace:
        player.hand._cards.clear()
    elif len(player.hand) == 2:
        player.hand._cards.pop()
    player.give(card)
Beispiel #8
0
def test_give_playerWithTwoCards_oneCard_raises(dummy_player: RoundPlayer):
    card = dummy_player.hand.card
    with pytest.raises(valid8.ValidationError):
        dummy_player.give(card)
Beispiel #9
0
def test_give_playerWithOneCard_oneCard_works(dummy_player: RoundPlayer):
    card = dummy_player.hand.card
    before = dummy_player.hand.card
    dummy_player.give(card)
    assert list(dummy_player.hand) == [before, card]
Beispiel #10
0
def test_eliminate_deadPlayer_raises(player: RoundPlayer):
    player.eliminate()
    with pytest.raises(valid8.ValidationError):
        player.eliminate()
Beispiel #11
0
def test_playType_notPresent_raises(player: RoundPlayer):
    give_card(player, cards.Guard())
    give_card(player, cards.Princess())
    with pytest.raises(valid8.ValidationError):
        send_gracious(player.play_type(CardType.PRINCE), None)