Beispiel #1
0
def main():
    players = PlayersDB()

    print_current_standings(players)

    print('Please enter the names of the players in the game, one at a time.')
    print('Please press <Enter> on a blank line when finished.')

    # Records names of people playing.
    while True:
        name = read_line('Player {0}: '.format(len(players) + 1))
        if is_empty(name):
            break
        players.add_player(name)

    ConsoleCompleter(players.get_players())

    # Prints initial wins then prompts for the winner of each game.
    while True:

        # Prints current wins for each player.
        print_current_standings(players)

        # Adds one to the winner's score.
        winner = read_line('Please enter the name of the player that won: ')
        if is_empty(winner):
            break
        players.add_wins(winner)
 def test_eof(self):
     # Populate stdin with an empty string. This will cause an
     # EOF. In the interest of simplicity, just return this as an
     # empty string. These are the same:
     #
     #     sys.stdin = StringIO()
     #     sys.stdin = StringIO('')
     #
     populate_stdin('')
     self.assertEqual(read_line('my prompt'), '')
     self.assert_stdout_equal('my prompt')
 def test_empty_line(self):
     populate_stdin('\n')
     self.assertEqual(read_line('fake prompt'), '')
     self.assert_stdout_equal('fake prompt')
 def test_normal_usage(self):
     populate_stdin('awesome\n')
     self.assertEqual(read_line('fake prompt'), 'awesome')
     self.assert_stdout_equal('fake prompt')