def test_wait_for_input(player, ui): ui.set_state = MagicMock() fake_callback = MagicMock() player.wait_for_input( "Test", [Option("Yes", True), Option("No", False)], fake_callback) player.handle("Event") ui.set_state.assert_called_once() fake_callback.assert_called_once_with("Event")
def test_choose_target(player, deck, ui, action_factory): target_obs = MagicMock() player.add_target_observer(target_obs) ui.set_state = MagicMock() filler = Player("Target1", deck, action_factory, ui) filler.draw_cards(1) target = Player("Target2", deck, action_factory, ui) target.draw_cards(1) expected = [Option("Target1", filler), Option("Target2", target)] player.player_list = [filler, player, target] player.choose_target() optionlist = ui.set_state.call_args[0][0] assert expected == optionlist.options player.handle(target) target_obs.receive_target.assert_called_once_with(target)
def choose_target(self): target_list = [] for p in self.player_list: if p is not self and len(p.cards) > 0: target_list.append(Option(p.name, p)) self.wait_for_input( "Choose a target", target_list, self._choose_target )
def _get_valid_actions(self): if self.coins >= 10: return [Option("Depose", "DEPOSE")] actions = [ Option("Salary", "SALARY"), Option("Donations", "DONATIONS"), Option("Tithe", "TITHE"), Option("Mug", "MUG"), Option("Diplomacy", "DIPLOMACY") ] if self.coins >= 3: actions.append(Option("Murder", "MURDER")) if self.coins >= 7: actions.append(Option("Depose", "DEPOSE")) return actions
def test_choose_action(player, ui, action_obs): from depose.actions import Salary test_cases = [(2, [ Option("Salary", "SALARY"), Option("Donations", "DONATIONS"), Option("Tithe", "TITHE"), Option("Mug", "MUG"), Option("Diplomacy", "DIPLOMACY") ]), (6, [ Option("Salary", "SALARY"), Option("Donations", "DONATIONS"), Option("Tithe", "TITHE"), Option("Mug", "MUG"), Option("Diplomacy", "DIPLOMACY"), Option("Murder", "MURDER") ]), (9, [ Option("Salary", "SALARY"), Option("Donations", "DONATIONS"), Option("Tithe", "TITHE"), Option("Mug", "MUG"), Option("Diplomacy", "DIPLOMACY"), Option("Murder", "MURDER"), Option("Depose", "DEPOSE") ]), (11, [Option("Depose", "DEPOSE")])] ui.set_state = MagicMock() for coins, options in test_cases: player.coins = coins player.choose_action() optionlist = ui.set_state.call_args[0][0] assert options == optionlist.options player.handle("SALARY") chosen_action = action_obs.receive_action.call_args[0][0] assert "Salary" == chosen_action.name assert player == chosen_action.actor
def test_cardlist(player): cardlist = player._cardlist() expected = [Option("LORD", Card.LORD), Option("BANDIT", Card.BANDIT)] assert expected == cardlist
def _cardlist(self): cl = [] for card in self.cards: cl.append(Option(card.name, card)) return cl
def ask_to_challenge(self, action): self.wait_for_input( "{}, challenge {}'s {}?".format(self.name, action.actor.name, action.name), [Option("Yes", True), Option("No", False)], self.receive_response )