Exemplo n.º 1
0
    def test_invalid_url_return_none(self, *args, **kwargs):
        mock_id = PropertyMock(return_value='BAD')
        player = Player(None)
        type(player)._player_id = mock_id

        result = player._retrieve_html_page()

        assert result is None
Exemplo n.º 2
0
    def test_correct_initial_index_found(self):
        seasons = ['2017', None, '2018']
        mock_season = mock.PropertyMock(return_value=seasons)
        player = Player('verlaju01')
        type(player)._season = mock_season

        result = player._find_initial_index()

        assert player._index == 1
Exemplo n.º 3
0
def add_pitchers(apps, schema_editor):
    Player = apps.get_model('core', 'Player')
    summary_list = []

    for x in range(1990, 1995):
        season = str(x)
        braves = Roster('ATL', season)
        pitchers = [
            player for player in braves.players if player.position == 'P'
        ]
        for pitcher in pitchers:
            summary_list.append((pitcher.name, season, pitcher.position,
                                 pitcher(season).games, pitcher(season).era,
                                 pitcher(season).wins, pitcher(season).whip))

        summary = tuple(summary_list)

        Player.objects.bulk_create(
            Player(name=name,
                   season=season,
                   position=position,
                   games=games,
                   era=era,
                   wins=wins,
                   whip=whip)
            for name, season, position, games, era, wins, whip in summary)
Exemplo n.º 4
0
    def test_no_float_returns_default_value(self):
        mock_batting_average = PropertyMock(return_value=[''])
        mock_index = PropertyMock(return_value=0)
        player = Player(None)
        type(player)._batting_average = mock_batting_average
        type(player)._index = mock_index

        result = player.batting_average

        assert result is None
Exemplo n.º 5
0
    def test_no_int_returns_default_value(self):
        mock_runs = PropertyMock(return_value=[''])
        mock_index = PropertyMock(return_value=0)
        player = Player(None)
        type(player)._runs = mock_runs
        type(player)._index = mock_index

        result = player.runs

        assert result is None
Exemplo n.º 6
0
    def test_no_recent_returns_default_value(self):
        mock_position = PropertyMock(return_value=[''])
        mock_season = PropertyMock(return_value='2018')
        mock_seasons = PropertyMock(return_value=['2018'])
        player = Player(None)
        type(player)._position = mock_position
        type(player)._season = mock_seasons
        type(player)._most_recent_season = mock_season

        result = player.position

        assert result is None
Exemplo n.º 7
0
def add_pitchers(apps, schema_editor):
    Player = apps.get_model('core', 'Player')
    braves = Roster('ATL', '1995')
    pitchers = [player for player in braves.players if player.position == 'P']
    summary_list = []

    for pitcher in pitchers:
        summary_list.append((pitcher.name))

    summary = tuple(summary_list)

    Player.objects.bulk_create(Player(name=name) for name in summary)
