Exemple #1
0
def test_call_pelita():
    rounds = 200
    viewer = 'ascii'
    size = 'small'

    teams = ["pelita/player/StoppingPlayer", "pelita/player/StoppingPlayer"]
    (state, stdout, stderr) = call_pelita(teams,
                                          rounds=rounds,
                                          viewer='null',
                                          size=size,
                                          seed=None)
    assert state['gameover'] is True
    assert state['whowins'] == 2
    # Quick assert that there is text in stdout
    assert len(stdout.split('\n')) > 0
    assert "Finished" in stdout

    teams = ["pelita/player/SmartEatingPlayer", "pelita/player/StoppingPlayer"]
    (state, stdout, stderr) = call_pelita(teams,
                                          rounds=rounds,
                                          viewer=viewer,
                                          size=size,
                                          seed=None)
    assert state['gameover'] is True
    assert state['whowins'] == 0

    teams = ["pelita/player/StoppingPlayer", "pelita/player/SmartEatingPlayer"]
    (state, stdout, stderr) = call_pelita(teams,
                                          rounds=rounds,
                                          viewer=viewer,
                                          size=size,
                                          seed=None)
    assert state['gameover'] is True
    assert state['whowins'] == 1
Exemple #2
0
def test_bad_seeds(seed, success):
    rounds = 2
    viewer = 'null'
    size = 'small'

    teams = ["pelita/player/StoppingPlayer", "pelita/player/StoppingPlayer"]
    if success:
        (state, stdout, stderr) = call_pelita(teams, rounds=rounds, viewer='null', size=size, seed=seed)
        assert state['gameover'] is True
    else:
        with pytest.raises(ValueError):
                call_pelita(teams, rounds=rounds, viewer='null', size=size, seed=seed)
Exemple #3
0
    def run_game(self, p1, p2):
        """Run a single game.

        This method runs a single game ``p1`` vs ``p2`` and internally
        stores the result.

        Parameters
        ----------
        p1, p2 : int
            the indices of the players

        """
        team_specs = [self.players[i]['path'] for i in (p1, p2)]

        final_state, stdout, stderr = call_pelita(team_specs,
                                                            rounds=self.rounds,
                                                            size=self.size,
                                                            viewer=self.viewer,
                                                            seed=self.seed)

        if final_state['whowins'] == 2:
            result = -1
        else:
            result = final_state['whowins']

        logger.info('Final state: %r', final_state)
        logger.debug('Stdout: %r', stdout)
        if stderr:
            logger.warning('Stderr: %r', stderr)
        p1_name, p2_name = self.players[p1]['name'], self.players[p2]['name']
        self.dbwrapper.add_gameresult(p1_name, p2_name, result, stdout, stderr)
Exemple #4
0
def test_remote_call_pelita(remote_teams):
    res, stdout, stderr = call_pelita(remote_teams, rounds=30, size='small', viewer='null', seed='1')
    assert res['whowins'] == 1
    assert res['fatal_errors'] == [[], []]
    # errors for call_pelita only contains the last thrown error, hence None
    # TODO: should be aligned so that call_pelita and run_game return the same thing
    assert res['errors'] == [None, None]