예제 #1
0
 def test_config_with_duplicate_char(self, capsys):
     """Tests for duplicate player character."""
     config = GameConfig(
         'tictactoe/tests/configs/config_with_duplicate_char.json')
     players = [config['players'][player] for player in config['players']]
     with pytest.raises(SystemExit):
         config.validate_player_chars(players)
     captured = capsys.readouterr()
     assert "Characters need to be unique between players." in captured.out
예제 #2
0
 def test_config_with_invalid_ai(self, capsys):
     """Tests config for invalid AI setting."""
     config = GameConfig(
         'tictactoe/tests/configs/config_with_invalid_ai.json')
     players = [config['players'][player] for player in config['players']]
     with pytest.raises(SystemExit):
         config.validate_ai_settings(players)
     captured = capsys.readouterr()
     assert "If present, player AI setting needs to be either true or false." in captured.out
예제 #3
0
 def test_config_with_invalid_char(self, capsys):
     """Tests for invalid or empty player character."""
     config = GameConfig(
         'tictactoe/tests/configs/config_with_invalid_char.json')
     players = [config['players'][player] for player in config['players']]
     with pytest.raises(SystemExit):
         config.validate_player_chars(players)
     captured = capsys.readouterr()
     assert "A player character needs to be a single character." in captured.out
예제 #4
0
def main(args=None):
    """Main program routine."""
    print(
        "=======================\nTic-Tac-Toe: Remastered\n======================="
    )

    config = GameConfig('config.json')
    # Note that config.json is exptected to be found in project root.

    if config.is_valid():
        # Intialize Game instance when we are sure the config is valid.
        game = Game(config)
        game.run()
예제 #5
0
 def test_config_which_doesnt_exist(self, capsys):
     """Tests for non existing config paths"""
     with pytest.raises(SystemExit):
         config = GameConfig(
             'tictactoe/tests/configs/config_which_doesnt_exist.json')
     captured = capsys.readouterr()
     assert "Couldn't load config file." in captured.out
예제 #6
0
    def test_game_run_with_ai(self, capsys):
        """Tests game run with 3 AI players and no human players."""
        config = GameConfig('tictactoe/tests/configs/config_with_3_ai.json')
        game = Game(config)

        with pytest.raises(SystemExit):
            game.run()
        captured = capsys.readouterr()

        # Assert game finished successfully and correct message is displayed.
        assert "Game finished" in captured.out and str(
            game.completed_turns) in captured.out
예제 #7
0
    def test_config_with_invalid_grid(self, capsys):
        """Test for too small and too big grid sizes"""
        config = GameConfig(
            'tictactoe/tests/configs/config_with_2x2_grid.json')
        with pytest.raises(SystemExit):
            config.validate_grid_size(config)
        captured = capsys.readouterr()
        assert "Grid size must be between 3 and 10." in captured.out

        config = GameConfig(
            'tictactoe/tests/configs/config_with_11x11_grid.json')
        with pytest.raises(SystemExit):
            config.validate_grid_size(config)
        captured = capsys.readouterr()
        assert "Grid size must be between 3 and 10." in captured.out
예제 #8
0
    def test_game_initiation(self):
        """Tests game initiation with example config."""
        config = GameConfig('config_example.json')
        game = Game(config)

        # Assert grid was initiated according to config.
        assert isinstance(game.grid,
                          Grid) and game.grid.size == config['grid']['size']
        # Assert list of players were initiated according to config.
        assert isinstance(game.players, list) and len(game.players) == len(
            config['players'])
        # Assert referee was initiated.
        assert isinstance(game.referee, Referee)

        game.init_referee()
예제 #9
0
 def test_config_example(self):
     """Tests the example config file which should pass all validations."""
     config = GameConfig('config_example.json')
     assert config.is_valid()
예제 #10
0
 def test_config_with_error(self, capsys):
     """Tests configs with syntax errors and empty configs"""
     GameConfig('tictactoe/tests/configs/config_with_error.json')
     captured = capsys.readouterr()
     assert "There was a problem with parsing your config file." in captured.out
예제 #11
0
def game():
    config = GameConfig('config_example.json')
    game = Game(config)
    yield game
예제 #12
0
def game_with_corners_win():
    config = GameConfig('tictactoe/tests/configs/config_corners_win.json')
    game = Game(config)
    yield game