예제 #1
0
    def test_mlb_boxscore_string_representation(self):
        expected = ('Boxscore for Detroit Tigers at Boston Red Sox (Thursday, '
                    'June 7, 2018)')

        boxscore = Boxscore(BOXSCORE)

        assert boxscore.__repr__() == expected
예제 #2
0
    def test_mlb_boxscore_string_representation(self):
        expected = ('Boxscore for San Francisco Giants at '
                    'Los Angeles Angels (Monday, August 17, 2020)')

        boxscore = Boxscore(BOXSCORE)

        assert boxscore.__repr__() == expected
예제 #3
0
    def test_mlb_boxscore_player(self):
        boxscore = Boxscore(BOXSCORE)

        assert len(boxscore.home_players) == 15
        assert len(boxscore.away_players) == 15

        for player in boxscore.home_players:
            assert not player.dataframe.empty
        for player in boxscore.away_players:
            assert not player.dataframe.empty
예제 #4
0
    def test_invalid_url_yields_empty_class(self):
        flexmock(Boxscore) \
            .should_receive('_retrieve_html_page') \
            .and_return(None)

        boxscore = Boxscore(BOXSCORE)

        for key, value in boxscore.__dict__.items():
            if key == '_uri':
                continue
            assert value is None
예제 #5
0
    def test_game_summary_with_no_scores_returns_none(self):
        result = Boxscore(None)._parse_summary(
            pq("""<table class="linescore nohover stats_table no_freeze">
    <tbody>
        <tr>
            <td class="center"></td>
            <td class="center"></td>
            <td class="center"></td>
            <td class="center"></td>
        </tr>
        <tr>
            <td class="center"></td>
            <td class="center"></td>
            <td class="center"></td>
            <td class="center"></td>
        </tr>
    </tbody>
</table>"""))

        assert result == {'away': [None], 'home': [None]}
예제 #6
0
    def setup_method(self, *args, **kwargs):
        self.results = {
            'date': 'Monday, August 17, 2020',
            'time': '6:40 p.m. Local',
            'venue': 'Angel Stadium of Anaheim',
            'time_of_day': NIGHT,
            'duration': '3:12',
            'winner': HOME,
            'winning_name': 'Los Angeles Angels',
            'winning_abbr': 'LAA',
            'losing_name': 'San Francisco Giants',
            'losing_abbr': 'SFG',
            'away_at_bats': 35,
            'away_runs': 6,
            'away_hits': 10,
            'away_rbi': 6,
            'away_earned_runs': 6.0,
            'away_bases_on_balls': 1,
            'away_strikeouts': 5,
            'away_plate_appearances': 38,
            'away_batting_average': .286,
            'away_on_base_percentage': .316,
            'away_slugging_percentage': .457,
            'away_on_base_plus': .773,
            'away_pitches': 140,
            'away_strikes': 100,
            'away_win_probability_for_offensive_player': .283,
            'away_average_leverage_index': 1.15,
            'away_win_probability_added': .893,
            'away_win_probability_subtracted': -.608,
            'away_base_out_runs_added': 1.1,
            'away_putouts': 25,
            'away_assists': 5,
            'away_innings_pitched': 8.1,
            'away_home_runs': 2,
            'away_strikes_by_contact': 63,
            'away_strikes_swinging': 14,
            'away_strikes_looking': 23,
            'away_grounded_balls': 10,
            'away_fly_balls': 21,
            'away_line_drives': 10,
            'away_unknown_bat_type': 0,
            'away_game_score': 38,
            'away_inherited_runners': 0,
            'away_inherited_score': 0,
            'away_win_probability_by_pitcher': -.783,
            'away_average_leverage_index': 1.75,
            'away_base_out_runs_saved': -2.4,
            'home_at_bats': 35,
            'home_runs': 7,
            'home_hits': 12,
            'home_rbi': 7,
            'home_earned_runs': 7.56,
            'home_bases_on_balls': 2,
            'home_strikeouts': 10,
            'home_plate_appearances': 38,
            'home_batting_average': .343,
            'home_on_base_percentage': .368,
            'home_slugging_percentage': .600,
            'home_on_base_plus': .968,
            'home_pitches': 159,
            'home_strikes': 99,
            'home_win_probability_for_offensive_player': .784,
            'home_average_leverage_index': 1.75,
            'home_win_probability_added': 1.842,
            'home_win_probability_subtracted': -1.060,
            'home_base_out_runs_added': 2.4,
            'home_putouts': 27,
            'home_assists': 8,
            'home_innings_pitched': 9,
            'home_home_runs': 1,
            'home_strikes_by_contact': 50,
            'home_strikes_swinging': 14,
            'home_strikes_looking': 35,
            'home_grounded_balls': 7,
            'home_fly_balls': 19,
            'home_line_drives': 9,
            'home_unknown_bat_type': 0,
            'home_game_score': 42,
            'home_inherited_runners': 5,
            'home_inherited_score': 2,
            'home_win_probability_by_pitcher': -.283,
            'home_average_leverage_index': 1.15,
            'home_base_out_runs_saved': -1.1
        }
        flexmock(utils) \
            .should_receive('_todays_date') \
            .and_return(MockDateTime(YEAR, MONTH))

        self.boxscore = Boxscore(BOXSCORE)
