Пример #1
0
async def test_night(players, run):
    """Test night."""
    with open(MOCK_IRC_FILE, "a") as fd:
        fd.write("\n===== TEST night =====\n")

    with mock.patch("lycanthrope.game.notify_player", new=mock_notify_player):
        with mock.patch("lycanthrope.game.get_choice", new=mock_get_choice):

            # init game
            game = lycanthrope.Game()
            for player in players:
                game.add_player(player)
            game.deal_roles()
            with open(MOCK_IRC_FILE, "a") as fd:
                fd.write("Initial distribution: {}\n".format(
                    str(game.initial_roles)))

            await game.night()
            with open(MOCK_IRC_FILE, "a") as fd:
                fd.write("Finale distribution: {}\n".format(
                    str(game.current_roles)))

            # clean up
            if game.tasks:
                await asyncio.wait(game.tasks)
Пример #2
0
async def test_victory_happy_path(distribution):
    """Test victory computing."""
    with open(MOCK_IRC_FILE, "a") as fd:
        fd.write("\n===== TEST victory =====\n")

    with mock.patch("lycanthrope.game.notify_player", new=mock_notify_player):
        with mock.patch("lycanthrope.game.get_choice", new=mock_get_choice):

            # init game
            game = lycanthrope.Game()
            real_players = [
                player for player in distribution
                if player not in ("0", "1", "2")
            ]

            for player in real_players:
                game.add_player(player)
            game.initial_roles = distribution.copy()
            game.current_roles = distribution.copy()

            for dead, doppel in product(game.players[3:] + [None], repeat=2):
                if dead:
                    game.dead = {dead}
                else:
                    game.dead = set()

                with open(MOCK_IRC_FILE, "a") as fd:
                    fd.write("distribution:{}\n".format(str(
                        game.current_roles)))
                    fd.write("dead:{}\n".format(game.dead))
                    fd.write("victory:{}\n".format(str(await game.victory())))
Пример #3
0
async def test_turns(players, run):
    """Test player turn."""
    with open(MOCK_IRC_FILE, "a") as fd:
        fd.write("\n===== TEST test_turns =====\n")

    with mock.patch("lycanthrope.game.notify_player", new=mock_notify_player):
        with mock.patch("lycanthrope.game.get_choice", new=mock_get_choice):

            # init game
            game = lycanthrope.Game()
            for player in players:
                game.add_player(player)
            game.deal_roles()
            with open(MOCK_IRC_FILE, "a") as fd:
                fd.write("Initial distribution: {}\n".format(
                    str(game.initial_roles)))

            # execute turns
            turn_names = [
                name for name in game.__dir__() if name.endswith("_turn")
            ]
            for turn_name in turn_names:
                with open(MOCK_IRC_FILE, "a") as fd:
                    fd.write("----- TEST {} -----\n".format(turn_name))
                ret = await getattr(game, turn_name)()
                if ret:
                    with open(MOCK_IRC_FILE, "a") as fd:
                        fd.write("- switches: {}\n".format(str(ret)))
                if game.tasks:
                    await asyncio.wait(game.tasks)
Пример #4
0
async def test_game(players, run):
    """Test whole game."""
    with open(MOCK_IRC_FILE, "a") as fd:
        fd.write("\n===== TEST game =====\n")

    with mock.patch("lycanthrope.game.notify_player", new=mock_notify_player):
        with mock.patch("lycanthrope.game.get_choice", new=mock_get_choice):

            # init game
            game = lycanthrope.Game()
            for player in players:
                game.add_player(player)
            game.deal_roles()

            # perform several games
            for _ in range(run):
                await game.game(timeout=1)
Пример #5
0
async def test_assassin(players):
    """Tes assassin."""
    with open(MOCK_IRC_FILE, "a") as fd:
        fd.write("\n===== TEST assassin and dawn =====\n")

    with mock.patch("lycanthrope.game.notify_player", new=mock_notify_player):
        with mock.patch("lycanthrope.game.get_choice", new=mock_get_choice):

            # init game
            game = lycanthrope.Game()
            for player in players:
                game.add_player(player)
            game.deal_roles()
            assa = game.players[-1]
            game.initial_roles[assa] = "assassin"
            game.current_roles = game.initial_roles.copy()
            game.dealt_roles = set(game.current_roles.values())

            await game.dawn()
Пример #6
0
async def test_notify_roles(players):
    """Test initial notification of players.

    Deal roles among players and then notitfy them.

    Args:
        players (string): players
    """
    with open(MOCK_IRC_FILE, "a") as fd:
        fd.write("\n===== TEST test_notify_roles =====\n")

    with mock.patch("lycanthrope.game.notify_player", new=mock_notify_player):
        game = lycanthrope.Game()
        for player in players:
            game.add_player(player)
        game.deal_roles()
        await game.notify_player_roles()
        await game.notify_player_roles(False)
        if game.tasks:
            await asyncio.wait(game.tasks)
Пример #7
0
async def test_votes(players, run):
    """Test votes."""
    with open(MOCK_IRC_FILE, "a") as fd:
        fd.write("\n===== TEST votes =====\n")

    with mock.patch("lycanthrope.game.notify_player", new=mock_notify_player):
        with mock.patch("lycanthrope.game.get_choice", new=mock_get_choice):

            # init game
            game = lycanthrope.Game()
            for player in players:
                game.add_player(player)
            game.deal_roles()

            await game.collect_votes(timeout=run / 10)

            with open(MOCK_IRC_FILE, "a") as fd:
                fd.write("votes: {}\n".format(str(game.votes)))
                fd.write("dead: {}\n".format(game.dead))

            # clean up
            if game.tasks:
                await asyncio.wait(game.tasks)
Пример #8
0
async def game():
    """Return a game."""
    game = lycanthrope.Game()
    yield game
    await game.clean_up()
Пример #9
0
def test_init():
    lycanthrope.Game()