Exemplo n.º 8
0
    def setup_method(self, *args, **kwargs):
        self.results_career = {
            'assists': 278,
            'at_bats': 48,
            'bases_on_balls': 0,
            'batting_average': 0.104,
            'birth_date': '1983-02-20',
            'complete_games': 24,
            'defensive_chances': 465,
            'defensive_runs_saved_above_average': 31,
            'defensive_runs_saved_above_average_per_innings': 2,
            'double_plays_turned': 28,
            'doubles': 0,
            'errors': 33,
            'fielding_percentage': 0.929,
            'games': 23,
            'games_catcher': 0,
            'games_center_fielder': 0,
            'games_designated_hitter': 0,
            'games_first_baseman': 0,
            'games_in_batting_order': 23,
            'games_in_defensive_lineup': 417,
            'games_left_fielder': 0,
            'games_outfielder': 0,
            'games_pinch_hitter': 0,
            'games_pinch_runner': 0,
            'games_pitcher': 417,
            'games_right_fielder': 0,
            'games_second_baseman': 0,
            'games_shortstop': 0,
            'games_started': 417,
            'games_third_baseman': 0,
            'grounded_into_double_plays': 1,
            'height': '6-5',
            'hits': 5,
            'home_runs': 0,
            'innings_played': 2747.0,
            'intentional_bases_on_balls': 0,
            'league_fielding_percentage': 0.953,
            'league_range_factor_per_game': 1.5,
            'league_range_factor_per_nine_innings': 1.51,
            'name': 'Justin Verlander',
            'nationality': 'United States of America',
            'on_base_percentage': 0.104,
            'on_base_plus_slugging_percentage': 0.208,
            'on_base_plus_slugging_percentage_plus': -43,
            'plate_appearances': 58,
            'player_id': 'verlaju01',
            'position': 'P',
            'putouts': 154,
            'range_factor_per_game': 1.04,
            'range_factor_per_nine_innings': 1.42,
            'runs': 2,
            'runs_batted_in': 1,
            'sacrifice_flies': 0,
            'sacrifice_hits': 10,
            'season': 'Career',
            'slugging_percentage': 0.104,
            'stolen_bases': 0,
            'team_abbreviation': 'HOU',
            'times_caught_stealing': 0,
            'times_hit_by_pitch': 0,
            'times_struck_out': 23,
            'total_bases': 5,
            'total_fielding_runs_above_average': None,
            'total_fielding_runs_above_average_per_innings': None,
            'triples': 0,
            'weight': 225,
            'balks': 19,
            'bases_on_balls_given': 807,
            'bases_on_balls_given_per_nine_innings': 2.6,
            'batters_faced': 11305,
            'batters_struckout_per_nine_innings': 8.8,
            'earned_runs_allowed': 1039,
            'era': 3.4,
            'era_plus': 125.0,
            'fielding_independent_pitching': 3.43,
            'games_finished': 0,
            'hits_against_per_nine_innings': 7.8,
            'hits_allowed': 2394,
            'home_runs_against_per_nine_innings': 0.9,
            'home_runs_allowed': 272,
            'intentional_bases_on_balls_given': 27,
            'losses': 123,
            'runs_allowed': 1124,
            'saves': 0,
            'shutouts': 8,
            'strikeouts': 2685,
            'strikeouts_thrown_per_walk': 3.33,
            'times_hit_player': 91,
            'whip': 1.165,
            'wild_pitches': 82,
            'win_percentage': 0.624,
            'wins': 204
        }

        self.results_2017 = {
            'assists': 13,
            'at_bats': 6,
            'bases_on_balls': 0,
            'batting_average': 0.167,
            'birth_date': '1983-02-20',
            'complete_games': 0,
            'defensive_chances': 24,
            'defensive_runs_saved_above_average': 0,
            'defensive_runs_saved_above_average_per_innings': 0,
            'double_plays_turned': 1,
            'doubles': 0,
            'errors': 1,
            'fielding_percentage': 0.958,
            'games': 2,
            'games_catcher': 0,
            'games_center_fielder': 0,
            'games_designated_hitter': 0,
            'games_first_baseman': 0,
            'games_in_batting_order': 2,
            'games_in_defensive_lineup': 28,
            'games_left_fielder': 0,
            'games_outfielder': 0,
            'games_pinch_hitter': 0,
            'games_pinch_runner': 0,
            'games_pitcher': 28,
            'games_right_fielder': 0,
            'games_second_baseman': 0,
            'games_shortstop': 0,
            'games_started': 33,
            'games_third_baseman': 0,
            'grounded_into_double_plays': 0,
            'height': '6-5',
            'hits': 1,
            'home_runs': 0,
            'innings_played': 206.0,
            'intentional_bases_on_balls': 0,
            'league_fielding_percentage': 0.948,
            'league_range_factor_per_game': 1.32,
            'league_range_factor_per_nine_innings': 1.33,
            'name': 'Justin Verlander',
            'nationality': 'United States of America',
            'on_base_percentage': 0.167,
            'on_base_plus_slugging_percentage': 0.333,
            'on_base_plus_slugging_percentage_plus': -10,
            'plate_appearances': 6,
            'player_id': 'verlaju01',
            'position': 'P',
            'putouts': 10,
            'range_factor_per_game': 0.7,
            'range_factor_per_nine_innings': 1.0,
            'runs': 0,
            'runs_batted_in': 1,
            'sacrifice_flies': 0,
            'sacrifice_hits': 0,
            'season': '2017',
            'slugging_percentage': 0.167,
            'stolen_bases': 0,
            'team_abbreviation': 'HOU',
            'times_caught_stealing': 0,
            'times_hit_by_pitch': 0,
            'times_struck_out': 4,
            'total_bases': 1,
            'total_fielding_runs_above_average': None,
            'total_fielding_runs_above_average_per_innings': None,
            'triples': 0,
            'weight': 225,
            'balks': 0,
            'bases_on_balls_given': 72,
            'bases_on_balls_given_per_nine_innings': 3.1,
            'batters_faced': 849,
            'batters_struckout_per_nine_innings': 9.6,
            'earned_runs_allowed': 77,
            'era': 3.36,
            'era_plus': 131.0,
            'fielding_independent_pitching': 3.84,
            'games_finished': 0,
            'hits_against_per_nine_innings': 7.4,
            'hits_allowed': 170,
            'home_runs_against_per_nine_innings': 1.2,
            'home_runs_allowed': 27,
            'intentional_bases_on_balls_given': 4,
            'losses': 8,
            'runs_allowed': 80,
            'saves': 0,
            'shutouts': 0,
            'strikeouts': 219,
            'strikeouts_thrown_per_walk': 3.04,
            'times_hit_player': 4,
            'whip': 1.175,
            'wild_pitches': 5,
            'win_percentage': 0.652,
            'wins': 15
        }

        self.player = Player('verlaju01')