예제 #7
0
    def setup_method(self, *args, **kwargs):
        flexmock(Boxscore) \
            .should_receive('_parse_game_data') \
            .and_return(None)

        self.boxscore = Boxscore(None)
예제 #8
0
    def test_invalid_url_returns_none(self, *args, **kwargs):
        result = Boxscore(None)._retrieve_html_page('')

        assert result is None
예제 #9
0
    def setup_method(self, *args, **kwargs):
        self.results = {
            'date': 'Thursday, June 7, 2018',
            'time': '7:10 p.m. ET',
            'attendance': 36556,
            'venue': 'Fenway Park',
            'time_of_day': NIGHT,
            'duration': '2:55',
            'winner': AWAY,
            'winning_name': 'Detroit Tigers',
            'winning_abbr': 'DET',
            'losing_name': 'Boston Red Sox',
            'losing_abbr': 'BOS',
            'away_at_bats': 37,
            'away_runs': 7,
            'away_hits': 10,
            'away_rbi': 7,
            'away_earned_runs': 7.0,
            'away_bases_on_balls': 3,
            'away_strikeouts': 11,
            'away_plate_appearances': 40,
            'away_batting_average': .270,
            'away_on_base_percentage': .325,
            'away_slugging_percentage': .486,
            'away_on_base_plus': .811,
            'away_pitches': 141,
            'away_strikes': 109,
            'away_win_probability_for_offensive_player': .315,
            'away_average_leverage_index': .46,
            'away_win_probability_added': .551,
            'away_win_probability_subtracted': -.236,
            'away_base_out_runs_added': 2.2,
            'away_putouts': 27,
            'away_assists': 9,
            'away_innings_pitched': 9,
            'away_home_runs': 1,
            'away_strikes_by_contact': 68,
            'away_strikes_swinging': 14,
            'away_strikes_looking': 27,
            'away_grounded_balls': 13,
            'away_fly_balls': 13,
            'away_line_drives': 6,
            'away_unknown_bat_type': 0,
            'away_game_score': 59,
            'away_inherited_runners': 1,
            'away_inherited_score': 0,
            'away_win_probability_by_pitcher': .184,
            'away_average_leverage_index': .71,
            'away_base_out_runs_saved': 2.8,
            'home_at_bats': 33,
            'home_runs': 2,
            'home_hits': 7,
            'home_rbi': 2,
            'home_earned_runs': 2.0,
            'home_bases_on_balls': 5,
            'home_strikeouts': 8,
            'home_plate_appearances': 38,
            'home_batting_average': .212,
            'home_on_base_percentage': .316,
            'home_slugging_percentage': .364,
            'home_on_base_plus': .679,
            'home_pitches': 157,
            'home_strikes': 83,
            'home_win_probability_for_offensive_player': -.184,
            'home_average_leverage_index': .71,
            'home_win_probability_added': .368,
            'home_win_probability_subtracted': -.552,
            'home_base_out_runs_added': -2.8,
            'home_putouts': 27,
            'home_assists': 9,
            'home_innings_pitched': 9,
            'home_home_runs': 1,
            'home_strikes_by_contact': 45,
            'home_strikes_swinging': 12,
            'home_strikes_looking': 26,
            'home_grounded_balls': 9,
            'home_fly_balls': 16,
            'home_line_drives': 7,
            'home_unknown_bat_type': 0,
            'home_game_score': 25,
            'home_inherited_runners': 0,
            'home_inherited_score': 0,
            'home_win_probability_by_pitcher': -.317,
            'home_average_leverage_index': .46,
            'home_base_out_runs_saved': -2.2
        }
        flexmock(utils) \
            .should_receive('_todays_date') \
            .and_return(MockDateTime(YEAR, MONTH))

        self.boxscore = Boxscore(BOXSCORE)
예제 #10
0
 def boxscore(self):
     """
     Returns an instance of the Boxscore class containing more detailed
     stats on the game.
     """
     return Boxscore(self._boxscore)