示例#1
0
    def test_play_game_4_rounds_2_player(self, mock_print, mock_player, mock_round):
        mock_input.side_effect = ["2", "test1", "test2"]
        player1 = TestData.Player("player1")
        player2 = TestData.Player("player2")
        self.game.players = [player1, player2]
        self.game.rounds = 4

        self.game.play_game()

        mock_input.assert_any_call(
            "Welcome to Yathzee!! \n With how many people will you play this game?"
        )
        mock_input.assert_any_call("What is the name of player 1?")
        self.assertEqual(player1.name, self.game.players[0].name)
        mock_player.assert_any_call("test1")
        mock_player.assert_any_call("test2")
        mock_print.assert_any_call(
            f"{player1.name} has a score of {player1.scoreblock.total_score()}"
        )
        mock_print.assert_any_call(
            f"{player2.name} has a score of {player2.scoreblock.total_score()}"
        )
        self.assertEqual(4, mock_round.call_count)
示例#2
0
    def test_play_game_wrong_input(self, mock_print, mock_player, mock_round):
        mock_input.side_effect = ["test", "1", "test1"]
        player1 = TestData.Player("player1")
        self.game.players = [player1]
        self.game.rounds = 0

        self.game.play_game()

        mock_input.assert_any_call(
            "Welcome to Yathzee!! \n With how many people will you play this game?"
        )
        mock_input.assert_any_call("What is the name of player 1?")
        self.assertEqual(player1.name, self.game.players[0].name)
        mock_player.assert_any_call("test1")
        mock_print.assert_called_with(
            f"{player1.name} has a score of {player1.scoreblock.total_score()}"
        )
        self.assertEqual(0, mock_round.call_count)
        mock_print.assert_any_call("please enter a digit")