Exemplo n.º 9
0
    def setup_method(self, *args, **kwargs):
        self.results_career = {
            'assists': 2763,
            'at_bats': 4436,
            'bases_on_balls': 311,
            'batting_average': 0.317,
            'birth_date': '1990-05-06',
            'complete_games': 990,
            'defensive_chances': 4500,
            'defensive_runs_saved_above_average': -24,
            'defensive_runs_saved_above_average_per_innings': -3,
            'double_plays_turned': 623,
            'doubles': 271,
            'errors': 61,
            'fielding_percentage': 0.986,
            'games': 1105,
            'games_catcher': 0,
            'games_center_fielder': 0,
            'games_designated_hitter': 30,
            'games_first_baseman': 0,
            'games_in_batting_order': 1105,
            'games_in_defensive_lineup': 1070,
            'games_left_fielder': 0,
            'games_outfielder': 0,
            'games_pinch_hitter': 7,
            'games_pinch_runner': 4,
            'games_pitcher': 0,
            'games_right_fielder': 0,
            'games_second_baseman': 1070,
            'games_shortstop': 1,
            'games_started': 1059,
            'games_third_baseman': 0,
            'grounded_into_double_plays': 123,
            'height': '5-6',
            'hits': 1404,
            'home_runs': 96,
            'innings_played': 9269.0,
            'intentional_bases_on_balls': 38,
            'league_fielding_percentage': 0.984,
            'league_range_factor_per_game': 4.5,
            'league_range_factor_per_nine_innings': 4.53,
            'name': u'José Altuve',
            'nationality': 'Venezuela',
            'on_base_percentage': 0.364,
            'on_base_plus_slugging_percentage': 0.818,
            'on_base_plus_slugging_percentage_plus': 126,
            'plate_appearances': 4851,
            'player_id': 'altuvjo01',
            'position': '2B',
            'putouts': 1676,
            'range_factor_per_game': 4.15,
            'range_factor_per_nine_innings': 4.31,
            'runs': 635,
            'runs_batted_in': 457,
            'sacrifice_flies': 36,
            'sacrifice_hits': 24,
            'season': 'Career',
            'slugging_percentage': 0.454,
            'stolen_bases': 246,
            'team_abbreviation': 'HOU',
            'times_caught_stealing': 68,
            'times_hit_by_pitch': 44,
            'times_struck_out': 535,
            'total_bases': 2013,
            'total_fielding_runs_above_average': 23,
            'total_fielding_runs_above_average_per_innings': 3,
            'triples': 25,
            'weight': 165
        }

        self.results_2017 = {
            'assists': 351,
            'at_bats': 590,
            'bases_on_balls': 58,
            'batting_average': 0.346,
            'birth_date': '1990-05-06',
            'complete_games': 134,
            'defensive_chances': 562,
            'defensive_runs_saved_above_average': 3,
            'defensive_runs_saved_above_average_per_innings': 3,
            'double_plays_turned': 86,
            'doubles': 39,
            'errors': 10,
            'fielding_percentage': 0.982,
            'games': 153,
            'games_catcher': 0,
            'games_center_fielder': 0,
            'games_designated_hitter': 3,
            'games_first_baseman': 0,
            'games_in_batting_order': 153,
            'games_in_defensive_lineup': 149,
            'games_left_fielder': 0,
            'games_outfielder': 0,
            'games_pinch_hitter': 1,
            'games_pinch_runner': 1,
            'games_pitcher': 0,
            'games_right_fielder': 0,
            'games_second_baseman': 149,
            'games_shortstop': 0,
            'games_started': 148,
            'games_third_baseman': 0,
            'grounded_into_double_plays': 19,
            'height': '5-6',
            'hits': 204,
            'home_runs': 24,
            'innings_played': 1283.1,
            'intentional_bases_on_balls': 3,
            'league_fielding_percentage': 0.983,
            'league_range_factor_per_game': 4.3,
            'league_range_factor_per_nine_innings': 4.35,
            'name': u'José Altuve',
            'nationality': 'Venezuela',
            'on_base_percentage': 0.41,
            'on_base_plus_slugging_percentage': 0.957,
            'on_base_plus_slugging_percentage_plus': 162,
            'plate_appearances': 662,
            'player_id': 'altuvjo01',
            'position': '2B',
            'putouts': 201,
            'range_factor_per_game': 3.7,
            'range_factor_per_nine_innings': 3.87,
            'runs': 112,
            'runs_batted_in': 81,
            'sacrifice_flies': 4,
            'sacrifice_hits': 1,
            'season': '2017',
            'slugging_percentage': 0.547,
            'stolen_bases': 32,
            'team_abbreviation': 'HOU',
            'times_caught_stealing': 6,
            'times_hit_by_pitch': 9,
            'times_struck_out': 84,
            'total_bases': 323,
            'total_fielding_runs_above_average': 13,
            'total_fielding_runs_above_average_per_innings': 12,
            'triples': 4,
            'weight': 165,
            # Properties specific to pitchers
            'balks': None,
            'bases_on_balls_given': None,
            'bases_on_balls_given_per_nine_innings': None,
            'batters_faced': None,
            'batters_struckout_per_nine_innings': None,
            'earned_runs_allowed': None,
            'era': None,
            'era_plus': None,
            'fielding_independent_pitching': None,
            'games_finished': None,
            'hits_against_per_nine_innings': None,
            'hits_allowed': None,
            'home_runs_against_per_nine_innings': None,
            'home_runs_allowed': None,
            'intentional_bases_on_balls_given': None,
            'losses': None,
            'runs_allowed': None,
            'saves': None,
            'shutouts': None,
            'strikeouts': None,
            'strikeouts_thrown_per_walk': None,
            'times_hit_player': None,
            'whip': None,
            'wild_pitches': None,
            'win_percentage': None,
            'wins': None
        }

        self.player = Player('altuvjo01')